Search in sources :

Example 56 with CharArrayReader

use of java.io.CharArrayReader in project robovm by robovm.

the class OldCharArrayReaderTest method test_close.

/**
     * java.io.CharArrayReader#close()
     */
public void test_close() {
    cr = new CharArrayReader(hw);
    cr.close();
    try {
        cr.read();
        fail("Failed to throw exception on read from closed stream");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) IOException(java.io.IOException)

Example 57 with CharArrayReader

use of java.io.CharArrayReader in project robovm by robovm.

the class OldCharArrayReaderTest method test_reset.

/**
     * java.io.CharArrayReader#reset()
     */
public void test_reset() throws IOException {
    cr = new CharArrayReader(hw);
    cr.skip(5L);
    cr.mark(100);
    cr.read();
    cr.reset();
    assertEquals("Test 1: Reset failed to return to marker position.", 'W', cr.read());
    cr.close();
    try {
        cr.reset();
        fail("Test 2: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) IOException(java.io.IOException)

Example 58 with CharArrayReader

use of java.io.CharArrayReader in project robovm by robovm.

the class OldCharArrayReaderTest method test_skipJ.

public void test_skipJ() throws IOException {
    long skipped = 0;
    cr = new CharArrayReader(hw);
    skipped = cr.skip(5L);
    assertEquals("Test 1: Failed to skip correct number of chars;", 5L, skipped);
    assertEquals("Test 2: Skip skipped wrong chars;", 'W', cr.read());
    cr.close();
    try {
        cr.skip(1);
        fail("Test 3: IOException expected.");
    } catch (IOException e) {
    // Expected.
    }
}
Also used : CharArrayReader(java.io.CharArrayReader) IOException(java.io.IOException)

Example 59 with CharArrayReader

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

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);
            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);
            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 60 with CharArrayReader

use of java.io.CharArrayReader in project nhin-d by DirectProject.

the class XslConversion method run.

/**
     * Perform the XSL conversion using the provided map file and message.
     * 
     * @param mapFile
     *            The map file.
     * @param message
     *            The message.
     * @return an XSL conversion.
     * @throws Exception
     */
public String run(String mapFile, String message) throws Exception {
    long start = System.currentTimeMillis();
    String retXml = "";
    Transformer transformer = null;
    try {
        if (conversions.containsKey(mapFile)) {
            Templates temp = conversions.get(mapFile);
            transformer = temp.newTransformer();
            LOGGER.info("From xsl cache");
        } else {
            synchronized (conversions) {
                if (!conversions.containsKey(mapFile)) {
                    /*
                         * Use the static TransformerFactory.newInstance()
                         * method to instantiate a TransformerFactory. The
                         * javax.xml.transform.TransformerFactory system
                         * property setting determines the actual class to
                         * instantiate --
                         * org.apache.xalan.transformer.TransformerImpl.
                         */
                    TransformerFactory tFactory = TransformerFactory.newInstance();
                    /*
                         * Use the TransformerFactory to instantiate a Template
                         * that is thread safe for use in generating Transfomers
                         */
                    InputStream is = this.getClass().getClassLoader().getResourceAsStream(mapFile);
                    if (is == null) {
                        LOGGER.info("Mapfile did not read " + mapFile);
                    }
                    Templates temp = tFactory.newTemplates(new StreamSource(is));
                    transformer = temp.newTransformer();
                    conversions.put(mapFile, temp);
                }
            }
        }
        CharArrayWriter to = new CharArrayWriter();
        transformer.transform(new StreamSource(new CharArrayReader(message.toCharArray())), new StreamResult(to));
        retXml = to.toString();
    } catch (TransformerConfigurationException e) {
        LOGGER.error("Exception occured during XSL conversion", e);
        throw e;
    } catch (TransformerException e) {
        LOGGER.error("Exception occured during XSL conversion", e);
        throw e;
    }
    if (LOGGER.isInfoEnabled()) {
        long elapse = System.currentTimeMillis() - start;
        LOGGER.info("Started at " + new Timestamp(start).toString());
        LOGGER.info("Elapsed conversion time was " + elapse + "ms");
    }
    return retXml;
}
Also used : Transformer(javax.xml.transform.Transformer) TransformerFactory(javax.xml.transform.TransformerFactory) StreamResult(javax.xml.transform.stream.StreamResult) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) InputStream(java.io.InputStream) StreamSource(javax.xml.transform.stream.StreamSource) Templates(javax.xml.transform.Templates) Timestamp(java.sql.Timestamp) CharArrayWriter(java.io.CharArrayWriter) CharArrayReader(java.io.CharArrayReader) TransformerException(javax.xml.transform.TransformerException)

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