use of java.io.RandomAccessFile in project android_frameworks_base by ResurrectionRemix.
the class BackupManagerService method writeToJournalLocked.
private void writeToJournalLocked(String str) {
RandomAccessFile out = null;
try {
if (mJournal == null)
mJournal = File.createTempFile("journal", null, mJournalDir);
out = new RandomAccessFile(mJournal, "rws");
out.seek(out.length());
out.writeUTF(str);
} catch (IOException e) {
Slog.e(TAG, "Can't write " + str + " to backup journal", e);
mJournal = null;
} finally {
try {
if (out != null)
out.close();
} catch (IOException e) {
}
}
}
use of java.io.RandomAccessFile in project android_frameworks_base by ResurrectionRemix.
the class RandomBlock method toFile.
void toFile(String filename, boolean sync) throws IOException {
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);
}
}
use of java.io.RandomAccessFile in project android_frameworks_base by ResurrectionRemix.
the class LockSettingsStorage method readFile.
private byte[] readFile(String name) {
int version;
synchronized (mCache) {
if (mCache.hasFile(name)) {
return mCache.peekFile(name);
}
version = mCache.getVersion();
}
RandomAccessFile raf = null;
byte[] stored = null;
try {
raf = new RandomAccessFile(name, "r");
stored = new byte[(int) raf.length()];
raf.readFully(stored, 0, stored.length);
raf.close();
} catch (IOException e) {
Slog.e(TAG, "Cannot read file " + e);
} finally {
if (raf != null) {
try {
raf.close();
} catch (IOException e) {
Slog.e(TAG, "Error closing file " + e);
}
}
}
mCache.putFileIfUnchanged(name, stored, version);
return stored;
}
use of java.io.RandomAccessFile in project android_frameworks_base by ResurrectionRemix.
the class LockSettingsStorage method writeFile.
private void writeFile(String name, byte[] hash) {
synchronized (mFileWriteLock) {
RandomAccessFile raf = null;
try {
// Write the hash to file
raf = new RandomAccessFile(name, "rw");
// Truncate the file if pattern is null, to clear the lock
if (hash == null || hash.length == 0) {
raf.setLength(0);
} else {
raf.write(hash, 0, hash.length);
}
raf.close();
} catch (IOException e) {
Slog.e(TAG, "Error writing to file " + e);
} finally {
if (raf != null) {
try {
raf.close();
} catch (IOException e) {
Slog.e(TAG, "Error closing file " + e);
}
}
}
mCache.putFile(name, hash);
}
}
use of java.io.RandomAccessFile in project android_frameworks_base by ResurrectionRemix.
the class Hyphenator method loadHyphenator.
private static Hyphenator loadHyphenator(String languageTag) {
String patternFilename = "hyph-" + languageTag.toLowerCase(Locale.US) + ".hyb";
File patternFile = new File(getSystemHyphenatorLocation(), patternFilename);
try {
RandomAccessFile f = new RandomAccessFile(patternFile, "r");
try {
FileChannel fc = f.getChannel();
MappedByteBuffer buf = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
long nativePtr = StaticLayout.nLoadHyphenator(buf, 0);
return new Hyphenator(nativePtr, buf);
} finally {
f.close();
}
} catch (IOException e) {
Log.e(TAG, "error loading hyphenation " + patternFile, e);
return null;
}
}
Aggregations