/** * Indicates if the representation is empty. It basically means that its * size is 0. * * @return True if the representation has no content. */ public boolean isEmpty() { return getSize() == 0; }
/** * Returns the wrapped representation's size. * * @return The wrapped representation's size. * @see ContentStream#getSize() */ public Long getSize() { long s = representation.getSize(); if (s == Representation.UNKNOWN_SIZE) return null; return s; }
/** * Indicates if the representation is empty. It basically means that its * size is 0. * * @return True if the representation has no content. */ public boolean isEmpty() { return getSize() == 0; }
/** * Indicates if the size of representation is known. It basically means that * its size 0 or superior. * * @return True if the representation has content. */ public boolean hasKnownSize() { return getSize() >= 0; }
/** * Indicates if the size of representation is known. It basically means that * its size 0 or superior. * * @return True if the representation has content. */ public boolean hasKnownSize() { return getSize() >= 0; }
public long getContentLength() { return entity.getSize(); }
public boolean isStreaming() { return (entity.getSize() == Representation.UNKNOWN_SIZE); }
public long getContentLength() { return entity.getSize(); }
/** * Indicates if some fresh content is potentially available, without having * to actually call one of the content manipulation method like getStream() * that would actually consume it. Note that when the size of a * representation is 0 is a not considered available. However, sometimes the * size isn't known until a read attempt is made, so availability doesn't * guarantee a non empty content.<br> * <br> * This is especially useful for transient representation whose content can * only be accessed once and also when the size of the representation is not * known in advance. * * @return True if some fresh content is available. */ public boolean isAvailable() { return this.available && (getSize() != 0); }
/** * Indicates if some fresh content is potentially available, without having * to actually call one of the content manipulation method like getStream() * that would actually consume it. Note that when the size of a * representation is 0 is a not considered available. However, sometimes the * size isn't known until a read attempt is made, so availability doesn't * guarantee a non empty content.<br> * <br> * This is especially useful for transient representation whose content can * only be accessed once and also when the size of the representation is not * known in advance. * * @return True if some fresh content is available. */ public boolean isAvailable() { return this.available && (getSize() != 0); }
@Override public long getSize() { if (this.jsonRepresentation != null) { return this.jsonRepresentation.getSize(); } return super.getSize(); }
@Override public long getSize() { if (this.jsonRepresentation != null) { return this.jsonRepresentation.getSize(); } return super.getSize(); }
@Override public long getSize() { if (this.jsonRepresentation != null) { return this.jsonRepresentation.getSize(); } return super.getSize(); }
@Override public long getSize() { return getWrappedRepresentation().getSize(); }
@Override public long getSize() { long result = wrappedRepresentation.getSize(); if (result > 0 && MediaType.APPLICATION_JSON.equals(wrappedRepresentation .getMediaType())) { try { java.io.StringWriter sw = new java.io.StringWriter(); write(sw); sw.flush(); return sw.toString().length(); } catch (IOException e) { return UNKNOWN_SIZE; } } return UNKNOWN_SIZE; }
@Override public long getSize() { long result = wrappedRepresentation.getSize(); if (result > 0 && MediaType.APPLICATION_JSON.equals(wrappedRepresentation .getMediaType())) { try { java.io.StringWriter sw = new java.io.StringWriter(); write(sw); sw.flush(); return sw.toString().length(); } catch (IOException e) { return UNKNOWN_SIZE; } } return UNKNOWN_SIZE; }
/** * Returns the size in bytes of the encoded representation if known, * UNKNOWN_SIZE (-1) otherwise. * * @return The size in bytes if known, UNKNOWN_SIZE (-1) otherwise. */ @Override public long getSize() { long result = UNKNOWN_SIZE; if (canEncode()) { if (this.encoding.equals(Encoding.IDENTITY)) { result = getWrappedRepresentation().getSize(); } } else { result = getWrappedRepresentation().getSize(); } return result; }
@Override public long getSize(Object object, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { Representation representation = null; try { // Convert the object into a representation Variant targetVariant = new Variant(toRestletMediaType(mediaType)); representation = getConverterService().toRepresentation(object, targetVariant, null); } catch (IOException e) { Context.getCurrentLogger().log(Level.FINE, "Unable to get the size", e); } return (representation == null) ? -1 : representation.getSize(); }
/** * 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())); } }