Search in sources :

Example 31 with FileWriter

use of java.io.FileWriter in project platform_frameworks_base by android.

the class VideoDumpView method onResume.

@Override
public void onResume() {
    Log.d(TAG, "onResume");
    mMediaPlayer = new MediaPlayer();
    try {
        mMediaPlayer.setDataSource(VideoDumpConfig.VIDEO_URI);
        class RGBFilter implements FilenameFilter {

            public boolean accept(File dir, String name) {
                return (name.endsWith(VideoDumpConfig.IMAGE_SUFFIX));
            }
        }
        File dump_dir = new File(VideoDumpConfig.ROOT_DIR);
        File[] dump_files = dump_dir.listFiles(new RGBFilter());
        for (File dump_file : dump_files) {
            dump_file.delete();
        }
        File image_list = new File(VideoDumpConfig.ROOT_DIR + VideoDumpConfig.IMAGES_LIST);
        image_list.delete();
        mImageListWriter = new BufferedWriter(new FileWriter(image_list));
    } catch (java.io.IOException e) {
        Log.e(TAG, e.getMessage(), e);
    }
    queueEvent(new Runnable() {

        public void run() {
            mRenderer.setMediaPlayer(mMediaPlayer);
            mRenderer.setImageListWriter(mImageListWriter);
        }
    });
    super.onResume();
}
Also used : FilenameFilter(java.io.FilenameFilter) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File) MediaPlayer(android.media.MediaPlayer) BufferedWriter(java.io.BufferedWriter)

Example 32 with FileWriter

use of java.io.FileWriter in project platform_frameworks_base by android.

the class DpmTestUtils method writeToFile.

public static void writeToFile(File path, String content) throws IOException {
    path.getParentFile().mkdirs();
    try (FileWriter writer = new FileWriter(path)) {
        Log.i(DpmTestBase.TAG, "Writing to " + path);
        Log.i(DpmTestBase.TAG, content);
        writer.write(content);
    }
}
Also used : FileWriter(java.io.FileWriter)

Example 33 with FileWriter

use of java.io.FileWriter in project platform_frameworks_base by android.

the class CSVWriterFilter method onProcess.

