@Override public InputSource getInputSource() throws IOException { if (this.xmlRepresentation != null && this.xmlRepresentation.isAvailable()) { return new InputSource(this.xmlRepresentation.getStream()); } return new InputSource((InputStream) null); }
@Override public InputSource getInputSource() throws IOException { if (this.xmlRepresentation.isAvailable()) { return new InputSource(this.xmlRepresentation.getStream()); } return new InputSource((InputStream) null); }
@Override public boolean isAvailable() { return getWrappedRepresentation().isAvailable(); }
/** * Exhaust the content of the representation by reading it and silently * discarding anything read. By default, it relies on {@link #getStream()} * and closes the retrieved stream in the end. * * @return The number of bytes consumed or -1 if unknown. */ public long exhaust() throws IOException { long result = -1L; if (isAvailable()) { InputStream is = getStream(); // result = IoUtils.exhaust(is); is.close(); } return result; }
/** * Constructor. * * @param xmlRepresentation * A source XML representation to parse. */ public DomRepresentation(Representation xmlRepresentation) { super((xmlRepresentation == null) ? null : xmlRepresentation .getMediaType()); this.setAvailable(xmlRepresentation.isAvailable()); this.xmlRepresentation = xmlRepresentation; }
/** * Exhaust the content of the representation by reading it and silently * discarding anything read. By default, it relies on {@link #getStream()} * and closes the retrieved stream in the end. * * @return The number of bytes consumed or -1 if unknown. */ public long exhaust() throws IOException { long result = -1L; if (isAvailable()) { InputStream is = getStream(); result = IoUtils.exhaust(is); is.close(); } return result; }
/** * Constructor. * * @param xmlRepresentation * A source XML representation to parse. */ public DomRepresentation(Representation xmlRepresentation) { super((xmlRepresentation == null) ? null : xmlRepresentation.getMediaType()); this.setAvailable((xmlRepresentation == null) ? false : xmlRepresentation.isAvailable()); this.xmlRepresentation = xmlRepresentation; }
/** * Indicates if a content is available and can be sent or received. Several * conditions must be met: the content must exists and have some available * data. * * @return True if a content is available and can be sent. */ public boolean isEntityAvailable() { // The declaration of the "result" variable is a workaround for the GWT // platform. Please keep it! boolean result = (getEntity() != null) && getEntity().isAvailable(); return result; }
/** * Indicates if a content is available and can be sent or received. Several * conditions must be met: the content must exists and have some available * data. * * @return True if a content is available and can be sent. */ public boolean isEntityAvailable() { // The declaration of the "result" variable is a workaround for the GWT // platform. Please keep it! boolean result = (getEntity() != null) && getEntity().isAvailable(); return result; }
/** * Reads the first entry with the given name. * * @param post * The web form representation. * @param name * The name to match. * @return The form data entry. * @throws IOException */ public static FormData getFirstEntry(Representation post, String name) throws IOException { if (!post.isAvailable()) { throw new IllegalStateException( "The Web form cannot be parsed as no fresh content is available. If this entity has been already read once, caching of the entity is required"); } return new FormReader(post).readFirstEntry(name); }
/** * Reads the first parameter with the given name. * * @param post * The web form representation. * @param name * The parameter name to match. * @return The parameter. * @throws IOException */ public static Parameter getFirstParameter(Representation post, String name) throws IOException { if (!post.isAvailable()) { throw new IllegalStateException( "The Web form cannot be parsed as no fresh content is available. If this entity has been already read once, caching of the entity is required"); } return new FormReader(post).readFirstParameter(name); }
/** * Reads the first parameter with the given name. * * @param post * The web form representation. * @param name * The parameter name to match. * @return The parameter. * @throws IOException */ public static Parameter getFirstParameter(Representation post, String name) throws IOException { if (!post.isAvailable()) { throw new IllegalStateException( "The Web form cannot be parsed as no fresh content is available. If this entity has been already read once, caching of the entity is required"); } return new FormReader(post).readFirstParameter(name); }
/** * Reads the entries with the given name.<br> * If multiple values are found, a list is returned created. * * @param form * The web form representation. * @param name * The name to match. * @return The form data or list of values. * @throws IOException * If the entries could not be read. */ public static Object getEntry(Representation form, String name) throws IOException { if (!form.isAvailable()) { throw new IllegalStateException( "The HTML form cannot be parsed as no fresh content is available. If this entity has been already read once, caching of the entity is required"); } return new FormReader(form).readEntry(name); }
/** * 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); } } }
private boolean shouldShowCommandForm( Method interactionMethod ) { // Show form on GET/HEAD if( Request.getCurrent().getMethod().isSafe() ) { return true; } if( interactionMethod.getParameterTypes().length > 0 ) { return !( interactionMethod.getParameterTypes()[ 0 ].equals( Response.class ) || Request.getCurrent() .getEntity() .isAvailable() || Request.getCurrent().getEntityAsText() != null || Request.getCurrent() .getResourceRef() .getQuery() != null ); } return false; }
private boolean shouldShowCommandForm( Method interactionMethod ) { // Show form on GET/HEAD if( Request.getCurrent().getMethod().isSafe() ) { return true; } if( interactionMethod.getParameterTypes().length > 0 ) { return !( interactionMethod.getParameterTypes()[ 0 ].equals( Response.class ) || Request.getCurrent() .getEntity() .isAvailable() || Request.getCurrent().getEntityAsText() != null || Request.getCurrent() .getResourceRef() .getQuery() != null ); } return false; }
private boolean shouldShowCommandForm( Method interactionMethod ) { // Show form on GET/HEAD if( Request.getCurrent().getMethod().isSafe() ) { return true; } if( interactionMethod.getParameterTypes().length > 0 ) { return !( interactionMethod.getParameterTypes()[ 0 ].equals( Response.class ) || Request.getCurrent() .getEntity() .isAvailable() || Request.getCurrent().getEntityAsText() != null || Request.getCurrent() .getResourceRef() .getQuery() != null ); } return false; }
@Override public InputStream getInputStream() throws IOException { // Milton doesn't check for null InputStream, but there are some places where it checks for -1 // Don't call target.isEntityAvailable(), doesn't work for PUT, see its source... if (getTarget().getEntity() != null && getTarget().getEntity().isAvailable()) { InputStream stream = getTarget().getEntity().getStream(); if (stream != null) return stream; } return new InputStream() { @Override public int read() throws IOException { return -1; } }; }
/** * 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())); } }
@Override public void writeResponseHead(org.restlet.Response restletResponse) throws IOException { final Headers headers = this.exchange.getResponseHeaders(); for (Header header : getResponseHeaders()) { headers.add(header.getName(), header.getValue()); } // Send the headers Representation entity = restletResponse.getEntity(); long responseLength = 0; if (entity == null || !entity.isAvailable()) { responseLength = -1; } else if (entity.getAvailableSize() != Representation.UNKNOWN_SIZE) { responseLength = entity.getAvailableSize(); } this.exchange.sendResponseHeaders(getStatusCode(), responseLength); }