KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.alfresco.filesys.server.filesys.FileInfo;
21 import org.alfresco.filesys.server.filesys.NetworkFile;
22
23 /**
24  * In Memory Pseudo File Class
25  *
26  * <p>Pseudo file class that uses an in memory buffer for the file data.
27  *
28  * @author gkspencer
29  */

30 public class MemoryPseudoFile extends PseudoFile
31 {
32     // File data buffer
33

34     private byte[] m_data;
35     
36     /**
37      * Class constructor
38      *
39      * @param name String
40      * @param data byte[]
41      */

42     public MemoryPseudoFile(String JavaDoc name, byte[] data)
43     {
44         super( name);
45         
46         m_data = data;
47     }
48     
49     /**
50      * Return the file information for the pseudo file
51      *
52      * @return FileInfo
53      */

54     public FileInfo getFileInfo()
55     {
56         // Check if the file information is valid
57

58         if ( m_fileInfo == null) {
59             
60             // Create the file information
61

62             m_fileInfo = new FileInfo( getFileName(), m_data != null ? m_data.length : 0, getAttributes());
63                 
64             // Set the file creation/modification times
65

66             m_fileInfo.setCreationDateTime( _creationDateTime);
67             m_fileInfo.setModifyDateTime( _creationDateTime);
68             m_fileInfo.setChangeDateTime( _creationDateTime);
69
70             // Set the allocation size, round up the actual length
71

72             m_fileInfo.setAllocationSize(( m_fileInfo.getSize() + 512L) & 0xFFFFFFFFFFFFFE00L);
73         }
74         
75         // Return the file information
76

77         return m_fileInfo;
78     }
79
80     /**
81      * Return a network file for reading/writing the pseudo file
82      *
83      * @param netPath String
84      * @return NetworkFile
85      */

86     public NetworkFile getFile(String JavaDoc netPath)
87     {
88         // Create a pseudo file mapped to the in memory file data
89

90         FileInfo finfo = getFileInfo();
91         finfo.setPath( netPath);
92         
93         return new MemoryNetworkFile( getFileName(), m_data, finfo);
94     }
95 }
96
Popular Tags