Search in sources :

Example 21 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 22 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 23 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 24 with CharArrayReader

use of java.io.CharArrayReader in project jackrabbit by apache.

the class ClonedInputSource method cloneInputSource.

/**
     * Make a clone if this input source. The input source being cloned is still
     * valid after cloning.
     *
     * @return input source clone.
     */
public ClonedInputSource cloneInputSource() {
    ClonedInputSource res = new ClonedInputSource(characterArray, byteArray);
    res.setEncoding(getEncoding());
    res.setPublicId(getPublicId());
    res.setSystemId(getSystemId());
    if (byteArray != null) {
        res.setByteStream(new ByteArrayInputStream(byteArray));
    }
    if (characterArray != null) {
        res.setCharacterStream(new CharArrayReader(characterArray));
    }
    return res;
}
Also used : CharArrayReader(java.io.CharArrayReader) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 25 with CharArrayReader

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

the class ModelGen method loadXml.

public static Element loadXml(File configXml) throws Exception {
    SAXBuilder saxBuilder = new SAXBuilder();
    saxBuilder.setEntityResolver(new EntityResolver() {

        public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
            return new InputSource(new CharArrayReader(new char[0]));
        }
    });
    final Document document = saxBuilder.build(configXml);
    return document.getRootElement();
}
Also used : SAXBuilder(org.jdom.input.SAXBuilder) InputSource(org.xml.sax.InputSource) XMLInputSource(org.apache.xerces.xni.parser.XMLInputSource) CharArrayReader(java.io.CharArrayReader) XMLEntityResolver(org.apache.xerces.xni.parser.XMLEntityResolver) EntityResolver(org.xml.sax.EntityResolver) IOException(java.io.IOException) Document(org.jdom.Document) SAXException(org.xml.sax.SAXException)

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