@Override public boolean isAvailable() { return getWrappedRepresentation().isAvailable(); }
/** * Exhauts the content of the representation by reading it and silently * discarding anything read. * * @return The number of bytes consumed or -1 if unknown. */ public long exhaust() throws IOException { long result = -1L; if (isAvailable()) { result = ByteUtils.exhaust(getStream()); } return result; }
/** * Converts the representation to a string value. Be careful when using this * method as the conversion of large content to a string fully stored in * memory can result in OutOfMemoryErrors being thrown. * * @return The representation as a string value. */ public String getText() throws IOException { String result = null; if (isAvailable()) { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); write(baos); if (getCharacterSet() != null) { result = baos.toString(getCharacterSet().getName()); } else { result = baos.toString(); } } return result; }
Digest result = null; if (isAvailable()) { try { MessageDigest md = MessageDigest.getInstance(algorithm);
/** * Indicates if a content is available and can be sent. 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() { return (getEntity() != null) && (getEntity().getSize() != 0) && getEntity().isAvailable(); }
@Override protected void afterHandle(Request request, Response response) { Map<String, Object> attributes = getContext().getAttributes(); /* Remove all the components that have been through the component manager and that have a PER_LOOKUP policy. */ ComponentManager componentManager = (ComponentManager) attributes.get(Constants.XWIKI_COMPONENT_MANAGER); List<XWikiRestComponent> releasableComponents = (List<XWikiRestComponent>) attributes.get(Constants.RELEASABLE_COMPONENT_REFERENCES); if (releasableComponents != null) { /* Release all the releasable components. */ for (XWikiRestComponent component : releasableComponents) { try { componentManager.release(component); } catch (ComponentLifecycleException e) { getLogger().log( Level.WARNING, String.format("Unable to release component %s. (%s)", component.getClass().getName(), e .getMessage())); } } } /* Avoid that empty entities make the engine forward the response creation to the XWiki servlet. */ if (response.getEntity() != null) { if (!response.getEntity().isAvailable()) { response.setEntity(null); } } }
public static SyndFeed getFeed( String feedId ) throws IllegalArgumentException, MalformedURLException, FeedException, IOException { SyndFeedInput input = new SyndFeedInput(); Response response = RequestFacade.sendMessage( FEED_URL_PART + feedId, Method.GET ); Assert.assertTrue( "Expected content", response.getEntity().isAvailable()); SyndFeed feed = input.build( new XmlReader( response.getEntity().getStream() ) ); // sort it by date sortSyndEntryOrderByPublishedDate( feed ); return feed; }