Example usage for java.io OutputStream close

List of usage examples for java.io OutputStream close

Introduction

In this page you can find the example usage for java.io OutputStream close.

Prototype

public void close() throws IOException 

Source Link

Document

Closes this output stream and releases any system resources associated with this stream.

Usage

From source file:com.intellectualcrafters.plot.uuid.UUIDFetcher.java

private static void writeBody(final HttpURLConnection connection, final String body) throws Exception {
    final OutputStream stream = connection.getOutputStream();
    stream.write(body.getBytes());/*from  w w w .  j a va2  s . c  om*/
    stream.flush();
    stream.close();
}

From source file:Main.java

public static boolean writeByte(@NonNull File file, @NonNull String content) {
    if (file.isDirectory()) {
        return false;
    }//w  ww.  jav  a  2s.co  m
    if (!file.exists()) {
        try {
            file.createNewFile();
        } catch (IOException e) {
        }
    }
    OutputStream out = null;
    try {
        out = new FileOutputStream(file);
        byte[] b = content.getBytes();
        out.write(b);
        out.close();
        return true;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    } catch (Exception e) {
        return false;
    } finally {
        CloseableClose(out);
    }
}

From source file:Main.java

public static void copyFileStream(InputStream input, OutputStream output) throws IOException {
    byte[] buffer = new byte[BUFFSIZE];
    int n = 0;/*w  ww  .  ja v a 2  s .  c  o m*/
    while (-1 != (n = input.read(buffer))) {
        output.write(buffer, 0, n);
    }
    input.close();
    output.close();
}

From source file:de.atomfrede.tools.evalutation.tools.plot.util.PlotUtil.java

/**
 * Saves the given chart as a pdf file with the given file name.
 * //from   w ww  . j av  a  2  s  .  c  o  m
 * @param file
 * @param chart
 * @param width
 * @param height
 * @param mapper
 * @throws IOException
 */
public static void saveChartAsPDF(File file, JFreeChart chart, int width, int height, FontMapper mapper)
        throws IOException {
    OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
    writeChartAsPDF(out, chart, width, height, mapper);
    out.close();
}

From source file:com.nextep.designer.beng.model.impl.FileUtils.java

public static void copyFile(File srcFile, File destFile) throws IOException {
    InputStream in = new FileInputStream(srcFile);
    OutputStream out = new FileOutputStream(destFile);
    long millis = System.currentTimeMillis();
    copyStreams(in, out);//from  w  w w. j ava2  s  . co m
    out.close();
    in.close();
    millis = System.currentTimeMillis() - millis;
    log.info("File " + srcFile + " copied in " + (millis / 1000L) + "s."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}

From source file:Main.java

static void copyFile(File src, File dst) throws IOException {
    InputStream in = new FileInputStream(src);
    OutputStream out = new FileOutputStream(dst);

    // Transfer bytes from in to out
    byte[] buf = new byte[1024];
    int len;//from w w  w  .ja  v a 2 s. co  m
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    in.close();
    out.close();
}

From source file:com.audiveris.installer.Expander.java

/**
 * Store the provided input stream to the desired file.
 *
 * @param in      the input stream. It is not closed by this method.
 * @param outFile the desired target file
 * @return the target file//from w ww  .j av a 2 s  .  com
 * @throws FileNotFoundException
 * @throws IOException
 */
public static File streamToFile(final InputStream in, final File outFile)
        throws FileNotFoundException, IOException {
    final OutputStream out = new FileOutputStream(outFile);
    IOUtils.copy(in, out);
    out.close();

    return outFile;
}

From source file:com.sharneng.io.IOUtils.java

/**
 * Quietly close a {@linkplain java.io.OutputStream} without throwing any exception. Exceptions will be logged as
 * error if the <code>logError</code> is <code>true</code>.
 * /* www .  j a  v  a  2 s  .c  o m*/
 * @param out
 *            the output stream to close
 * @param logError
 *            true to log exception as error
 * @see #close(OutputStream)
 * @see #close(InputStream, boolean)
 */
public static void close(OutputStream out, boolean logError) {
    if (out != null) {
        try {
            out.close();
        } catch (Throwable t) {
            if (logError)
                log.error(t.getMessage(), t);
            else
                log.debug(t.getMessage(), t);
        }
    }
}

From source file:Util.java

public static void copyInputstreamToFile(InputStream in, OutputStream out) {
    try {/*from  w w  w  .j a va 2 s .  co m*/
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        in.close();
        out.close();
    } catch (IOException ex) {

    }
}

From source file:Main.java

public static File getFileFromInputStream(File file, InputStream ins) throws IOException {
    OutputStream os = new FileOutputStream(file);
    int bytesRead = 0;
    byte[] buffer = new byte[8192];
    while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) {
        os.write(buffer, 0, bytesRead);//from w  w  w . j av  a  2 s .  co  m
    }
    os.close();
    ins.close();
    return file;
}