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