Methods Summary |
---|
private static native void | close(int handle)Close a native stream.
|
public void | connect(java.lang.String name, int mode, boolean timeouts)Connect to a file in storage.
connect(name, mode);
|
public void | connect(java.lang.String name, int mode)Called to connect a RandomAccessStream to a file in storage.
byte[] asciiFilename;
if (handle != -1) {
throw new
IOException("Disconnect the stream before reconnecting.");
}
asciiFilename = Util.toCString(name);
handle = open(asciiFilename, mode);
/* This object is re-used by internal methods */
connectionOpen = true;
if (mode == Connector.READ) {
maxOStreams = 0;
} else {
maxOStreams = 1;
}
maxIStreams = 1;
|
public void | disconnect()Disconnect the stream.
Any streams obtained with either openInputStream or
openOutputStream will throw an exception if used after
this call.
if (handle == -1) {
return;
}
close(handle);
handle = -1;
connectionOpen = false;
|
private native void | finalize()Ensures native resources are freed when Object is collected.
|
public int | getSizeOf()Get the size of this stream.
return sizeOf(handle);
|
private native int | open(byte[] szFilename, int mode)Open a stream to a native file.
|
private static native void | position(int handle, int absolutePosition)Set the current position of a native stream.
|
private static native int | read(int handle, byte[] buffer, int offset, int length)Read at least one byte from a native stream.
|
public int | readBytes(byte[] b, int off, int len)Reads up to len bytes of data from the input stream into
an array of bytes, blocks until at least one byte is available.
Do not use this method if openInputStream has been called
since the input stream may be buffering data.
if (len == 0) {
return 0;
}
// test before we goto the native code
int test = b[off] + b[len - 1] + b[off + len - 1];
return read(handle, b, off, len);
|
protected int | readBytesNonBlocking(byte[] b, int off, int len)Reads up to len bytes of data from the input stream into
an array of bytes, but does not block if no bytes available.
The readBytesNonBlocking method of
ConnectionBaseAdapter does nothing and returns 0.
// Read bytes should be non blocking
return readBytes(b, off, len);
|
public void | setPosition(int absolutePosition)Set the absolute postion of this stream.
Do not use this method if either openInputStream or
openOutputStream has been called
since the streams may be buffering data.
position(handle, absolutePosition);
|
private static native int | sizeOf(int handle)Get the total size of a native stream.
|
public void | truncate(int size)Truncate the size of the stream to size bytes.
This method cannot be used to make the size of the
underlying stream larger.
truncateStream(handle, size);
|
private static native void | truncateStream(int handle, int size)Set the size of a native stream.
|
private static native void | write(int handle, byte[] buffer, int offset, int length)Write bytes to a native stream.
|
public int | writeBytes(byte[] b, int off, int len)Writes len bytes from the specified byte array
starting at offset off to this output stream.
Polling the native code is done here to allow for simple
asynchronous native code to be written. Not all implementations
work this way (they block in the native code) but the same
Java code works for both.
Do not use this method if openOutputStream has been called
since the output stream may be buffering data.
if (len == 0) {
return 0;
}
// test before we goto the native code
int test = b[off] + b[len - 1] + b[off + len - 1];
write(handle, b, off, len);
return len;
|
public int | writeStream(java.io.InputStream in)Write the given stream fully into this one.
byte[] temp = new byte[1024];
int bytesRead;
int totalBytesWritten = 0;
for (;;) {
bytesRead = in.read(temp);
if (bytesRead == -1) {
return totalBytesWritten;
}
writeBytes(temp, 0, bytesRead);
totalBytesWritten += bytesRead;
}
|