Search in sources :

Example 41 with FileOutputStream

use of java.io.FileOutputStream in project tomcat by apache.

the class ManagerServlet method uploadWar.

/**
     * Upload the WAR file included in this request, and store it at the
     * specified file location.
     *
     * @param writer    Writer to render to
     * @param request   The servlet request we are processing
     * @param war       The file into which we should store the uploaded WAR
     * @param smClient  The StringManager used to construct i18n messages based
     *                  on the Locale of the client
     *
     * @exception IOException if an I/O error occurs during processing
     */
protected void uploadWar(PrintWriter writer, HttpServletRequest request, File war, StringManager smClient) throws IOException {
    if (war.exists() && !war.delete()) {
        String msg = smClient.getString("managerServlet.deleteFail", war);
        throw new IOException(msg);
    }
    try (ServletInputStream istream = request.getInputStream();
        BufferedOutputStream ostream = new BufferedOutputStream(new FileOutputStream(war), 1024)) {
        byte[] buffer = new byte[1024];
        while (true) {
            int n = istream.read(buffer);
            if (n < 0) {
                break;
            }
            ostream.write(buffer, 0, n);
        }
    } catch (IOException e) {
        if (war.exists() && !war.delete()) {
            writer.println(smClient.getString("managerServlet.deleteFail", war));
        }
        throw e;
    }
}
Also used : ServletInputStream(javax.servlet.ServletInputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 42 with FileOutputStream

use of java.io.FileOutputStream in project zeppelin by apache.

the class ScreenCaptureHtmlUnitDriver method getScreenshotAs.

@Override
@SuppressWarnings("unchecked")
public <X> X getScreenshotAs(OutputType<X> target) throws WebDriverException {
    byte[] archive = new byte[0];
    try {
        archive = downloadCssAndImages(getWebClient(), (HtmlPage) getCurrentWindow().getEnclosedPage());
    } catch (Exception e) {
        LOGGER.error("Exception in ScreenCaptureHtmlUnitDriver while getScreenshotAs ", e);
    }
    if (target.equals(OutputType.BASE64)) {
        return target.convertFromBase64Png(new Base64Encoder().encode(archive));
    }
    if (target.equals(OutputType.FILE)) {
        File f = new File("screen.tmp");
        try {
            FileOutputStream scr = new FileOutputStream(f);
            scr.write(archive);
            scr.close();
        } catch (IOException e) {
            throw new WebDriverException(e);
        }
        return (X) f;
    }
    return (X) archive;
}
Also used : HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) WebDriverException(org.openqa.selenium.WebDriverException) IOException(java.io.IOException) Base64Encoder(org.openqa.selenium.internal.Base64Encoder) WebDriverException(org.openqa.selenium.WebDriverException)

Example 43 with FileOutputStream

use of java.io.FileOutputStream in project zookeeper by apache.

the class FileSnap method serialize.

/**
     * serialize the datatree and session into the file snapshot
     * @param dt the datatree to be serialized
     * @param sessions the sessions to be serialized
     * @param snapShot the file to store snapshot into
     */
public synchronized void serialize(DataTree dt, Map<Long, Integer> sessions, File snapShot) throws IOException {
    if (!close) {
        OutputStream sessOS = new BufferedOutputStream(new FileOutputStream(snapShot));
        CheckedOutputStream crcOut = new CheckedOutputStream(sessOS, new Adler32());
        //CheckedOutputStream cout = new CheckedOutputStream()
        OutputArchive oa = BinaryOutputArchive.getArchive(crcOut);
        FileHeader header = new FileHeader(SNAP_MAGIC, VERSION, dbId);
        serialize(dt, sessions, oa, header);
        long val = crcOut.getChecksum().getValue();
        oa.writeLong(val, "val");
        oa.writeString("/", "path");
        sessOS.flush();
        crcOut.close();
        sessOS.close();
    }
}
Also used : BinaryOutputArchive(org.apache.jute.BinaryOutputArchive) OutputArchive(org.apache.jute.OutputArchive) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) CheckedOutputStream(java.util.zip.CheckedOutputStream) FileOutputStream(java.io.FileOutputStream) CheckedOutputStream(java.util.zip.CheckedOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) Adler32(java.util.zip.Adler32)

Example 44 with FileOutputStream

use of java.io.FileOutputStream in project cw-omnibus by commonsguy.

the class AbstractFileProvider method copy.

static void copy(InputStream in, File dst) throws IOException {
    FileOutputStream out = new FileOutputStream(dst);
    byte[] buf = new byte[1024];
    int len;
    while ((len = in.read(buf)) >= 0) {
        out.write(buf, 0, len);
    }
    in.close();
    out.close();
}
Also used : FileOutputStream(java.io.FileOutputStream)

Example 45 with FileOutputStream

use of java.io.FileOutputStream in project cw-omnibus by commonsguy.

the class FilesCPDemo method copy.

private static void copy(InputStream in, File dst) throws IOException {
    FileOutputStream out = new FileOutputStream(dst);
    byte[] buf = new byte[1024];
    int len;
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    in.close();
    out.close();
}
Also used : FileOutputStream(java.io.FileOutputStream)

Aggregations

FileOutputStream (java.io.FileOutputStream)13792 File (java.io.File)8295 IOException (java.io.IOException)6166 FileInputStream (java.io.FileInputStream)2644 OutputStream (java.io.OutputStream)2605 InputStream (java.io.InputStream)2077 BufferedOutputStream (java.io.BufferedOutputStream)1755 FileNotFoundException (java.io.FileNotFoundException)1531 OutputStreamWriter (java.io.OutputStreamWriter)1440 Test (org.junit.Test)1115 ZipEntry (java.util.zip.ZipEntry)734 BufferedWriter (java.io.BufferedWriter)668 ArrayList (java.util.ArrayList)654 ZipOutputStream (java.util.zip.ZipOutputStream)642 BufferedInputStream (java.io.BufferedInputStream)604 ByteArrayOutputStream (java.io.ByteArrayOutputStream)556 PrintWriter (java.io.PrintWriter)530 Properties (java.util.Properties)497 URL (java.net.URL)478 Writer (java.io.Writer)477