125 |
{ |
{ |
126 |
} |
} |
127 |
|
|
128 |
private FileDescriptor(int nativeFd) |
private FileDescriptor(long nativeFd) |
129 |
{ |
{ |
130 |
this.nativeFd = nativeFd; |
this.nativeFd = nativeFd; |
131 |
} |
} |
193 |
nativeFd = nativeOpen(path, mode); |
nativeFd = nativeOpen(path, mode); |
194 |
} |
} |
195 |
|
|
196 |
void close() throws IOException |
synchronized void close() throws IOException |
197 |
{ |
{ |
198 |
if (nativeFd == -1L) |
if (nativeFd == -1L) |
199 |
return; |
return; |
200 |
|
|
201 |
nativeClose(nativeFd); |
try |
202 |
nativeFd = -1L; |
{ |
203 |
|
nativeClose(nativeFd); |
204 |
|
} |
205 |
|
catch(IOException e) |
206 |
|
{ |
207 |
|
nativeFd = -1L; |
208 |
|
throw new IOException(e.getMessage()); |
209 |
|
} |
210 |
} |
} |
211 |
|
|
212 |
void write(int b) throws IOException |
void write(int b) throws IOException |
214 |
if (nativeFd == -1L) |
if (nativeFd == -1L) |
215 |
throw new IOException("Invalid FileDescriptor"); |
throw new IOException("Invalid FileDescriptor"); |
216 |
|
|
217 |
nativeWriteByte(nativeFd, (long)(b & 0xFF)); |
nativeWriteByte(nativeFd, (b & 0xFF)); |
218 |
} |
} |
219 |
|
|
220 |
void write(byte[] buf, long offset, long len) throws IOException |
void write(byte[] buf, int offset, int len) throws IOException |
221 |
{ |
{ |
222 |
if (nativeFd == -1L) |
if (nativeFd == -1L) |
223 |
throw new IOException("Invalid FileDescriptor"); |
throw new IOException("Invalid FileDescriptor"); |
241 |
if (nativeFd == -1L) |
if (nativeFd == -1L) |
242 |
throw new IOException("Invalid FileDescriptor"); |
throw new IOException("Invalid FileDescriptor"); |
243 |
|
|
244 |
long byteRead = nativeReadByte(nativeFd); |
return(nativeReadByte(nativeFd)); |
|
if (byteRead == -1L) |
|
|
return(-1); |
|
|
|
|
|
return((int)(byteRead & 0xFF)); |
|
245 |
} |
} |
246 |
|
|
247 |
int read(byte[] buf, int offset, int len) throws IOException |
int read(byte[] buf, int offset, int len) throws IOException |
260 |
|
|
261 |
// Note that above ops implicitly bomb if buf == null |
// Note that above ops implicitly bomb if buf == null |
262 |
|
|
263 |
long bytesRead = nativeReadBuf(nativeFd, buf, offset, len); |
return(nativeReadBuf(nativeFd, buf, offset, len)); |
|
if (bytesRead == -1L) |
|
|
return(-1); |
|
|
|
|
|
return((int)(bytesRead & 0xFFFF)); |
|
264 |
} |
} |
265 |
|
|
266 |
int available() throws IOException |
int available() throws IOException |
268 |
if (nativeFd == -1L) |
if (nativeFd == -1L) |
269 |
throw new IOException("Invalid FileDescriptor"); |
throw new IOException("Invalid FileDescriptor"); |
270 |
|
|
271 |
long bytesAvail = nativeAvailable(nativeFd); |
return(nativeAvailable(nativeFd)); |
|
|
|
|
// FIXME: Is this right? |
|
|
if (bytesAvail > 0xFFFFL) |
|
|
return(0xFFFF); |
|
|
else |
|
|
return((int)(bytesAvail & 0xFFFF)); |
|
272 |
} |
} |
273 |
|
|
274 |
long seek(long offset, int whence, boolean stopAtEof) throws IOException |
long seek(long offset, int whence, boolean stopAtEof) throws IOException |
384 |
* |
* |
385 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
386 |
*/ |
*/ |
387 |
private native long nativeWriteByte(long fd, long b) throws IOException; |
private native long nativeWriteByte(long fd, int b) throws IOException; |
388 |
// I hate name mangling. |
// I hate name mangling. |
389 |
|
|
390 |
/** |
/** |
399 |
* |
* |
400 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
401 |
*/ |
*/ |
402 |
private native long nativeWriteBuf(long fd, byte[] buf, long offset, long len) |
private native long nativeWriteBuf(long fd, byte[] buf, int offset, int len) |
403 |
throws IOException; |
throws IOException; |
404 |
// I hate name mangling. |
// I hate name mangling. |
405 |
|
|
413 |
* |
* |
414 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
415 |
*/ |
*/ |
416 |
private native long nativeReadByte(long fd) throws IOException; |
private native int nativeReadByte(long fd) throws IOException; |
417 |
// I hate name mangling. |
// I hate name mangling. |
418 |
|
|
419 |
/** |
/** |
428 |
* |
* |
429 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
430 |
*/ |
*/ |
431 |
private native long nativeReadBuf(long fd, byte[] buf, long offset, long len) |
private native int nativeReadBuf(long fd, byte[] buf, int offset, int len) |
432 |
throws IOException; |
throws IOException; |
433 |
// I hate name mangling. |
// I hate name mangling. |
434 |
|
|
441 |
* |
* |
442 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
443 |
*/ |
*/ |
444 |
private native long nativeAvailable(long fd) throws IOException; |
private native int nativeAvailable(long fd) throws IOException; |
445 |
|
|
446 |
/** |
/** |
447 |
* Method to do a "seek" operation on the file |
* Method to do a "seek" operation on the file |