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