use of java.io.BufferedWriter in project qi4j-sdk by Qi4j.
the class Report method writeTo.
public void writeTo(Writer writer) throws IOException {
BufferedWriter out;
if (writer instanceof BufferedWriter) {
out = (BufferedWriter) writer;
} else {
out = new BufferedWriter(writer);
}
out.write(toXML());
out.flush();
}
use of java.io.BufferedWriter in project android_frameworks_base by ParanoidAndroid.
the class DdmHandleViewDebug method profileView.
/** Profiles provided view. */
private Chunk profileView(View rootView, final View targetView) {
ByteArrayOutputStream b = new ByteArrayOutputStream(32 * 1024);
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(b), 32 * 1024);
try {
ViewDebug.profileViewAndChildren(targetView, bw);
} catch (IOException e) {
return createFailChunk(1, "Unexpected error while profiling view: " + e.getMessage());
} finally {
try {
bw.close();
} catch (IOException e) {
// ignore
}
}
byte[] data = b.toByteArray();
return new Chunk(CHUNK_VUOP, data, 0, data.length);
}
use of java.io.BufferedWriter in project android_frameworks_base by ParanoidAndroid.
the class Process method openZygoteSocketIfNeeded.
/**
* Tries to open socket to Zygote process if not already open. If
* already open, does nothing. May block and retry.
*/
private static void openZygoteSocketIfNeeded() throws ZygoteStartFailedEx {
int retryCount;
if (sPreviousZygoteOpenFailed) {
/*
* If we've failed before, expect that we'll fail again and
* don't pause for retries.
*/
retryCount = 0;
} else {
retryCount = 10;
}
/*
* See bug #811181: Sometimes runtime can make it up before zygote.
* Really, we'd like to do something better to avoid this condition,
* but for now just wait a bit...
*/
for (int retry = 0; (sZygoteSocket == null) && (retry < (retryCount + 1)); retry++) {
if (retry > 0) {
try {
Log.i("Zygote", "Zygote not up yet, sleeping...");
Thread.sleep(ZYGOTE_RETRY_MILLIS);
} catch (InterruptedException ex) {
// should never happen
}
}
try {
sZygoteSocket = new LocalSocket();
sZygoteSocket.connect(new LocalSocketAddress(ZYGOTE_SOCKET, LocalSocketAddress.Namespace.RESERVED));
sZygoteInputStream = new DataInputStream(sZygoteSocket.getInputStream());
sZygoteWriter = new BufferedWriter(new OutputStreamWriter(sZygoteSocket.getOutputStream()), 256);
Log.i("Zygote", "Process: zygote socket opened");
sPreviousZygoteOpenFailed = false;
break;
} catch (IOException ex) {
if (sZygoteSocket != null) {
try {
sZygoteSocket.close();
} catch (IOException ex2) {
Log.e(LOG_TAG, "I/O exception on close after exception", ex2);
}
}
sZygoteSocket = null;
}
}
if (sZygoteSocket == null) {
sPreviousZygoteOpenFailed = true;
throw new ZygoteStartFailedEx("connect failed");
}
}
use of java.io.BufferedWriter in project android_frameworks_base by ParanoidAndroid.
the class MultipartTest method testParts.
public void testParts() throws Exception {
StringBuffer filebuffer = new StringBuffer();
String filepartStr = "this is file part";
filebuffer.append(filepartStr);
File upload = File.createTempFile("Multipart", "test");
FileWriter outFile = new FileWriter(upload);
BufferedWriter out = new BufferedWriter(outFile);
try {
out.write(filebuffer.toString());
out.flush();
} finally {
out.close();
}
Part[] parts = new Part[3];
parts[0] = new StringPart("stringpart", "PART1!!");
parts[1] = new FilePart(upload.getName(), upload);
parts[2] = new StringPart("stringpart", "PART2!!");
MultipartEntity me = new MultipartEntity(parts);
ByteArrayOutputStream os = new ByteArrayOutputStream();
me.writeTo(os);
Header h = me.getContentType();
String boundry = EncodingUtils.getAsciiString(me.getMultipartBoundary());
StringBuffer contentType = new StringBuffer("multipart/form-data");
contentType.append("; boundary=");
contentType.append(boundry);
assertEquals("Multipart content type error", contentType.toString(), h.getValue());
final String CRLF = "\r\n";
StringBuffer output = new StringBuffer();
output.append("--");
output.append(boundry);
output.append(CRLF);
output.append("Content-Disposition: form-data; name=\"stringpart\"");
output.append(CRLF);
output.append("Content-Type: text/plain; charset=US-ASCII");
output.append(CRLF);
output.append("Content-Transfer-Encoding: 8bit");
output.append(CRLF);
output.append(CRLF);
output.append("PART1!!");
output.append(CRLF);
output.append("--");
output.append(boundry);
output.append(CRLF);
output.append("Content-Disposition: form-data; name=\"");
output.append(upload.getName());
output.append("\"; filename=\"");
output.append(upload.getName());
output.append("\"");
output.append(CRLF);
output.append("Content-Type: application/octet-stream; charset=ISO-8859-1");
output.append(CRLF);
output.append("Content-Transfer-Encoding: binary");
output.append(CRLF);
output.append(CRLF);
output.append(filepartStr);
output.append(CRLF);
output.append("--");
output.append(boundry);
output.append(CRLF);
output.append("Content-Disposition: form-data; name=\"stringpart\"");
output.append(CRLF);
output.append("Content-Type: text/plain; charset=US-ASCII");
output.append(CRLF);
output.append("Content-Transfer-Encoding: 8bit");
output.append(CRLF);
output.append(CRLF);
output.append("PART2!!");
output.append(CRLF);
output.append("--");
output.append(boundry);
output.append("--");
output.append(CRLF);
// System.out.print(output.toString());
assertEquals("Multipart content error", output.toString(), os.toString());
// System.out.print(os.toString());
}
use of java.io.BufferedWriter in project android_frameworks_base by ParanoidAndroid.
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();
}
Aggregations