/** * Closes the Atom content stream. */ private void closeAtomContentStream() { IOUtils.closeQuietly(atomContentStream); atomContentStream = null; }
/** * Closes the CMIS content stream. */ private void closeCmisContentStream() { IOUtils.closeQuietly(cmisContentStream); cmisContentStream = null; }
public static CmisEndpointsDocument read(File file) throws IOException, JSONParseException { if (file == null) { throw new IllegalArgumentException("File is null!"); } InputStream stream = new BufferedInputStream(new FileInputStream(file)); try { return read(stream); } finally { IOUtils.closeQuietly(stream); } }
public static CmisEndpointsDocument read(URL url) throws IOException, JSONParseException { if (url == null) { throw new IllegalArgumentException("URL is null!"); } InputStream stream = url.openStream(); try { return read(stream); } finally { IOUtils.closeQuietly(stream); } }
public static CmisEndpointsDocument read(File file) throws IOException, JSONParseException { if (file == null) { throw new IllegalArgumentException("File is null!"); } InputStream stream = new BufferedInputStream(new FileInputStream(file)); try { return read(stream); } finally { IOUtils.closeQuietly(stream); } }
public void loadParameters(File file) throws IOException { if (file == null || !file.isFile()) { throw new IllegalArgumentException("File not found!"); } InputStream stream = new FileInputStream(file); try { loadParameters(stream); } finally { IOUtils.closeQuietly(stream); } }
public void loadDefaultTckGroups() throws Exception { InputStream stream = this.getClass().getResourceAsStream(DEFAULT_TCK_GROUPS); if (stream != null) { try { loadGroups(stream); } finally { IOUtils.closeQuietly(stream); } } }
@Override public void createReport(Map<String, String> parameters, List<CmisTestGroup> groups, File file) throws Exception { Writer writer = new OutputStreamWriter(new FileOutputStream(file), IOUtils.UTF8); try { createReport(parameters, groups, writer); } finally { IOUtils.closeQuietly(writer); } } }
public void loadGroups(File file) throws Exception { if (file == null || !file.isFile()) { throw new IllegalArgumentException("File not found!"); } InputStream stream = new FileInputStream(file); try { loadGroups(stream); } finally { IOUtils.closeQuietly(stream); } }
private String loadTCKTimestamp() { InputStream stream = getClass().getResourceAsStream(TCK_BUILD_TIMESTAMP); if (stream != null) { try { return IOUtils.readAllLines(stream, 1000); } catch (IOException e) { return ""; } finally { IOUtils.closeQuietly(stream); } } return ""; }
/** * Closes the stream of a {@link ContentStream} object and ignores any * exceptions. * * @param contentStream * the content stream */ public static void closeQuietly(final ContentStream contentStream) { if (contentStream != null) { closeQuietly(contentStream.getStream()); } }
public static CmisEndpointsDocument read(URL url) throws IOException, JSONParseException { if (url == null) { throw new IllegalArgumentException("URL is null!"); } InputStream stream = url.openStream(); try { return read(stream); } finally { IOUtils.closeQuietly(stream); } }
/** * Closes the stream of a {@link ContentStream} object and ignores any * exceptions. * * @param contentStream * the content stream */ public static void closeQuietly(final ContentStream contentStream) { if (contentStream != null) { closeQuietly(contentStream.getStream()); } }
private String readFile(ServletConfig config, String path) throws ServletException { InputStream stream = config.getServletContext().getResourceAsStream(path); if (stream == null) { throw new ServletException("Cannot find file '" + path + "'!"); } try { return IOUtils.readAllLines(stream, 100000); } catch (IOException e) { throw new ServletException("Cannot read file '" + path + "': " + e.getMessage(), e); } finally { IOUtils.closeQuietly(stream); } }
private void writeTextToFile(String filename, String content) { PrintWriter pw = null; OutputStreamWriter fw = null; try { fw = new OutputStreamWriter(new FileOutputStream(filename), IOUtils.UTF8); pw = new PrintWriter(fw); Scanner scanner = new Scanner(content); while (scanner.hasNextLine()) { String line = scanner.nextLine(); pw.println(line); } scanner.close(); pw.flush(); } catch (IOException e) { LOG.error(e.getMessage(), e); } finally { IOUtils.closeQuietly(pw); IOUtils.closeQuietly(fw); } }
private void loadProperties() { // Returns null on lookup failures: InputStream in = Configurator.class.getResourceAsStream("/mapping.properties"); if (in != null) { properties = new Properties(); try { properties.load(in); } catch (IOException e) { LOG.error(e.toString(), e); e.printStackTrace(); throw new MapperException("Could not load file mapping.properties as resource", e); } finally { IOUtils.closeQuietly(in); } } }
private String loadTCKRevision() { InputStream stream = getClass().getResourceAsStream(TCK_REVISION); if (stream != null) { try { String revStr = IOUtils.readFirstLine(stream); return String.valueOf(Integer.parseInt(revStr.trim())); } catch (NumberFormatException e) { return null; } catch (IOException e) { return null; } finally { IOUtils.closeQuietly(stream); } } return null; }
@Override public ContentStream call() throws Exception { ContentStream contentStream = super.call(); try { if (contentStream != null && contentStream.getStream() != null && target != null) { IOUtils.copy(contentStream.getStream(), target); } } finally { IOUtils.closeQuietly(contentStream); } return contentStream; } }
@Override public ContentStream call() throws Exception { ContentStream contentStream = super.call(); try { if (contentStream != null && contentStream.getStream() != null && target != null) { IOUtils.copy(contentStream.getStream(), target); } } finally { IOUtils.closeQuietly(contentStream); } return contentStream; } }
private boolean readNext() throws IOException { try { readHeaders(); // no headers -> end of request if (headers == null) { skipEpilogue(); return false; } readBody(); return true; } catch (IOException e) { IOUtils.closeQuietly(contentStream); skipEpilogue(); throw e; } }