use of java.io.OutputStream in project ninja by ninjaframework.
the class TemplateEngineJsonP method invoke.
@Override
public void invoke(Context context, Result result) {
ResponseStreams responseStreams = context.finalizeHeaders(result);
String callback = getCallbackName(context);
try (OutputStream outputStream = responseStreams.getOutputStream()) {
objectMapper.writeValue(outputStream, new JSONPObject(callback, result.getRenderable()));
} catch (IOException e) {
logger.error("Error while rendering jsonp.", e);
}
}
use of java.io.OutputStream in project jodd by oblac.
the class DiskFileUpload method processStream.
@Override
protected void processStream() throws IOException {
file = new File(destFolder, header.getFileName());
OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
size = 0;
try {
if (maxFileSize == -1) {
size = input.copyAll(out);
} else {
// one more byte to detect larger files
size = input.copyMax(out, maxFileSize + 1);
if (size > maxFileSize) {
fileTooBig = true;
valid = false;
input.skipToBoundary();
return;
}
}
valid = true;
} finally {
StreamUtil.close(out);
}
}
use of java.io.OutputStream in project dex2jar by pxb1988.
the class Files method copy.
public static Path copy(Path source, Path target, CopyOption... options) throws IOException {
InputStream is = source._newInputStream();
OutputStream os = target._newOutputStream();
FileSystemProvider.copy(is, os);
is.close();
os.close();
return target;
}
use of java.io.OutputStream in project dex2jar by pxb1988.
the class AbstractJarSign method sign.
public void sign(File in, File out) throws IOException, GeneralSecurityException {
JarFile inputJar = null;
JarOutputStream outputJar = null;
FileOutputStream outputFile = null;
try {
// Assume the certificate is valid for at least an hour.
long timestamp = System.currentTimeMillis();
// Don't verify.
inputJar = new JarFile(in, false);
OutputStream outputStream = outputFile = new FileOutputStream(out);
outputJar = new JarOutputStream(outputStream);
outputJar.setLevel(9);
JarEntry je;
// MANIFEST.MF
Manifest manifest = addDigestsToManifest(inputJar);
je = new JarEntry(JarFile.MANIFEST_NAME);
je.setTime(timestamp);
outputJar.putNextEntry(je);
manifest.write(outputJar);
// CERT.SF
Signature signature = Signature.getInstance(signAlg);
signature.initSign(privateKey);
je = new JarEntry("META-INF/CERT.SF");
je.setTime(timestamp);
outputJar.putNextEntry(je);
writeSignatureFile(manifest, new SignatureOutputStream(outputJar, signature));
int i = digestAlg.toLowerCase().indexOf("with");
String ext;
if (i > 0) {
ext = digestAlg.substring(i + 4);
} else {
ext = "RSA";
}
// CERT.RSA
je = new JarEntry("META-INF/CERT." + ext);
je.setTime(timestamp);
outputJar.putNextEntry(je);
writeSignatureBlock(signature.sign(), outputJar);
// Everything else
copyFiles(manifest, inputJar, outputJar, timestamp);
outputJar.close();
outputJar = null;
outputStream.flush();
} finally {
try {
if (inputJar != null) {
inputJar.close();
}
if (outputFile != null) {
outputFile.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
use of java.io.OutputStream in project platform_frameworks_base by android.
the class NetworkStatsFactoryTest method stageFile.
/**
* Copy a {@link Resources#openRawResource(int)} into {@link File} for
* testing purposes.
*/
private void stageFile(int rawId, File file) throws Exception {
new File(file.getParent()).mkdirs();
InputStream in = null;
OutputStream out = null;
try {
in = getContext().getResources().openRawResource(rawId);
out = new FileOutputStream(file);
Streams.copy(in, out);
} finally {
IoUtils.closeQuietly(in);
IoUtils.closeQuietly(out);
}
}
Aggregations