Search in sources :

Example 81 with OutputStream

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);
    }
}
Also used : ResponseStreams(ninja.utils.ResponseStreams) OutputStream(java.io.OutputStream) JSONPObject(com.fasterxml.jackson.databind.util.JSONPObject) IOException(java.io.IOException)

Example 82 with OutputStream

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);
    }
}
Also used : OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Example 83 with OutputStream

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;
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream)

Example 84 with OutputStream

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();
        }
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) JarOutputStream(java.util.jar.JarOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FilterOutputStream(java.io.FilterOutputStream) DigestOutputStream(java.security.DigestOutputStream) Signature(java.security.Signature) JarOutputStream(java.util.jar.JarOutputStream) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) Manifest(java.util.jar.Manifest)

Example 85 with OutputStream

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);
    }
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

OutputStream (java.io.OutputStream)4178 IOException (java.io.IOException)1673 FileOutputStream (java.io.FileOutputStream)1331 InputStream (java.io.InputStream)1304 File (java.io.File)925 ByteArrayOutputStream (java.io.ByteArrayOutputStream)830 Test (org.junit.Test)735 BufferedOutputStream (java.io.BufferedOutputStream)477 FileInputStream (java.io.FileInputStream)431 Socket (java.net.Socket)375 ByteArrayInputStream (java.io.ByteArrayInputStream)233 URL (java.net.URL)231 OutputStreamWriter (java.io.OutputStreamWriter)230 HttpURLConnection (java.net.HttpURLConnection)189 BufferedInputStream (java.io.BufferedInputStream)178 InputStreamReader (java.io.InputStreamReader)176 BufferedReader (java.io.BufferedReader)159 FileNotFoundException (java.io.FileNotFoundException)158 GZIPOutputStream (java.util.zip.GZIPOutputStream)157 Path (java.nio.file.Path)155