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.
}
}
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.
}
}
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.
}
}
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);
}
}
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;
}
Aggregations