/** * Reader characters from an input stream and write then to an output stream. * * @param in the reader to read from. * @param out the writer to write to. * @throws IOException if there is an error reading or writing characters. */ public static void writeTo(Reader in, Writer out) throws IOException { ReaderWriter.writeTo(in, out); }
/** * Reader characters from an input stream and write then to an output stream. * * @param in the reader to read from. * @param out the writer to write to. * @throws IOException if there is an error reading or writing characters. */ public static void writeTo(Reader in, Writer out) throws IOException { ReaderWriter.writeTo(in, out); }
/** * Reader bytes from an input stream and write then to an output stream. * * @param in the input stream to read from. * @param out the output stream to write to. * @throws IOException if there is an error reading or writing bytes. */ public static void writeTo(InputStream in, OutputStream out) throws IOException { ReaderWriter.writeTo(in, out); }
/** * Reader bytes from an input stream and write then to an output stream. * * @param in the input stream to read from. * @param out the output stream to write to. * @throws IOException if there is an error reading or writing bytes. */ public static void writeTo(InputStream in, OutputStream out) throws IOException { ReaderWriter.writeTo(in, out); }
response.setStatus(HttpStatus.OK_200); response.setContentType(mediaType); ReaderWriter.writeTo(fileStream, response.getOutputStream());
public ByteArrayDataSource(final InputStream is, final String type) throws IOException { final DSByteArrayOutputStream os = new DSByteArrayOutputStream(); ReaderWriter.writeTo(is, os); this.data = os.getBuf(); this.len = os.getCount(); /* * ByteArrayOutputStream doubles the size of the buffer every time * it needs to expand, which can waste a lot of memory in the worst * case with large buffers. Check how much is wasted here and if * it's too much, copy the data into a new buffer and allow the * old buffer to be garbage collected. */ if (this.data.length - this.len > 256 * 1024) { this.data = os.toByteArray(); this.len = this.data.length; // should be the same } this.type = type; }
public ByteArrayDataSource(final InputStream is, final String type) throws IOException { final DSByteArrayOutputStream os = new DSByteArrayOutputStream(); ReaderWriter.writeTo(is, os); this.data = os.getBuf(); this.len = os.getCount(); /* * ByteArrayOutputStream doubles the size of the buffer every time * it needs to expand, which can waste a lot of memory in the worst * case with large buffers. Check how much is wasted here and if * it's too much, copy the data into a new buffer and allow the * old buffer to be garbage collected. */ if (this.data.length - this.len > 256 * 1024) { this.data = os.toByteArray(); this.len = this.data.length; // should be the same } this.type = type; }
/** * Buffer the entity stream (if not empty). * * @return {@code true} if the entity input stream was successfully buffered. * @throws javax.ws.rs.ProcessingException in case of an IO error. */ public boolean bufferEntity() throws ProcessingException { entityContent.ensureNotClosed(); try { if (entityContent.isBuffered() || !entityContent.hasContent()) { return true; } final InputStream entityStream = entityContent.getWrappedStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ReaderWriter.writeTo(entityStream, baos); } finally { // Workaround for JRFCAF-1344: the underlying stream close() implementation may be thread-unsafe // and as such the close() may result in an IOException at the socket input stream level, // if the close() gets called at once from multiple threads somehow. // We want to ignore these exceptions in the readEntity/bufferEntity operations though. ReaderWriter.safelyClose(entityStream); } entityContent.setContent(new ByteArrayInputStream(baos.toByteArray()), true); return true; } catch (IOException ex) { throw new ProcessingException(LocalizationMessages.MESSAGE_CONTENT_BUFFERING_FAILED(), ex); } }
/** * Buffer the entity stream (if not empty). * * @return {@code true} if the entity input stream was successfully buffered. * @throws javax.ws.rs.ProcessingException in case of an IO error. */ public boolean bufferEntity() throws ProcessingException { entityContent.ensureNotClosed(); try { if (entityContent.isBuffered() || !entityContent.hasContent()) { return true; } final InputStream entityStream = entityContent.getWrappedStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); try { ReaderWriter.writeTo(entityStream, baos); } finally { // Workaround for JRFCAF-1344: the underlying stream close() implementation may be thread-unsafe // and as such the close() may result in an IOException at the socket input stream level, // if the close() gets called at once from multiple threads somehow. // We want to ignore these exceptions in the readEntity/bufferEntity operations though. ReaderWriter.safelyClose(entityStream); } entityContent.setContent(new ByteArrayInputStream(baos.toByteArray()), true); return true; } catch (IOException ex) { throw new ProcessingException(LocalizationMessages.MESSAGE_CONTENT_BUFFERING_FAILED(), ex); } }
/** * Reader bytes from an input stream and write then to an output stream. * * @param in the input stream to read from. * @param out the output stream to write to. * @throws IOException if there is an error reading or writing bytes. */ public static void writeTo(InputStream in, OutputStream out) throws IOException { ReaderWriter.writeTo(in, out); }
/** * Reader characters from an input stream and write then to an output stream. * * @param in the reader to read from. * @param out the writer to write to. * @throws IOException if there is an error reading or writing characters. */ public static void writeTo(Reader in, Writer out) throws IOException { ReaderWriter.writeTo(in, out); }
/** * Reader bytes from an input stream and write then to an output stream. * * @param in the input stream to read from. * @param out the output stream to write to. * @throws IOException if there is an error reading or writing bytes. */ public static void writeTo(InputStream in, OutputStream out) throws IOException { ReaderWriter.writeTo(in, out); }
/** * Reader characters from an input stream and write then to an output stream. * * @param in the reader to read from. * @param out the writer to write to. * @throws IOException if there is an error reading or writing characters. */ public static void writeTo(Reader in, Writer out) throws IOException { ReaderWriter.writeTo(in, out); }
/** * Reader bytes from an input stream and write then to an output stream. * * @param in the input stream to read from. * @param out the output stream to write to. * @throws IOException if there is an error reading or writing bytes. */ public static void writeTo(InputStream in, OutputStream out) throws IOException { ReaderWriter.writeTo(in, out); }
/** * Reader characters from an input stream and write then to an output stream. * * @param in the reader to read from. * @param out the writer to write to. * @throws IOException if there is an error reading or writing characters. */ public static void writeTo(Reader in, Writer out) throws IOException { ReaderWriter.writeTo(in, out); }
/** * Reader bytes from an input stream and write then to an output stream. * * @param in the input stream to read from. * @param out the output stream to write to. * @throws IOException if there is an error reading or writing bytes. */ public static void writeTo(InputStream in, OutputStream out) throws IOException { ReaderWriter.writeTo(in, out); }
/** * Reader characters from an input stream and write then to an output stream. * * @param in the reader to read from. * @param out the writer to write to. * @throws IOException if there is an error reading or writing characters. */ public static void writeTo(Reader in, Writer out) throws IOException { ReaderWriter.writeTo(in, out); }
/** * Reader characters from an input stream and write then to an output stream. * * @param in the reader to read from. * @param out the writer to write to. * @throws IOException if there is an error reading or writing characters. */ public static void writeTo(Reader in, Writer out) throws IOException { ReaderWriter.writeTo(in, out); }
/** * Reader bytes from an input stream and write then to an output stream. * * @param in the input stream to read from. * @param out the output stream to write to. * @throws IOException if there is an error reading or writing bytes. */ public static void writeTo(InputStream in, OutputStream out) throws IOException { ReaderWriter.writeTo(in, out); }
/** {@inheritDoc} */ @Override public void writeTo(Path path, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { try (InputStream in = Files.newInputStream(path)) { ReaderWriter.writeTo(in, entityStream); } } }