Search in sources :

Example 1 with CharArrayReader

use of java.io.CharArrayReader in project android_frameworks_base by ResurrectionRemix.

the class SettingsBackupAgent method restoreWifiSupplicant.

private void restoreWifiSupplicant(String filename, byte[] bytes, int size) {
    try {
        WifiNetworkSettings supplicantImage = new WifiNetworkSettings();
        File supplicantFile = new File(FILE_WIFI_SUPPLICANT);
        if (supplicantFile.exists()) {
            // Retain the existing APs; we'll append the restored ones to them
            BufferedReader in = new BufferedReader(new FileReader(FILE_WIFI_SUPPLICANT));
            supplicantImage.readNetworks(in, null, true);
            in.close();
            supplicantFile.delete();
        }
        // Incorporate the restore AP information
        if (size > 0) {
            char[] restoredAsBytes = new char[size];
            for (int i = 0; i < size; i++) restoredAsBytes[i] = (char) bytes[i];
            BufferedReader in = new BufferedReader(new CharArrayReader(restoredAsBytes));
            supplicantImage.readNetworks(in, null, false);
            if (DEBUG_BACKUP) {
                Log.v(TAG, "Final AP list:");
                supplicantImage.dump();
            }
        }
        // Install the correct default template
        BufferedWriter bw = new BufferedWriter(new FileWriter(FILE_WIFI_SUPPLICANT));
        copyWifiSupplicantTemplate(bw);
        // Write the restored supplicant config and we're done
        supplicantImage.write(bw);
        bw.close();
    } catch (IOException ioe) {
        Log.w(TAG, "Couldn't restore " + filename);
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) FileWriter(java.io.FileWriter) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 2 with CharArrayReader

use of java.io.CharArrayReader in project voltdb by VoltDB.

the class TestInMemoryJarfile method testReadFileFromJarfile.

/**
     *
     */
public void testReadFileFromJarfile() throws IOException {
    String catalog0 = this.m_catalog.serialize();
    assertTrue(catalog0.length() > 0);
    InMemoryJarfile jarfile = new InMemoryJarfile(m_jarPath.getAbsolutePath());
    byte[] catalogBytes = jarfile.get(CatalogUtil.CATALOG_FILENAME);
    String catalog1 = new String(catalogBytes, "UTF-8");
    assertTrue(catalog1.length() > 0);
    assertEquals(catalog0.length(), catalog1.length());
    LineNumberReader reader0 = new LineNumberReader(new CharArrayReader(catalog0.toCharArray()));
    LineNumberReader reader1 = new LineNumberReader(new CharArrayReader(catalog1.toCharArray()));
    try {
        int lines = 0;
        while (reader0.ready()) {
            assertEquals(reader0.ready(), reader1.ready());
            assertEquals(reader0.readLine(), reader1.readLine());
            lines++;
        }
        assertTrue(lines > 0);
        reader0.close();
        reader1.close();
    } catch (Exception ex) {
        ex.printStackTrace();
        assertTrue(false);
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) LineNumberReader(java.io.LineNumberReader)

Example 3 with CharArrayReader

use of java.io.CharArrayReader in project intellij-community by JetBrains.

the class CompactSyntaxLexerAdapter method start.

@Deprecated
public void start(char[] buffer, int startOffset, int endOffset, int initialState) {
    myBuffer = new CharArrayCharSequence(buffer, startOffset, endOffset);
    final CharArrayReader reader = new CharArrayReader(buffer, startOffset, endOffset - startOffset);
    init(startOffset, endOffset, reader, initialState);
}
Also used : CharArrayReader(java.io.CharArrayReader) CharArrayCharSequence(com.intellij.util.text.CharArrayCharSequence)

Example 4 with CharArrayReader

use of java.io.CharArrayReader in project android_frameworks_base by DirtyUnicorns.

the class SettingsBackupAgent method restoreWifiSupplicant.

private void restoreWifiSupplicant(String filename, byte[] bytes, int size) {
    try {
        WifiNetworkSettings supplicantImage = new WifiNetworkSettings();
        File supplicantFile = new File(FILE_WIFI_SUPPLICANT);
        if (supplicantFile.exists()) {
            // Retain the existing APs; we'll append the restored ones to them
            BufferedReader in = new BufferedReader(new FileReader(FILE_WIFI_SUPPLICANT));
            supplicantImage.readNetworks(in, null, true);
            in.close();
            supplicantFile.delete();
        }
        // Incorporate the restore AP information
        if (size > 0) {
            char[] restoredAsBytes = new char[size];
            for (int i = 0; i < size; i++) restoredAsBytes[i] = (char) bytes[i];
            BufferedReader in = new BufferedReader(new CharArrayReader(restoredAsBytes));
            supplicantImage.readNetworks(in, null, false);
            if (DEBUG_BACKUP) {
                Log.v(TAG, "Final AP list:");
                supplicantImage.dump();
            }
        }
        // Install the correct default template
        BufferedWriter bw = new BufferedWriter(new FileWriter(FILE_WIFI_SUPPLICANT));
        copyWifiSupplicantTemplate(bw);
        // Write the restored supplicant config and we're done
        supplicantImage.write(bw);
        bw.close();
    } catch (IOException ioe) {
        Log.w(TAG, "Couldn't restore " + filename);
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) FileWriter(java.io.FileWriter) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File) BufferedWriter(java.io.BufferedWriter)

Example 5 with CharArrayReader

use of java.io.CharArrayReader in project jdk8u_jdk by JetBrains.

the class OverflowInSkip method main.

public static void main(String[] args) throws Exception {
    char[] a = "_123456789_123456789_123456789_123456789".toCharArray();
    try (CharArrayReader car = new CharArrayReader(a)) {
        long small = 33;
        long big = Long.MAX_VALUE;
        long smallSkip = car.skip(small);
        if (smallSkip != small)
            throw new Exception("Expected to skip " + small + " chars, but skipped " + smallSkip);
        long expSkip = a.length - small;
        long bigSkip = car.skip(big);
        if (bigSkip != expSkip)
            throw new Exception("Expected to skip " + expSkip + " chars, but skipped " + bigSkip);
    }
}
Also used : CharArrayReader(java.io.CharArrayReader)

Aggregations

CharArrayReader (java.io.CharArrayReader)102 IOException (java.io.IOException)45 BufferedReader (java.io.BufferedReader)22 Reader (java.io.Reader)19 File (java.io.File)11 InputStreamReader (java.io.InputStreamReader)10 Test (org.junit.Test)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 StringReader (java.io.StringReader)8 FileReader (java.io.FileReader)7 PreparedStatement (java.sql.PreparedStatement)7 BufferedWriter (java.io.BufferedWriter)5 CharArrayWriter (java.io.CharArrayWriter)5 FileWriter (java.io.FileWriter)5 InputStream (java.io.InputStream)5 ResultSet (java.sql.ResultSet)5 InputSource (org.xml.sax.InputSource)5 PipedReader (java.io.PipedReader)4 CharBuffer (java.nio.CharBuffer)4 Signature (java.security.Signature)4