use of java.io.OutputStream in project platform_frameworks_base by android.
the class WindowManagerService method viewServerGetFocusedWindow.
// TODO(multidisplay): Extend to multiple displays.
/**
* Returns the focused window in the following format:
* windowHashCodeInHexadecimal windowName
*
* @param client The remote client to send the listing to.
* @return False if an error occurred, true otherwise.
*/
boolean viewServerGetFocusedWindow(Socket client) {
if (isSystemSecure()) {
return false;
}
boolean result = true;
WindowState focusedWindow = getFocusedWindow();
BufferedWriter out = null;
// Any uncaught exception will crash the system process
try {
OutputStream clientStream = client.getOutputStream();
out = new BufferedWriter(new OutputStreamWriter(clientStream), 8 * 1024);
if (focusedWindow != null) {
out.write(Integer.toHexString(System.identityHashCode(focusedWindow)));
out.write(' ');
out.append(focusedWindow.mAttrs.getTitle());
}
out.write('\n');
out.flush();
} catch (Exception e) {
result = false;
} finally {
if (out != null) {
try {
out.close();
} catch (IOException e) {
result = false;
}
}
}
return result;
}
use of java.io.OutputStream in project jstorm by alibaba.
the class Utils method unJar.
/*
* Unpack matching files from a jar. Entries inside the jar that do
* not match the given pattern will be skipped.
*
* @param jarFile the .jar file to unpack
* @param toDir the destination directory into which to unpack the jar
*/
public static void unJar(File jarFile, File toDir) throws IOException {
JarFile jar = new JarFile(jarFile);
try {
Enumeration<JarEntry> entries = jar.entries();
while (entries.hasMoreElements()) {
final JarEntry entry = entries.nextElement();
if (!entry.isDirectory()) {
InputStream in = jar.getInputStream(entry);
try {
File file = new File(toDir, entry.getName());
ensureDirectory(file.getParentFile());
OutputStream out = new FileOutputStream(file);
try {
copyBytes(in, out, 8192);
} finally {
out.close();
}
} finally {
in.close();
}
}
}
} finally {
jar.close();
}
}
use of java.io.OutputStream in project lombok by rzwitserloot.
the class CreateLombokRuntimeApp method writeRuntimeJar.
private int writeRuntimeJar(File outFile) throws Exception {
Map<String, Class<?>> deps = new LinkedHashMap<String, Class<?>>();
for (RuntimeDependencyInfo info : infoObjects) {
List<String> depNames = info.getRuntimeDependencies();
if (depNames != null)
for (String depName : depNames) {
if (!deps.containsKey(depName))
deps.put(depName, info.getClass());
}
}
if (deps.isEmpty()) {
System.out.println("Not generating lombok-runtime.jar: No lombok transformations currently have any runtime dependencies!");
return 1;
}
OutputStream out = new FileOutputStream(outFile);
boolean success = false;
try {
JarOutputStream jar = new JarOutputStream(out);
deps.put("LICENSE", CreateLombokRuntimeApp.class);
deps.put("AUTHORS", CreateLombokRuntimeApp.class);
for (Entry<String, Class<?>> dep : deps.entrySet()) {
InputStream in = dep.getValue().getResourceAsStream("/" + dep.getKey());
try {
if (in == null) {
throw new Fail(String.format("Dependency %s contributed by %s cannot be found", dep.getKey(), dep.getValue()));
}
writeIntoJar(jar, dep.getKey(), in);
} finally {
if (in != null)
in.close();
}
}
jar.close();
out.close();
System.out.println("Successfully created: " + canonical(outFile));
return 0;
} catch (Throwable t) {
try {
out.close();
} catch (Throwable ignore) {
}
if (!success)
outFile.delete();
if (t instanceof Fail) {
System.err.println(t.getMessage());
return 1;
} else if (t instanceof Exception) {
throw (Exception) t;
} else if (t instanceof Error) {
throw (Error) t;
} else {
throw new Exception(t);
}
}
}
use of java.io.OutputStream in project lombok by rzwitserloot.
the class AssertionLogger method logToFile.
private static synchronized void logToFile(String msg) {
if (msg == null)
return;
try {
OutputStream out = new FileOutputStream(LOG_PATH, true);
out.write(msg.getBytes("UTF-8"));
out.close();
} catch (Exception e) {
throw new RuntimeException("assertion logging can't write to log file", e);
}
}
use of java.io.OutputStream in project Conversations by siacs.
the class PgpDecryptionService method executeApi.
private void executeApi(Message message) {
synchronized (message) {
Intent params = new Intent();
params.setAction(OpenPgpApi.ACTION_DECRYPT_VERIFY);
if (message.getType() == Message.TYPE_TEXT) {
InputStream is = new ByteArrayInputStream(message.getBody().getBytes());
final OutputStream os = new ByteArrayOutputStream();
Intent result = getOpenPgpApi().executeApi(params, is, os);
switch(result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
case OpenPgpApi.RESULT_CODE_SUCCESS:
try {
os.flush();
final String body = os.toString();
if (body == null) {
throw new IOException("body was null");
}
message.setBody(body);
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
final HttpConnectionManager manager = mXmppConnectionService.getHttpConnectionManager();
if (message.trusted() && message.treatAsDownloadable() != Message.Decision.NEVER && manager.getAutoAcceptFileSize() > 0) {
manager.createNewDownloadConnection(message);
}
} catch (IOException e) {
message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
}
mXmppConnectionService.updateMessage(message);
break;
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
synchronized (PgpDecryptionService.this) {
PendingIntent pendingIntent = result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
messages.addFirst(message);
currentMessage = null;
storePendingIntent(pendingIntent);
}
break;
case OpenPgpApi.RESULT_CODE_ERROR:
message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
mXmppConnectionService.updateMessage(message);
break;
}
} else if (message.getType() == Message.TYPE_IMAGE || message.getType() == Message.TYPE_FILE) {
try {
final DownloadableFile inputFile = mXmppConnectionService.getFileBackend().getFile(message, false);
final DownloadableFile outputFile = mXmppConnectionService.getFileBackend().getFile(message, true);
outputFile.getParentFile().mkdirs();
outputFile.createNewFile();
InputStream is = new FileInputStream(inputFile);
OutputStream os = new FileOutputStream(outputFile);
Intent result = getOpenPgpApi().executeApi(params, is, os);
switch(result.getIntExtra(OpenPgpApi.RESULT_CODE, OpenPgpApi.RESULT_CODE_ERROR)) {
case OpenPgpApi.RESULT_CODE_SUCCESS:
URL url = message.getFileParams().url;
mXmppConnectionService.getFileBackend().updateFileParams(message, url);
message.setEncryption(Message.ENCRYPTION_DECRYPTED);
inputFile.delete();
mXmppConnectionService.getFileBackend().updateMediaScanner(outputFile);
mXmppConnectionService.updateMessage(message);
break;
case OpenPgpApi.RESULT_CODE_USER_INTERACTION_REQUIRED:
synchronized (PgpDecryptionService.this) {
PendingIntent pendingIntent = result.getParcelableExtra(OpenPgpApi.RESULT_INTENT);
messages.addFirst(message);
currentMessage = null;
storePendingIntent(pendingIntent);
}
break;
case OpenPgpApi.RESULT_CODE_ERROR:
message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
mXmppConnectionService.updateMessage(message);
break;
}
} catch (final IOException e) {
message.setEncryption(Message.ENCRYPTION_DECRYPTION_FAILED);
mXmppConnectionService.updateMessage(message);
}
}
}
notifyIfPending(message);
}
Aggregations