/** * Creates instance of FastBufferInputStream. * * @param stream */ @Deprecated public FastBufferInputStream(FastBufferOutputStream stream) { this(stream.getFirstBuffer()); }
/** * Writes all data written up to the moment to out. * * @param out * @throws IOException */ public void writeTo(OutputStream out) throws IOException { ByteBuffer b = getFirstBuffer(); while (b != null) { out.write(b.getBytes(), 0, b.getUsedSize()); b = b.getNext(); } }
public InputStream getWrittenDataAsStream() throws IOException { flushBuffers(); if (stream != null) { ByteBuffer firstBuffer = stream.getFirstBuffer(); firstBuffer.compact(); return new FastBufferInputStream(firstBuffer); } else { return EMPTY_STREAM; } }
/** * Writes all data written up to the moment to out. * * @param out * @throws IOException */ public void writeTo(Writer out, String encoding) throws IOException { ByteBuffer b = getFirstBuffer(); while (b != null) { CharBuffer c = b.toCharBuffer(encoding); out.write(c.getChars(), 0, c.getUsedSize()); b = b.getNext(); } }
private static ByteBuffer readContent(InputStream is) throws IOException { if (is == null) { throw new NullPointerException("Resource input stream is null"); } FastBufferOutputStream os = new FastBufferOutputStream(); try { ResourceUtils.copyStreamContent(is, os); } finally { try { is.close(); } catch (IOException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(e.getMessage(), e); } } try { os.close(); } catch (IOException e) { if (LOGGER.isDebugEnabled()) { LOGGER.debug(e.getMessage(), e); } } } ByteBuffer buffer = os.getFirstBuffer(); buffer.compact(); return buffer; }
public InputStream getInputStream() throws IOException { FastBufferOutputStream fbos = new FastBufferOutputStream(); ImageOutputStream imageOutputStream = ImageIO.createImageOutputStream(fbos); try { paintAndWrite(imageOutputStream); } finally { if (imageOutputStream != null) { try { imageOutputStream.close(); } catch (IOException e) { LOGGER.debug(e.getMessage(), e); } try { fbos.close(); } catch (IOException e) { // Swallow } } } ByteBuffer buffer = fbos.getFirstBuffer(); buffer.compact(); return new FastBufferInputStream(buffer); }
public byte[] toByteArray() { ByteBuffer b = getFirstBuffer(); if (b == null) { return new byte[0]; } ByteBuffer l = b; while (l.getNext() != null) { l = l.getNext(); } byte[] result = new byte[l.getTotalSize()]; int index = 0; while (b != null) { int s = b.getUsedSize(); System.arraycopy(b.getBytes(), 0, result, index, s); index += s; b = b.getNext(); } return result; }