use of java.io.FileReader in project platform_frameworks_base by android.
the class TaskPersister method loadPersistedTaskIdsForUser.
@NonNull
SparseBooleanArray loadPersistedTaskIdsForUser(int userId) {
if (mTaskIdsInFile.get(userId) != null) {
return mTaskIdsInFile.get(userId).clone();
}
final SparseBooleanArray persistedTaskIds = new SparseBooleanArray();
synchronized (mIoLock) {
BufferedReader reader = null;
String line;
try {
reader = new BufferedReader(new FileReader(getUserPersistedTaskIdsFile(userId)));
while ((line = reader.readLine()) != null) {
for (String taskIdString : line.split("\\s+")) {
int id = Integer.parseInt(taskIdString);
persistedTaskIds.put(id, true);
}
}
} catch (FileNotFoundException e) {
// File doesn't exist. Ignore.
} catch (Exception e) {
Slog.e(TAG, "Error while reading taskIds file for user " + userId, e);
} finally {
IoUtils.closeQuietly(reader);
}
}
mTaskIdsInFile.put(userId, persistedTaskIds);
return persistedTaskIds.clone();
}
use of java.io.FileReader in project platform_frameworks_base by android.
the class PhoneWindowManager method initializeHdmiState.
void initializeHdmiState() {
boolean plugged = false;
// watch for HDMI plug messages if the hdmi switch exists
if (new File("/sys/devices/virtual/switch/hdmi/state").exists()) {
mHDMIObserver.startObserving("DEVPATH=/devices/virtual/switch/hdmi");
final String filename = "/sys/class/switch/hdmi/state";
FileReader reader = null;
try {
reader = new FileReader(filename);
char[] buf = new char[15];
int n = reader.read(buf);
if (n > 1) {
plugged = 0 != Integer.parseInt(new String(buf, 0, n - 1));
}
} catch (IOException ex) {
Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
} catch (NumberFormatException ex) {
Slog.w(TAG, "Couldn't read hdmi state from " + filename + ": " + ex);
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException ex) {
}
}
}
}
// This dance forces the code in setHdmiPlugged to run.
// Always do this so the sticky intent is stuck (to false) if there is no hdmi.
mHdmiPlugged = !plugged;
setHdmiPlugged(!mHdmiPlugged);
}
use of java.io.FileReader in project gradle by gradle.
the class TestFile method linesThat.
public List<String> linesThat(Matcher<? super String> matcher) {
try {
BufferedReader reader = new BufferedReader(new FileReader(this));
try {
List<String> lines = new ArrayList<String>();
String line;
while ((line = reader.readLine()) != null) {
if (matcher.matches(line)) {
lines.add(line);
}
}
return lines;
} finally {
reader.close();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of java.io.FileReader in project gradle by gradle.
the class RegexBackedCSourceParser method parseFile.
private List<Include> parseFile(File file) {
List<Include> includes = Lists.newArrayList();
try {
BufferedReader bf = new BufferedReader(new PreprocessingReader(new BufferedReader(new FileReader(file))));
try {
String line;
while ((line = bf.readLine()) != null) {
Matcher m = includePattern.matcher(line.trim());
if (m.matches()) {
boolean isImport = "import".equals(m.group(1));
String value = m.group(2);
includes.add(DefaultInclude.parse(value, isImport));
}
}
} finally {
IOUtils.closeQuietly(bf);
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return includes;
}
use of java.io.FileReader in project grails-maven by grails.
the class AbstractGrailsMojo method handleVersionSync.
private void handleVersionSync() throws MojoExecutionException {
// Search for all Grails plugin dependencies and install
// any that haven't already been installed.
final Properties metadata = new Properties();
File metadataFile = new File(getBasedir(), "application.properties");
FileReader reader = null;
FileWriter writer = null;
try {
boolean created = true;
if (!metadataFile.exists()) {
created = metadataFile.createNewFile();
}
if (created) {
reader = new FileReader(metadataFile);
metadata.load(reader);
boolean metadataModified = syncVersions(metadata);
if (metadataModified) {
writer = new FileWriter(metadataFile);
metadata.store(writer, "Grails Metadata file");
}
}
} catch (IOException e) {
throw new MojoExecutionException("Failed to sync application version with Maven plugin defined version");
} finally {
try {
if (reader != null)
reader.close();
if (writer != null)
writer.close();
} catch (IOException e) {
// ignore
}
}
}
Aggregations