Search in sources :

Example 31 with FileReader

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();
}
Also used : SparseBooleanArray(android.util.SparseBooleanArray) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) FileReader(java.io.FileReader) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) NonNull(android.annotation.NonNull)

Example 32 with FileReader

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);
}
Also used : FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File)

Example 33 with FileReader

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);
    }
}
Also used : BufferedReader(java.io.BufferedReader) ArrayList(java.util.ArrayList) FileReader(java.io.FileReader) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException)

Example 34 with FileReader

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;
}
Also used : Matcher(java.util.regex.Matcher) BufferedReader(java.io.BufferedReader) Include(org.gradle.language.nativeplatform.internal.Include) FileReader(java.io.FileReader) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException)

Example 35 with FileReader

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
        }
    }
}
Also used : MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileWriter(java.io.FileWriter) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File)

Aggregations

FileReader (java.io.FileReader)1873 BufferedReader (java.io.BufferedReader)1289 IOException (java.io.IOException)893 File (java.io.File)811 FileNotFoundException (java.io.FileNotFoundException)304 ArrayList (java.util.ArrayList)274 Test (org.junit.Test)197 FileWriter (java.io.FileWriter)148 HashMap (java.util.HashMap)116 Reader (java.io.Reader)99 BufferedWriter (java.io.BufferedWriter)98 Properties (java.util.Properties)66 InputStreamReader (java.io.InputStreamReader)64 LineNumberReader (java.io.LineNumberReader)61 Matcher (java.util.regex.Matcher)61 Map (java.util.Map)59 List (java.util.List)56 PrintWriter (java.io.PrintWriter)51 StringTokenizer (java.util.StringTokenizer)51 HashSet (java.util.HashSet)50