@Override
protected void onProcess() {
    Log.v(TAG, "in csv writer on process");
    FrameValue sharpnessValue = getConnectedInputPort("sharpness").pullFrame().asFrameValue();
    float sharpness = ((Float) sharpnessValue.getValue()).floatValue();
    FrameValue overExposureValue = getConnectedInputPort("overExposure").pullFrame().asFrameValue();
    float overExposure = ((Float) overExposureValue.getValue()).floatValue();
    FrameValue underExposureValue = getConnectedInputPort("underExposure").pullFrame().asFrameValue();
    float underExposure = ((Float) underExposureValue.getValue()).floatValue();
    FrameValue colorfulnessValue = getConnectedInputPort("colorfulness").pullFrame().asFrameValue();
    float colorfulness = ((Float) colorfulnessValue.getValue()).floatValue();
    FrameValue contrastValue = getConnectedInputPort("contrastRating").pullFrame().asFrameValue();
    float contrast = ((Float) contrastValue.getValue()).floatValue();
    FrameValue brightnessValue = getConnectedInputPort("brightness").pullFrame().asFrameValue();
    float brightness = ((Float) brightnessValue.getValue()).floatValue();
    FrameValue motionValuesFrameValue = getConnectedInputPort("motionValues").pullFrame().asFrameValue();
    float[] motionValues = (float[]) motionValuesFrameValue.getValue();
    float vectorAccel = (float) Math.sqrt(Math.pow(motionValues[0], 2) + Math.pow(motionValues[1], 2) + Math.pow(motionValues[2], 2));
    FrameValue imageFileNameFrameValue = getConnectedInputPort("imageFileName").pullFrame().asFrameValue();
    String imageFileName = ((String) imageFileNameFrameValue.getValue());
    FrameValue csvFilePathFrameValue = getConnectedInputPort("csvFilePath").pullFrame().asFrameValue();
    String csvFilePath = ((String) csvFilePathFrameValue.getValue());
    if (mFirstTime) {
        try {
            FileWriter fileWriter = new FileWriter(csvFilePath + "/CSVFile.csv");
            BufferedWriter csvWriter = new BufferedWriter(fileWriter);
            csvWriter.write("FileName,Sharpness,OverExposure,UnderExposure,Colorfulness," + "ContrastRating,Brightness,Motion");
            csvWriter.newLine();
            csvWriter.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        mFirstTime = false;
    }
    try {
        Log.v(TAG, "about to write to file");
        FileWriter fileWriter = new FileWriter(csvFilePath + mFileName, true);
        BufferedWriter csvWriter = new BufferedWriter(fileWriter);
        csvWriter.write(imageFileName + "," + sharpness + "," + overExposure + "," + underExposure + "," + colorfulness + "," + contrast + "," + brightness + "," + vectorAccel);
        Log.v(TAG, "" + imageFileName + "," + sharpness + "," + overExposure + "," + underExposure + "," + colorfulness + "," + contrast + "," + brightness + "," + vectorAccel);
        csvWriter.newLine();
        csvWriter.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : FileWriter(java.io.FileWriter) IOException(java.io.IOException) FrameValue(androidx.media.filterfw.FrameValue) BufferedWriter(java.io.BufferedWriter)

Example 34 with FileWriter

use of java.io.FileWriter in project antlr4 by antlr.

the class LogManager method save.

public void save(String filename) throws IOException {
    FileWriter fw = new FileWriter(filename);
    BufferedWriter bw = new BufferedWriter(fw);
    try {
        bw.write(toString());
    } finally {
        bw.close();
    }
}
Also used : FileWriter(java.io.FileWriter) BufferedWriter(java.io.BufferedWriter)

Example 35 with FileWriter

use of java.io.FileWriter in project platform_frameworks_base by android.

the class TaskPersister method writePersistedTaskIdsForUser.

@VisibleForTesting
void writePersistedTaskIdsForUser(@NonNull SparseBooleanArray taskIds, int userId) {
    if (userId < 0) {
        return;
    }
    final File persistedTaskIdsFile = getUserPersistedTaskIdsFile(userId);
    synchronized (mIoLock) {
        BufferedWriter writer = null;
        try {
            writer = new BufferedWriter(new FileWriter(persistedTaskIdsFile));
            for (int i = 0; i < taskIds.size(); i++) {
                if (taskIds.valueAt(i)) {
                    writer.write(String.valueOf(taskIds.keyAt(i)));
                    writer.newLine();
                }
            }
        } catch (Exception e) {
            Slog.e(TAG, "Error while writing taskIds file for user " + userId, e);
        } finally {
            IoUtils.closeQuietly(writer);
        }
    }
}
Also used : FileWriter(java.io.FileWriter) AtomicFile(android.util.AtomicFile) File(java.io.File) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) BufferedWriter(java.io.BufferedWriter) VisibleForTesting(com.android.internal.annotations.VisibleForTesting)

Aggregations

FileWriter (java.io.FileWriter)1994 File (java.io.File)1195 IOException (java.io.IOException)866 BufferedWriter (java.io.BufferedWriter)798 PrintWriter (java.io.PrintWriter)329 Test (org.junit.Test)243 Writer (java.io.Writer)181 FileReader (java.io.FileReader)148 BufferedReader (java.io.BufferedReader)128 ArrayList (java.util.ArrayList)121 FileNotFoundException (java.io.FileNotFoundException)78 Date (java.util.Date)68 FileOutputStream (java.io.FileOutputStream)65 Properties (java.util.Properties)65 HashMap (java.util.HashMap)61 FileInputStream (java.io.FileInputStream)54 StringWriter (java.io.StringWriter)51 Path (org.apache.hadoop.fs.Path)50 Map (java.util.Map)42 InputStreamReader (java.io.InputStreamReader)34