/** * Closes the Atom content stream. */ private void closeAtomContentStream() { IOUtils.closeQuietly(atomContentStream); atomContentStream = null; }
private void writeLine(OutputStream out, String s) throws IOException { out.write(IOUtils.toUTF8Bytes(s == null ? CRLF : s + CRLF)); } }
@Override public void write(OutputStream out) throws IOException { IOUtils.copy(stream, out); } });
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 ""; }
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; } }
bytes = IOUtils.toUTF8Bytes(s); IOUtils.closeQuietly(baos); IOUtils.closeQuietly(gzis); IOUtils.closeQuietly(bais);
/** * Parses an input stream. */ protected Object parse(InputStream stream, String charset, ContainerFactory containerFactory) { InputStreamReader reader = null; Object obj = null; try { reader = new InputStreamReader(stream, charset); JSONParser parser = new JSONParser(); obj = parser.parse(reader, containerFactory); } catch (JSONParseException e) { throw new CmisConnectionException("Parsing exception: " + e.getMessage(), e); } catch (Exception e) { throw new CmisConnectionException("Parsing exception!", e); } finally { IOUtils.consumeAndClose(reader); if (reader == null) { IOUtils.closeQuietly(stream); } } return obj; }
byte[] amp = IOUtils.toUTF8Bytes("&"); out.write(IOUtils.toUTF8Bytes(param.getKey() + "=" + URLEncoder.encode(param.getValue(), IOUtils.UTF8))); writeLine(out); IOUtils.copy(stream, out, BUFFER_SIZE);
IOUtils.closeQuietly(oos); IOUtils.closeQuietly(gzos); IOUtils.closeQuietly(b64os); IOUtils.closeQuietly(baos); return IOUtils.toUTF8String(baos.toByteArray());
IOUtils.closeQuietly(errorStream); IOUtils.closeQuietly(responseStream); stream = new BufferedInputStream(stream, 64 * 1024); try { hasResponseStream = IOUtils.checkForBytes(stream); } catch (IOException ioe) { throw new CmisConnectionException("IO exception!", ioe); errorContent = e.getMessage(); stream = null; IOUtils.closeQuietly(responseStream);
public void writeServiceLink(String href, String repositoryId) throws XMLStreamException { writeLink(Constants.REL_SERVICE, href + "?repositoryId=" + IOUtils.encodeURL(repositoryId), Constants.MEDIATYPE_SERVICE, null); }
/** * Performs a POST on an URL, checks the response code and consumes the * response. */ protected void postAndConsume(UrlBuilder url, String contentType, Output writer) { Response resp = post(url, contentType, writer); IOUtils.consumeAndClose(resp.getStream()); }
/** * Checks if a stream has more bytes. If the provided stream is not * markable, it wrappes a {@link BufferedInputStream} around the stream and * returns it. * * @param stream * the stream * @param bufferSize * the size of the buffer in bytes if a * {@link BufferedInputStream} has to be created * @return {@code null} if the stream doesn't have more bytes, the provided * stream if the provided stream is markable and has more bytes, or * a {@link BufferedInputStream} if the provided stream is not * markable and has more bytes * * @throws IOException */ public static InputStream checkForBytes(InputStream stream, int bufferSize) throws IOException { if (stream == null) { return null; } InputStream checkStream = stream; if (!stream.markSupported()) { checkStream = new BufferedInputStream(stream, bufferSize); } if (checkForBytes(checkStream)) { return checkStream; } return null; }
/** * Reads all lines from a stream and closes the stream. * * @param stream * the input stream */ public static String readAllLines(InputStream stream) throws IOException { return readAllLines(stream, Integer.MAX_VALUE); }
/** * Reads all lines from a stream, ignores all comments, and closes the * stream. * * @param stream * the input stream */ public static List<String> readAllLinesAsList(InputStream stream) throws IOException { return readAllLinesAsList(stream, Integer.MAX_VALUE); }
/** * Reads all lines from a stream, ignores all comments, and closes the * stream. * * @param stream * the input stream */ public static Map<String, String> readAllLinesAsMap(InputStream stream) throws IOException { return readAllLinesAsMap(stream, Integer.MAX_VALUE); }
public String getPayload() { return IOUtils.toUTF8String(baous.toByteArray()); }
@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; } }
bytes = IOUtils.toUTF8Bytes(s); IOUtils.closeQuietly(baos); IOUtils.closeQuietly(gzis); IOUtils.closeQuietly(bais);