public void complete() { buffer.compact(); } }
public void complete() { buffer.compact(); } }
/** * @since 4.0 */ public void compact() { if (bytes.length - usedSize > MAX_WASTE) { byte[] bs = new byte[usedSize]; System.arraycopy(bytes, 0, bs, 0, usedSize); this.bytes = bs; this.cacheSize = bs.length; } if (next != null) { next.compact(); } }
public InputStream getWrittenDataAsStream() throws IOException { flushBuffers(); if (stream != null) { ByteBuffer firstBuffer = stream.getFirstBuffer(); firstBuffer.compact(); return new FastBufferInputStream(firstBuffer); } else { return EMPTY_STREAM; } }
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); }