List of usage examples for org.apache.commons.io IOUtils closeQuietly
public static void closeQuietly(OutputStream output)
OutputStream
. From source file:com.datatorrent.stram.client.AppPackageTest.java
@BeforeClass public static void starting() { try {// w w w.j a va 2 s .c o m File file = StramTestSupport.createAppPackageFile(); // Set up test instance ap = new AppPackage(file, true); // set up another instance File testfolder = new File("target/testapp"); yap = new AppPackage(file, testfolder, false); jomp = new JSONSerializationProvider(); json = new JSONObject(jomp.getContext(null).writeValueAsString(ap)); } catch (ZipException e) { throw new RuntimeException(e); } catch (IOException e) { throw new RuntimeException(e); } catch (JSONException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(ap); IOUtils.closeQuietly(yap); } }
From source file:de.tudarmstadt.ukp.experiments.argumentation.comments.pipeline.ExtendedMalletTopicModelEstimator.java
/** * Loads serialized vocabulary ({@code HashMap<String, Integer>}) from file * * @return vocabulary entries (key set)//from w ww. j av a 2 s . c om * @throws IOException * @throws ClassNotFoundException */ @SuppressWarnings("unchecked") public static Set<String> readVocabulary(File vocabularyFile) throws IOException, ClassNotFoundException { ObjectInputStream ois = new ObjectInputStream(new FileInputStream(vocabularyFile)); Map<String, Integer> map = (Map<String, Integer>) ois.readObject(); IOUtils.closeQuietly(ois); return map.keySet(); }
From source file:gov.nih.nci.ncicb.tcga.dcc.qclive.bean.SDRF.java
public SDRF(String dirLocation, String headerListFileName, final ProcessLogger processLogger) { CSVReader reader = null;//from w ww .ja v a 2 s . c o m FileReader fileReader = null; try { //noinspection IOResourceOpenedButNotSafelyClosed fileReader = new FileReader(new File(dirLocation, headerListFileName)); reader = new CSVReader(fileReader, '\t'); SDRFList = reader.readAll(); } catch (IOException e) { processLogger.addError(); processLogger.logToLogger(Level.FATAL, "Could not find the SDRF File. Aborting Processing."); processLogger.getLogBuffer().append("Could not find the SDRF File. Aborting Processing."); } finally { IOUtils.closeQuietly(fileReader); IOUtils.closeQuietly(reader); } }
From source file:com.zte.gu.webtools.web.download.DownloadController.java
@RequestMapping(method = RequestMethod.GET) public void download(HttpSession session, HttpServletResponse response) { String filePath = (String) session.getAttribute("filePath"); String fileName = (String) session.getAttribute("fileName"); if (filePath != null) { response.reset();// w ww . j a va 2 s .co m response.setHeader("Content-Disposition", "attachment; filename=" + fileName); response.setContentType("application/octet-stream; charset=UTF-8"); InputStream in = null; try { in = new FileInputStream(filePath); IOUtils.copy(in, response.getOutputStream()); } catch (Exception e) { LoggerFactory.getLogger(DownloadController.class).warn("download error,", e); } finally { IOUtils.closeQuietly(in); session.removeAttribute("filePath"); session.removeAttribute("fileName"); } } }
From source file:io.mandrel.io.payload.ByteSourcePayload.java
/** * if we created the stream, then it is already consumed on close. */ @Override public void release() { IOUtils.closeQuietly(closer); }
From source file:net.padaf.preflight.font.type1.PeekInputStream.java
public PeekInputStream(InputStream source) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); try {/*from ww w. j a v a2s . co m*/ IOUtils.copyLarge(source, bos); content = bos.toByteArray(); } finally { IOUtils.closeQuietly(source); IOUtils.closeQuietly(bos); } }
From source file:com.izforge.izpack.util.LogUtils.java
public static void loadConfiguration(final String resource, Variables variables) throws IOException { if (OVERRIDE) { InputStream resourceStream = null; try {/*from w ww. j av a2s .c o m*/ resourceStream = LogUtils.class.getResourceAsStream(resource); loadLoggingResource(resourceStream, variables); } finally { IOUtils.closeQuietly(resourceStream); } } }
From source file:com.thoughtworks.go.server.web.XmlView.java
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response) throws Exception { Document document = (Document) model.get("document"); ServletOutputStream outputStream = response.getOutputStream(); try {/*from w w w. j a v a 2s.c o m*/ XmlUtils.writeXml(document, outputStream); } finally { IOUtils.closeQuietly(outputStream); } }
From source file:Client.ClientHandler.java
public void run() { try {//from w w w .ja va2 s. c om PrintWriter out = null; BufferedReader in = null; out = new PrintWriter(socket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader(socket.getInputStream())); out.println("Welcome to the capitalization server"); out.println("Your client Id is " + clientID); while (true) { String input = in.readLine(); if (input.equals("") || input.equals(".")) { break; } out.println(input.toUpperCase()); } } catch (IOException ex) { Logger.getLogger(ClientHandler.class.getName()).log(Level.SEVERE, null, ex); } finally { IOUtils.closeQuietly(socket); IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } }
From source file:com.pickr.utils.BitmapUtils.java
private static Bitmap loadBitmap(URL url) throws IOException { InputStream is = null;/*ww w . j av a 2 s .c o m*/ try { is = new BufferedInputStream(url.openStream(), 512000); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 1; return BitmapFactory.decodeStream(is, null, options); } finally { IOUtils.closeQuietly(is); } }