List of usage examples for java.io OutputStream close
public void close() throws IOException
From source file:com.arthurpitman.common.HttpUtils.java
/** * Connects to an HTTP resource using the post method. * @param url the URL to connect to./* www . j a va2 s . c om*/ * @param requestProperties optional request properties, <code>null</code> if not required. * @param postData the data to post. * @return the resulting {@link HttpURLConnection}. * @throws IOException */ public static HttpURLConnection connectPost(final String url, final RequestProperty[] requestProperties, final byte[] postData) throws IOException { // setup connection HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); connection.setDoOutput(true); connection.setUseCaches(false); connection.setRequestMethod(POST_METHOD); // send the post form connection.setFixedLengthStreamingMode(postData.length); addRequestProperties(connection, requestProperties); OutputStream outStream = connection.getOutputStream(); outStream.write(postData); outStream.close(); return connection; }
From source file:Main.java
public static void copy(InputStream in, File dst) throws IOException { OutputStream out = new FileOutputStream(dst); // Transfer bytes from in to out byte[] buf = buffers.get(); int len;//from ww w . j a v a 2 s . com while ((len = in.read(buf)) > 0) { Thread.yield(); out.write(buf, 0, len); } out.close(); }
From source file:net.sourceforge.jencrypt.lib.Utils.java
public static void closeQuietly(OutputStream output) { try {/*from w w w . java 2 s.c o m*/ if (output != null) { output.close(); } } catch (IOException ioe) { // ignore } }
From source file:io.undertow.server.handlers.PreChunkedResponseTransferCodingTestCase.java
@BeforeClass public static void setup() { final BlockingHandler blockingHandler = new BlockingHandler(); DefaultServer.setRootHandler(blockingHandler); blockingHandler.setRootHandler(new HttpHandler() { @Override/*from w w w.j a va2 s.c om*/ public void handleRequest(final HttpServerExchange exchange) { try { if (connection == null) { connection = exchange.getConnection(); } else if (!DefaultServer.isAjp() && !DefaultServer.isProxy() && connection != exchange.getConnection()) { final OutputStream outputStream = exchange.getOutputStream(); outputStream.write("Connection not persistent".getBytes()); outputStream.close(); return; } exchange.getResponseHeaders().put(Headers.TRANSFER_ENCODING, Headers.CHUNKED.toString()); exchange.putAttachment(HttpAttachments.PRE_CHUNKED_RESPONSE, true); new StringWriteChannelListener(chunkedMessage).setup(exchange.getResponseChannel()); } catch (IOException e) { throw new RuntimeException(e); } } }); }
From source file:Main.java
/** * From http://stackoverflow.com/questions/9292954/how-to-make-a-copy-of-a-file-in-android *//*from w w w . jav a 2 s . c o m*/ public static void copy(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; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); }
From source file:cn.mdict.utils.IOUtil.java
public static void forceClose(OutputStream os) { try {/* w w w.jav a 2 s .c o m*/ os.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:de.tudarmstadt.ukp.dkpro.tc.core.util.SaveModelUtils.java
public static void writeFeatureClassFiles(File modelFolder, List<String> featureSet) throws Exception { for (String featureString : featureSet) { Class<?> feature = Class.forName(featureString); InputStream inStream = feature.getResource("/" + featureString.replace(".", "/") + ".class") .openStream();//from w w w . ja v a2 s .c om OutputStream outStream = buildOutputStream(modelFolder, featureString); IOUtils.copy(inStream, outStream); outStream.close(); inStream.close(); } }
From source file:Main.java
/** * Copies a file from res/raw to destination (typically context.getFilesDir()) *///from www . j a v a 2 s. co m public static void copyInputFileStreamToFilesystem(InputStream in, String outputFilePathName) throws IOException { Log.i(TAG, "copyInputFileStreamToFilesystem() outputFilePathName: " + outputFilePathName); OutputStream out = new BufferedOutputStream(new FileOutputStream(outputFilePathName)); byte[] buffer = new byte[4096]; int len = in.read(buffer); while (len != -1) { out.write(buffer, 0, len); len = in.read(buffer); } out.close(); }
From source file:com.janoz.usenet.support.LogUtil.java
private static void copyStream(InputStream in, OutputStream out) throws IOException { byte[] buffer = new byte[BUFF_SIZE]; int len;//from www .j a v a 2 s . co m while ((len = in.read(buffer)) >= 0) { out.write(buffer, 0, len); } in.close(); out.close(); }
From source file:Main.java
/** * Converts a DOM Tree to a String./*www . java 2 s . c o m*/ * * @param xml The DOM document to convert. * @param file The file to save to. * * @return true if there were no errors saving to disk. */ public static boolean xmlToFile(Document xml, File file) { try { TransformerFactory f = TransformerFactory.newInstance(); OutputStream writer = new FileOutputStream(file); Transformer t = f.newTransformer(); DOMSource src = new DOMSource(xml); StreamResult result = new StreamResult(writer); t.transform(src, result); writer.close(); return true; } catch (Exception e) { return false; } }