@Override public String getText() throws IOException { buffer(); if (getBuffer() != null) { return (getCharacterSet() != null) ? new String(getBuffer(), getCharacterSet().toCharset().name()) : new String(getBuffer()); } return null; }
@Override public long getAvailableSize() { return getSize(); }
@Override public void write(Writer writer) throws IOException { String text = getText(); if (text != null) { writer.write(text); } }
/** * Buffers the content of the wrapped entity. * * @throws IOException */ private void buffer() throws IOException { if (!isBuffered()) { if (getWrappedRepresentation().isAvailable()) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); getWrappedRepresentation().write(baos); baos.flush(); setBuffer(baos.toByteArray()); setBuffered(true); } } }
@Override public Reader getReader() throws IOException { return IoUtils.getReader(getStream(), getCharacterSet()); }
@Override public boolean isAvailable() { try { buffer(); } catch (IOException e) { Context.getCurrentLogger().log(Level.FINER, "Unable to buffer the wrapped representation", e); } return isBuffered(); }
@Override public java.nio.channels.ReadableByteChannel getChannel() throws IOException { return IoUtils.getChannel(getStream()); }
/** * If the entity is transient or its size unknown in advance but available, * then the entity is wrapped with a {@link org.restlet.representation.BufferingRepresentation}.<br> * <br> * Be careful as this method could create potentially very large byte * buffers in memory that could impact your application performance. * * @see org.restlet.representation.BufferingRepresentation * @see ClientResource#setRequestEntityBuffering(boolean) * @see ClientResource#setResponseEntityBuffering(boolean) */ public void bufferEntity() { if ((getEntity() != null) && (getEntity().isTransient() || getEntity().getSize() == UNKNOWN_SIZE) && getEntity().isAvailable()) { setEntity(new org.restlet.representation.BufferingRepresentation(getEntity())); } }