Search in sources :

Example 71 with RandomAccessFile

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) {
        }
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) IOException(java.io.IOException)

Example 72 with RandomAccessFile

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);
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile)

Example 73 with RandomAccessFile

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;
}
Also used : RandomAccessFile(java.io.RandomAccessFile) IOException(java.io.IOException)

Example 74 with RandomAccessFile

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);
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) IOException(java.io.IOException)

Example 75 with RandomAccessFile

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;
    }
}
Also used : RandomAccessFile(java.io.RandomAccessFile) MappedByteBuffer(java.nio.MappedByteBuffer) FileChannel(java.nio.channels.FileChannel) IOException(java.io.IOException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File)

Aggregations

RandomAccessFile (java.io.RandomAccessFile)1607 IOException (java.io.IOException)761 File (java.io.File)691 FileChannel (java.nio.channels.FileChannel)284 ByteBuffer (java.nio.ByteBuffer)174 FileNotFoundException (java.io.FileNotFoundException)167 Test (org.junit.Test)152 FileOutputStream (java.io.FileOutputStream)91 FileLock (java.nio.channels.FileLock)91 MappedByteBuffer (java.nio.MappedByteBuffer)83 InputStream (java.io.InputStream)68 FileInputStream (java.io.FileInputStream)63 EOFException (java.io.EOFException)55 ArrayList (java.util.ArrayList)45 ByteArrayOutputStream (java.io.ByteArrayOutputStream)39 BufferedInputStream (java.io.BufferedInputStream)35 ByteArrayInputStream (java.io.ByteArrayInputStream)35 Random (java.util.Random)33 HashMap (java.util.HashMap)24 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)23