- 积分
- 7
- 实力分
- 点
- 金钱数
- 两
- 技术分
- 分
- 贡献分
- 分
|
楼主 |
发表于 2008-10-5 20:25:19
|
显示全部楼层
从网上查资料的时候,发现如下一段代码,不知其何用。。。。
1 /*
2 * Siemens API for MicroEmulator
3 * Copyright (C) 2003 Markus Heberling <markus@heberling.net>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19 package com.siemens.mp.io;
20
21 import java.io.BufferedInputStream;
22 import java.io.InputStream;
23 import java.util.Hashtable;
24 import java.util.Vector;
25
26 import com.barteo.emulator.device.DeviceFactory;
27
28 /**
29 *
30 * @author markus
31 * @version
32 */
33 public class File {
34 static Vector files=new Vector();
35 static Hashtable data=new Hashtable();
36
37 public int close(int fileDescriptor) {
38 //System.out.println("public int close(int fileDescriptor)"+files.elementAt(fileDescriptor));
39 files.setElementAt(null, fileDescriptor);
40 return 1;
41 }
42
43 public static int copy(java.lang.String source, java.lang.String dest) {
44 System.out.println("public static int copy(java.lang.String source, java.lang.String dest)");
45 return 1;
46 }
47
48 public static int debugWrite(java.lang.String fileName, java.lang.String infoString) {
49 System.out.println("public static int debugWrite(java.lang.String fileName, java.lang.String infoString)");
50 return 1;
51 }
52
53 public static int delete(java.lang.String fileName) {
54 //System.out.println("public static int delete(java.lang.String "+fileName+") ");
55 data.remove(fileName);
56 return 1;
57 }
58
59 public static int exists(java.lang.String fileName) {
60 //System.out.println("public static int exists(java.lang.String "+fileName+") "+data.containsKey(fileName));
61 if (data.containsKey(fileName.intern())||
62 DeviceFactory.getDevice().getEmulatorContext().getClassLoader().getResourceAsStream(fileName)!=null
63 ) return 1; else return -1;
64 }
65
66 public static boolean isDirectory(java.lang.String pathName) {
67 System.out.println("public static boolean isDirectory(java.lang.String pathName)");
68 return false;
69 }
70
71 public int length(int fileDescriptor) {
72 //System.out.println("public int length(int fileDescriptor)");
73 return ((FileInfo)data.get(files.elementAt(fileDescriptor))).data.length;
74
75 }
76
77 public static java.lang.String[] list(java.lang.String pathName) {
78 System.out.println(" public static java.lang.String[] list(java.lang.String pathName)");
79 return null;
80 }
81
82 public int open(java.lang.String fileName){
83 //System.out.println("public int open(java.lang.String "+fileName+")");
84
85
86 files.addElement(fileName.intern());
87 byte[] s=new byte[0];
88 if (!data.containsKey(fileName)) {
89 data.put(fileName.intern(), new FileInfo(s));
90 try {
91 InputStream is=DeviceFactory.getDevice().getEmulatorContext().getClassLoader().getResourceAsStream(fileName);
92
93 if(is!=null) {
94 BufferedInputStream bis=new BufferedInputStream(is);
95
96 int l;
97 byte[] b=new byte[1024];
98 while((l=bis.read(b))!=-1) {
99 byte[] t=new byte[l+s.length];
100 System.arraycopy(s, 0, t, 0, s.length);
101 System.arraycopy(b, 0, t, s.length, l);
102 s=t;
103 }
104 data.put(fileName.intern(), new FileInfo(s));
105 }
106 }
107 catch (Exception e) {
108 e.printStackTrace();
109 }
110 }
111 return files.indexOf(fileName);
112 }
113
114 public int read(int fileDescriptor, byte[] buf, int offset, int numBytes) {
115 //System.out.println("public int read(int fileDescriptor, byte[] buf, int offset, int numBytes)"+files.elementAt(fileDescriptor));
116 FileInfo f=((FileInfo)data.get(files.elementAt(fileDescriptor)));
117
118 if(numBytes>(f.data.length-f.seek)) numBytes= f.data.length-f.seek;
119
120 System.arraycopy(f.data, f.seek, buf, offset, numBytes);
121 f.seek+=numBytes;
122 return numBytes;
123 }
124
125 public static int rename(java.lang.String source, java.lang.String dest) {
126 System.out.println("public static int rename(java.lang.String source, java.lang.String dest)");
127 return 1;
128 }
129
130 public int seek(int fileDescriptor, int seekpos) {
131 //System.out.println("public int seek(int fileDescriptor, int seekpos)");
132 ((FileInfo)data.get(files.elementAt(fileDescriptor))).seek=seekpos;
133 return 1;
134 }
135
136 public static int spaceAvailable() {
137 //System.out.println("public static int spaceAvailable()");
138 return 1000000;
139 }
140
141 public static void truncate(int fileDescriptor, int size) {
142 System.out.println("public static void truncate(int fileDescriptor, int size)");
143 }
144
145 public int write(int fileDescriptor, byte[] buf, int offset, int numBytes) {
146 //System.out.println("public int write(int fileDescriptor, byte[] buf, int offset, int numBytes)"+files.elementAt(fileDescriptor));
147 FileInfo f=((FileInfo)data.get(files.elementAt(fileDescriptor)));
148
149 if(numBytes>(f.data.length+f.seek)) {
150 byte[] t=new byte[f.data.length+numBytes];
151 System.arraycopy(f.data, 0, t, 0, f.data.length);
152 f.data=t;
153 }
154
155 System.arraycopy(buf,offset,f.data,f.seek,numBytes);
156 f.seek+=numBytes;
157
158 /*for (int i=0;i<f.data.length;i++)
159 {
160 System.out.print((char)f.data);
161 }
162 System.out.println();*/
163
164 return 1;
165 }
166
167
168 class FileInfo {
169 byte[] data;
170 int seek;
171
172 FileInfo(byte[] data) {
173 this.data=data;
174 this.seek=0;
175 }
176 }
177 } |
|