KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > alfresco > filesys > smb > server > repo > pseudo > LocalPseudoFile


1 /*
2  * Copyright (C) 2005 Alfresco, Inc.
3  *
4  * Licensed under the Mozilla Public License version 1.1
5  * with a permitted attribution clause. You may obtain a
6  * copy of the License at
7  *
8  * http://www.alfresco.org/legal/license.txt
9  *
10  * Unless required by applicable law or agreed to in writing,
11  * software distributed under the License is distributed on an
12  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific
14  * language governing permissions and limitations under the
15  * License.
16  */

17
18 package org.alfresco.filesys.smb.server.repo.pseudo;
19
20 import java.io.File JavaDoc;
21
22 import org.alfresco.filesys.server.filesys.FileInfo;
23 import org.alfresco.filesys.server.filesys.NetworkFile;
24
25 /**
26  * Local Pseudo File Class
27  *
28  * <p>Pseudo file class that uses a file on the local filesystem.
29  *
30  * @author gkspencer
31  */

32 public class LocalPseudoFile extends PseudoFile
33 {
34     // Path to the file on the local filesystem
35

36     private String JavaDoc m_path;
37     
38     /**
39      * Class constructor
40      *
41      * @param name String
42      * @param path String
43      */

44     public LocalPseudoFile(String JavaDoc name, String JavaDoc path)
45     {
46         super(name);
47         
48         m_path = path;
49     }
50     
51     /**
52      * Return the path to the file on the local filesystem
53      *
54      * @return String
55      */

56     public final String JavaDoc getFilePath()
57     {
58         return m_path;
59     }
60     
61     /**
62      * Return the file information for the pseudo file
63      *
64      * @return FileInfo
65      */

66     public FileInfo getFileInfo()
67     {
68         // Check if the file information is valid
69

70         if ( m_fileInfo == null) {
71             
72             // Get the file details
73

74             File JavaDoc localFile = new File JavaDoc( getFilePath());
75             if ( localFile.exists())
76             {
77                 // Create the file information
78

79                 m_fileInfo = new FileInfo( getFileName(), localFile.length(), getAttributes());
80                 
81                 // Set the file creation/modification times
82

83                 m_fileInfo.setModifyDateTime( localFile.lastModified());
84                 m_fileInfo.setCreationDateTime( _creationDateTime);
85                 m_fileInfo.setChangeDateTime( _creationDateTime);
86
87                 // Set the allocation size, round up the actual length
88

89                 m_fileInfo.setAllocationSize(( localFile.length() + 512L) & 0xFFFFFFFFFFFFFE00L);
90             }
91         }
92         
93         // Return the file information
94

95         return m_fileInfo;
96     }
97
98     /**
99      * Return a network file for reading/writing the pseudo file
100      *
101      * @param netPath String
102      * @return NetworkFile
103      */

104     public NetworkFile getFile(String JavaDoc netPath)
105     {
106         // Create a pseudo file mapped to a file in the local filesystem
107

108         return new PseudoNetworkFile( getFileName(), getFilePath(), netPath);
109     }
110 }
111
Popular Tags