Methods Summary |
---|
private static void | close(java.io.Closeable c)
try {
if (c == null) {
return;
}
c.close();
} catch (IOException e) {
Slog.w(TAG, "IOException thrown while closing Closeable", e);
}
|
static com.android.server.RandomBlock | fromFile(java.lang.String filename)
if (DEBUG) Slog.v(TAG, "reading from file " + filename);
InputStream stream = null;
try {
stream = new FileInputStream(filename);
return fromStream(stream);
} finally {
close(stream);
}
|
private static com.android.server.RandomBlock | fromStream(java.io.InputStream in)
RandomBlock retval = new RandomBlock();
int total = 0;
while(total < BLOCK_SIZE) {
int result = in.read(retval.block, total, BLOCK_SIZE - total);
if (result == -1) {
throw new EOFException();
}
total += result;
}
return retval;
|
private void | toDataOut(java.io.DataOutput out)
out.write(block);
|
void | toFile(java.lang.String filename, boolean sync)
if (DEBUG) Slog.v(TAG, "writing to file " + filename);
RandomAccessFile out = null;
try {
out = new RandomAccessFile(filename, sync ? "rws" : "rw");
toDataOut(out);
truncateIfPossible(out);
} finally {
close(out);
}
|
private static void | truncateIfPossible(java.io.RandomAccessFile f)
try {
f.setLength(BLOCK_SIZE);
} catch (IOException e) {
// ignore this exception. Sometimes, the file we're trying to
// write is a character device, such as /dev/urandom, and
// these character devices do not support setting the length.
}
|