List of usage examples for org.apache.commons.io IOUtils closeQuietly
public static void closeQuietly(OutputStream output)
OutputStream
. From source file:com.alta189.deskbin.util.CryptUtils.java
private static boolean writeKey(SecretKey key) { FileOutputStream fos = null;/*w w w . java 2 s . co m*/ ObjectOutputStream out = null; try { if (keyFile.getParentFile() != null) { keyFile.getParentFile().mkdirs(); } fos = new FileOutputStream(keyFile); out = new ObjectOutputStream(fos); out.writeObject(key); out.flush(); return true; } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(fos); IOUtils.closeQuietly(out); } return false; }
From source file:io.cloudslang.orchestrator.services.ExecutionSerializationUtil.java
public Execution objFromBytes(byte[] bytes) { ObjectInputStream ois = null; try {/*w ww.j ava 2 s. c om*/ //2 Buffers are added to increase performance ByteArrayInputStream is = new ByteArrayInputStream(bytes); BufferedInputStream bis = new BufferedInputStream(is); ois = new ObjectInputStream(bis); //noinspection unchecked return (Execution) ois.readObject(); } catch (IOException | ClassNotFoundException ex) { throw new RuntimeException("Failed to read execution from byte[]. Error: ", ex); } finally { IOUtils.closeQuietly(ois); } }
From source file:com.redhat.red.offliner.PomArtifactListReaderTest.java
@BeforeClass public static void prepare() throws IOException { File tempDir = new File(TEMP_POM_DIR); if (tempDir.exists()) { FileUtils.deleteDirectory(tempDir); }/*from w w w . j av a 2 s .c o m*/ tempDir.mkdirs(); List<String> resources = new ArrayList<String>(2); resources.add("repo.pom"); resources.add("settings.xml"); for (String resource : resources) { InputStream is = PomArtifactListReaderTest.class.getClassLoader().getResourceAsStream(resource); File target = new File(TEMP_POM_DIR, resource); OutputStream os = new FileOutputStream(target); try { IOUtils.copy(is, os); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(os); } } }
From source file:com.discursive.jccook.io.SplitOutExample.java
public void start() { File test1 = new File("split1.txt"); File test2 = new File("split2.txt"); OutputStream outStream = null; try {//from w ww . j a va 2 s . c om FileOutputStream fos1 = new FileOutputStream(test1); FileOutputStream fos2 = new FileOutputStream(test2); outStream = new TeeOutputStream(fos1, fos2); outStream.write("One Two Three, Test".getBytes()); } catch (IOException ioe) { System.out.println("Error writing to split output stream"); } finally { IOUtils.closeQuietly(outStream); } }
From source file:com.oprisnik.semdroid.utils.FileUtils.java
public static void writeObjectToFile(Object object, File file) throws IOException { if (!file.exists()) { file.getParentFile().mkdirs();//from www.ja va 2 s . c o m } ObjectOutputStream out = null; try { out = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(file))); out.writeObject(object); out.flush(); } finally { IOUtils.closeQuietly(out); } }
From source file:com.oprisnik.semdroid.permissions.AndroidPermissionMapFactory.java
public AndroidPermissionMapFactory(Context context) { mPermissionMap = new PermissionMap(); InputStream is = null;/* w ww .j a v a 2 s. co m*/ try { is = context.getAssets() .open("config" + File.separator + "permissionmap" + File.separator + "APICalls.txt"); mPermissionMap.createMap(new BufferedReader(new InputStreamReader(is))); } catch (Exception e) { Log.e(TAG, e.getMessage()); } finally { IOUtils.closeQuietly(is); } }
From source file:ch.cyberduck.core.cryptomator.ContentReader.java
public String read(final Path file) throws BackgroundException { final Read read = session._getFeature(Read.class); final InputStream in = read.read(file, new TransferStatus(), new DisabledConnectionCallback()); try {//w w w . ja va 2 s.c o m return IOUtils.toString(in, "UTF-8"); } catch (IOException e) { throw new DefaultIOExceptionMappingService().map(e); } finally { IOUtils.closeQuietly(in); } }
From source file:com.netflix.curator.framework.imps.TestTempFramework.java
@Test public void testBasic() throws Exception { CuratorTempFramework client = CuratorFrameworkFactory.builder().connectString(server.getConnectString()) .retryPolicy(new RetryOneTime(1)).buildTemp(); try {//from w w w. java2 s .c o m client.inTransaction().create().forPath("/foo", "data".getBytes()).and().commit(); byte[] bytes = client.getData().forPath("/foo"); Assert.assertEquals(bytes, "data".getBytes()); } finally { IOUtils.closeQuietly(client); } }
From source file:com.wenzani.maven.mongodb.TarUtils.java
public String untargz(File archive, File outputDir) { String absolutePath = archive.getAbsolutePath(); String root = null;//from w w w.j a v a 2 s . co m boolean first = true; while (absolutePath.contains("tar") || absolutePath.contains("gz") || absolutePath.contains("tgz")) { absolutePath = absolutePath.substring(0, absolutePath.lastIndexOf(".")); } absolutePath = absolutePath + ".tar"; try { GZIPInputStream input = new GZIPInputStream(new FileInputStream(archive)); FileOutputStream fos = new FileOutputStream(new File(absolutePath)); IOUtils.copy(input, fos); IOUtils.closeQuietly(input); IOUtils.closeQuietly(fos); TarArchiveInputStream tarArchiveInputStream = new TarArchiveInputStream( new FileInputStream(absolutePath)); for (TarArchiveEntry entry = tarArchiveInputStream.getNextTarEntry(); entry != null;) { unpackEntries(tarArchiveInputStream, entry, outputDir); if (first && entry.isDirectory()) { root = outputDir + File.separator + entry.getName(); } entry = tarArchiveInputStream.getNextTarEntry(); } } catch (Exception e) { e.printStackTrace(); } return root; }
From source file:latexstudio.editor.runtime.CommandLineExecutor.java
public static synchronized void executeGeneratePDF(CommandLineBuilder cmd) { String outputDirectory = "--output-directory=" + cmd.getOutputDirectory(); String outputFormat = "--output-format=pdf"; String job = cmd.getJobname() == null ? "" : "--jobname=" + cmd.getJobname().replaceAll(" ", "_"); ByteArrayOutputStream outputStream = null; try {//from w ww . j av a2 s .c o m String[] command = new String[] { outputDirectory, outputFormat, job, cmd.getPathToSource() }; CommandLine cmdLine = new CommandLine(ApplicationUtils.getPathToTEX(cmd.getLatexPath())); //For windows, we set handling quoting to true cmdLine.addArguments(command, ApplicationUtils.isWindows()); outputStream = new ByteArrayOutputStream(); PumpStreamHandler streamHandler = new PumpStreamHandler(outputStream); EXECUTOR.setStreamHandler(streamHandler); if (cmd.getWorkingFile() != null) { EXECUTOR.setWorkingDirectory(cmd.getWorkingFile().getParentFile().getAbsoluteFile()); } EXECUTOR.execute(cmdLine); if (cmd.getLogger() != null) { cmd.getLogger().log(cmdLine.toString()); cmd.getLogger().log(outputStream.toString()); } } catch (IOException e) { if (cmd.getLogger() != null) { cmd.getLogger().log("The path to the pdflatex tool is incorrect or has not been set."); } } finally { IOUtils.closeQuietly(outputStream); } }