use of java.io.BufferedWriter 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);
}
}
use of java.io.BufferedWriter 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();
}
}
use of java.io.BufferedWriter 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);
}
}
}
use of java.io.BufferedWriter in project platform_frameworks_base by android.
the class AppLaunch method testMeasureStartUpTime.
public void testMeasureStartUpTime() throws RemoteException, NameNotFoundException, IOException, InterruptedException {
InstrumentationTestRunner instrumentation = (InstrumentationTestRunner) getInstrumentation();
Bundle args = instrumentation.getArguments();
mAm = ActivityManagerNative.getDefault();
String launchDirectory = args.getString(KEY_LAUNCH_DIRECTORY);
mTraceDirectoryStr = args.getString(KEY_TRACE_DIRECTORY);
mDropCache = Boolean.parseBoolean(args.getString(KEY_DROP_CACHE));
mSimplePerfCmd = args.getString(KEY_SIMPLEPPERF_CMD);
mLaunchOrder = args.getString(KEY_LAUNCH_ORDER, LAUNCH_ORDER_CYCLIC);
createMappings();
parseArgs(args);
checkAccountSignIn();
// Root directory for applaunch file to log the app launch output
// Will be useful in case of simpleperf command is used
File launchRootDir = null;
if (null != launchDirectory && !launchDirectory.isEmpty()) {
launchRootDir = new File(launchDirectory);
if (!launchRootDir.exists() && !launchRootDir.mkdirs()) {
throw new IOException("Unable to create the destination directory");
}
}
try {
File launchSubDir = new File(launchRootDir, LAUNCH_SUB_DIRECTORY);
if (!launchSubDir.exists() && !launchSubDir.mkdirs()) {
throw new IOException("Unable to create the lauch file sub directory");
}
mFile = new File(launchSubDir, LAUNCH_FILE);
mOutputStream = new FileOutputStream(mFile);
mBufferedWriter = new BufferedWriter(new OutputStreamWriter(mOutputStream));
// Root directory for trace file during the launches
File rootTrace = null;
File rootTraceSubDir = null;
int traceBufferSize = 0;
int traceDumpInterval = 0;
Set<String> traceCategoriesSet = null;
if (null != mTraceDirectoryStr && !mTraceDirectoryStr.isEmpty()) {
rootTrace = new File(mTraceDirectoryStr);
if (!rootTrace.exists() && !rootTrace.mkdirs()) {
throw new IOException("Unable to create the trace directory");
}
rootTraceSubDir = new File(rootTrace, TRACE_SUB_DIRECTORY);
if (!rootTraceSubDir.exists() && !rootTraceSubDir.mkdirs()) {
throw new IOException("Unable to create the trace sub directory");
}
assertNotNull("Trace iteration parameter is mandatory", args.getString(KEY_TRACE_ITERATIONS));
mTraceLaunchCount = Integer.parseInt(args.getString(KEY_TRACE_ITERATIONS));
String traceCategoriesStr = args.getString(KEY_TRACE_CATEGORY, DEFAULT_TRACE_CATEGORIES);
traceBufferSize = Integer.parseInt(args.getString(KEY_TRACE_BUFFERSIZE, DEFAULT_TRACE_BUFFER_SIZE));
traceDumpInterval = Integer.parseInt(args.getString(KEY_TRACE_DUMPINTERVAL, DEFAULT_TRACE_DUMP_INTERVAL));
traceCategoriesSet = new HashSet<String>();
if (!traceCategoriesStr.isEmpty()) {
String[] traceCategoriesSplit = traceCategoriesStr.split(DELIMITER);
for (int i = 0; i < traceCategoriesSplit.length; i++) {
traceCategoriesSet.add(traceCategoriesSplit[i]);
}
}
}
// Get the app launch order based on launch order, trial launch,
// launch iterations and trace iterations
setLaunchOrder();
for (LaunchOrder launch : mLaunchOrderList) {
// launch time calculations.
if (launch.getLaunchReason().equals(TRIAL_LAUNCH)) {
// In the "applaunch.txt" file, trail launches is referenced using
// "TRIAL_LAUNCH"
long launchTime = startApp(launch.getApp(), true, launch.getLaunchReason());
if (launchTime < 0) {
List<Long> appLaunchList = new ArrayList<Long>();
appLaunchList.add(-1L);
mNameToLaunchTime.put(launch.getApp(), appLaunchList);
// error should have already been logged by startApp
continue;
}
sleep(INITIAL_LAUNCH_IDLE_TIMEOUT);
closeApp(launch.getApp(), true);
dropCache();
sleep(BETWEEN_LAUNCH_SLEEP_TIMEOUT);
}
// App launch times used for final calculation
if (launch.getLaunchReason().contains(LAUNCH_ITERATION_PREFIX)) {
long launchTime = -1;
if (null != mNameToLaunchTime.get(launch.getApp())) {
long firstLaunchTime = mNameToLaunchTime.get(launch.getApp()).get(0);
if (firstLaunchTime < 0) {
// skip if the app has failures while launched first
continue;
}
}
// In the "applaunch.txt" file app launches are referenced using
// "LAUNCH_ITERATION - ITERATION NUM"
launchTime = startApp(launch.getApp(), true, launch.getLaunchReason());
if (launchTime < 0) {
// if it fails once, skip the rest of the launches
List<Long> appLaunchList = new ArrayList<Long>();
appLaunchList.add(-1L);
mNameToLaunchTime.put(launch.getApp(), appLaunchList);
continue;
} else {
if (null != mNameToLaunchTime.get(launch.getApp())) {
mNameToLaunchTime.get(launch.getApp()).add(launchTime);
} else {
List<Long> appLaunchList = new ArrayList<Long>();
appLaunchList.add(launchTime);
mNameToLaunchTime.put(launch.getApp(), appLaunchList);
}
}
sleep(POST_LAUNCH_IDLE_TIMEOUT);
closeApp(launch.getApp(), true);
dropCache();
sleep(BETWEEN_LAUNCH_SLEEP_TIMEOUT);
}
// launch time calculations.
if (launch.getLaunchReason().contains(TRACE_ITERATION_PREFIX)) {
AtraceLogger atraceLogger = AtraceLogger.getAtraceLoggerInstance(getInstrumentation());
// Start the trace
try {
atraceLogger.atraceStart(traceCategoriesSet, traceBufferSize, traceDumpInterval, rootTraceSubDir, String.format("%s-%s", launch.getApp(), launch.getLaunchReason()));
startApp(launch.getApp(), true, launch.getLaunchReason());
sleep(POST_LAUNCH_IDLE_TIMEOUT);
} finally {
// Stop the trace
atraceLogger.atraceStop();
closeApp(launch.getApp(), true);
dropCache();
sleep(BETWEEN_LAUNCH_SLEEP_TIMEOUT);
}
}
}
} finally {
if (null != mBufferedWriter) {
mBufferedWriter.close();
}
}
for (String app : mNameToResultKey.keySet()) {
StringBuilder launchTimes = new StringBuilder();
for (Long launch : mNameToLaunchTime.get(app)) {
launchTimes.append(launch);
launchTimes.append(",");
}
mResult.putString(mNameToResultKey.get(app), launchTimes.toString());
}
instrumentation.sendStatus(0, mResult);
}
use of java.io.BufferedWriter in project androidannotations by androidannotations.
the class ViewServer method writeValue.
private static boolean writeValue(Socket client, String value) {
boolean result;
BufferedWriter out = null;
try {
OutputStream clientStream = client.getOutputStream();
out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
out.write(value);
out.write("\n");
out.flush();
result = true;
} catch (Exception e) {
result = false;
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
result = false;
}
}
}
return result;
}
Aggregations