Search in sources :

Example 16 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 17 with CharArrayReader

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

the class DriverManagerTests method tests18.

/**
     * Create a PrintWriter and use to to send output via DriverManager.println
     * Validate that if you disable the writer, the output sent is not present
     */
@Test
public void tests18() throws Exception {
    CharArrayWriter cw = new CharArrayWriter();
    PrintWriter pw = new PrintWriter(cw);
    DriverManager.setLogWriter(pw);
    assertTrue(DriverManager.getLogWriter() == pw);
    DriverManager.println(results[0]);
    DriverManager.setLogWriter(null);
    assertTrue(DriverManager.getLogWriter() == null);
    DriverManager.println(noOutput);
    DriverManager.setLogWriter(pw);
    DriverManager.println(results[1]);
    DriverManager.println(results[2]);
    DriverManager.println(results[3]);
    DriverManager.setLogWriter(null);
    DriverManager.println(noOutput);
    /*
         * Check we do not get the output when the stream is disabled
         */
    BufferedReader reader = new BufferedReader(new CharArrayReader(cw.toCharArray()));
    for (String result : results) {
        assertTrue(result.equals(reader.readLine()));
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) BufferedReader(java.io.BufferedReader) CharArrayWriter(java.io.CharArrayWriter) PrintWriter(java.io.PrintWriter) Test(org.testng.annotations.Test)

Example 18 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)

Example 19 with CharArrayReader

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

the class bug8005391 method main.

public static void main(String[] args) throws Exception {
    int N = 10;
    for (int i = 0; i < N; i++) {
        HTMLEditorKit kit = new HTMLEditorKit();
        Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
        HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
        HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
        parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true);
        htmlReader.flush();
        CharArrayWriter writer = new CharArrayWriter(1000);
        kit.write(writer, doc, 0, doc.getLength());
        writer.flush();
        String result = writer.toString();
        if (!result.contains("<tt><a")) {
            throw new RuntimeException("The <a> and <tt> tags are swapped");
        }
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) HTMLDocument(javax.swing.text.html.HTMLDocument) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) CharArrayWriter(java.io.CharArrayWriter)

Example 20 with CharArrayReader

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

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)

Aggregations

CharArrayReader (java.io.CharArrayReader)53 IOException (java.io.IOException)31 BufferedReader (java.io.BufferedReader)14 Reader (java.io.Reader)7 File (java.io.File)6 StringReader (java.io.StringReader)6 BufferedWriter (java.io.BufferedWriter)5 FileReader (java.io.FileReader)5 FileWriter (java.io.FileWriter)5 InputStreamReader (java.io.InputStreamReader)5 CharArrayWriter (java.io.CharArrayWriter)4 PipedReader (java.io.PipedReader)4 Support_StringReader (tests.support.Support_StringReader)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputSource (org.xml.sax.InputSource)3 XmlOffshoot (alma.demo.XmlOffshoot)2 XmlEntityStruct (alma.xmlentity.XmlEntityStruct)2 InputStream (java.io.InputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 DocumentBuilder (javax.xml.parsers.DocumentBuilder)2