List of usage examples for java.io OutputStream close
public void close() throws IOException
From source file:de.tudarmstadt.ukp.dkpro.core.api.resources.CompressionUtilsTest.java
private static void testCompression(CompressionMethod compressionMethod) throws IOException { String text = StringUtils.repeat("This is a test. ", 100000); File file = new File("compressed" + compressionMethod.getExtension()); OutputStream os = CompressionUtils.getOutputStream(file); os.write(text.getBytes());/*w w w . ja v a2 s . com*/ os.close(); InputStream is = CompressionUtils.getInputStream(file.getPath(), new FileInputStream(file)); assertEquals(text, IOUtils.toString(is)); is.close(); file.delete(); }
From source file:Main.java
public static boolean fileCopy(File srcFile, File objFile) { if (srcFile == null || objFile == null) { return false; }//from ww w . jav a 2 s . c om boolean result; try { InputStream iStream = new FileInputStream(srcFile); OutputStream oStream = new FileOutputStream(objFile); streamCopy(iStream, oStream); iStream.close(); oStream.close(); result = true; } catch (IOException e) { e.printStackTrace(); result = false; } return result; }
From source file:Main.java
public static void write(InputStream in, OutputStream out) throws IOException { int read = 0; while ((read = in.read()) != -1) { out.write(read);//from www . j av a 2s .com } in.close(); out.close(); out.flush(); }
From source file:com.sosee.util.PropertyUtil.java
public static void writePropertiesFile(String key, String value) { Properties properties = new Properties(); try {//from w ww .j a va2 s. co m OutputStream outputStream = new FileOutputStream(getFilePath()); properties.setProperty(key, value); properties.store(outputStream, "user register"); outputStream.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.netflix.spinnaker.clouddriver.appengine.artifacts.StorageUtils.java
public static void writeStreamToFile(InputStream sourceStream, File target) throws IOException { File parent = target.getParentFile(); if (!parent.exists()) { parent.mkdirs();/*from www .j av a 2 s . co m*/ } OutputStream targetStream = new FileOutputStream(target); IOUtils.copy(sourceStream, targetStream); targetStream.close(); }
From source file:Main.java
static void copy(File src, File dst) throws IOException { InputStream in = new FileInputStream(src); OutputStream out = new FileOutputStream(dst); byte[] buf = new byte[1024]; int len;//from ww w . j ava2 s . c o m while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); }
From source file:ca.xecure.easychip.CommonUtilities.java
public static void http_post(String endpoint, Map<String, String> params) throws IOException { URL url;//from w w w . j a va 2 s. c o m try { url = new URL(endpoint); } catch (MalformedURLException e) { throw new IllegalArgumentException("invalid url: " + endpoint); } String body = JSONValue.toJSONString(params); Log.v(LOG_TAG, "Posting '" + body + "' to " + url); byte[] bytes = body.getBytes(); HttpURLConnection conn = null; try { conn = (HttpURLConnection) url.openConnection(); conn.setDoOutput(true); conn.setUseCaches(false); conn.setFixedLengthStreamingMode(bytes.length); conn.setRequestMethod("POST"); conn.setRequestProperty("Content-Type", "application/json"); OutputStream out = conn.getOutputStream(); out.write(bytes); out.close(); int status = conn.getResponseCode(); if (status != 200) { throw new IOException("Post failed with error code " + status); } } finally { if (conn != null) { conn.disconnect(); } } }
From source file:com.thenairn.linker.config.Libraries.java
/** * Puts library to temp dir and loads to memory *///from w ww. j av a2 s. c om private static void loadLib(String path, String name) { name = name + ".dll"; try { // have to use a stream InputStream in = Libraries.class.getResourceAsStream(LIB_BIN + name); // always write to different location File fileOut = new File(System.getProperty("java.io.tmpdir") + "/" + path + LIB_BIN + name); logger.info("Writing dll to: " + fileOut.getAbsolutePath()); OutputStream out = FileUtils.openOutputStream(fileOut); IOUtils.copy(in, out); in.close(); out.close(); System.load(fileOut.toString()); } catch (Exception e) { e.printStackTrace(); } }
From source file:Main.java
/** * Copy the entire content of an InputStream into an OutputStream and close * both streams./*from www .j a va2 s . c o m*/ * * @param in * The InputStream to read data from * @param out * The OutputStream to write data to * * @throws IOException * I/O exception from read or write */ public static void copyWholeStreamAndClose(InputStream in, OutputStream out) throws IOException { try { copyWholeStreamAndCloseInput(in, out); } finally { out.close(); } }
From source file:brut.util.Jar.java
public static File extractToTmp(String resourcePath, String tmpPrefix) throws BrutException { try {/*from w w w . j ava 2 s . c o m*/ InputStream in = Class.class.getResourceAsStream(resourcePath); if (in == null) { throw new FileNotFoundException(resourcePath); } File fileOut = File.createTempFile(tmpPrefix, null); fileOut.deleteOnExit(); OutputStream out = new FileOutputStream(fileOut); IOUtils.copy(in, out); in.close(); out.close(); return fileOut; } catch (IOException ex) { throw new BrutException("Could not extract resource: " + resourcePath, ex); } }