/** * Returns the wrapped representation's stream. * * @return The wrapped representation's stream. * @see ContentStream#getStream() */ public InputStream getStream() throws IOException { return representation.getStream(); }
public InputStream getContent() throws IOException, IllegalStateException { return entity.getStream(); }
Representation representation = resource.get(); InputStream stream = representation.getStream();
/** * Returns the reader for the template source. * * @param templateSource * The template source {@link Representation}. * @param characterSet * The reader character set. */ public Reader getReader(Object templateSource, String characterSet) throws IOException { Representation r = (Representation) templateSource; return new InputStreamReader(r.getStream(), characterSet); }
@Override public InputSource getInputSource() throws IOException { if (this.xmlRepresentation != null && this.xmlRepresentation.isAvailable()) { return new InputSource(this.xmlRepresentation.getStream()); } return new InputSource((InputStream) null); }
/** * {@inheritDoc}<br> * * The stream of the underlying representation is wrapped with a new * instance of the {@link DigestInputStream} class, which allows to compute * progressively the digest value. */ @Override public InputStream getStream() throws IOException { return new DigestInputStream(getWrappedRepresentation().getStream(), this.computedDigest); }
@Override public InputSource getInputSource() throws IOException { if (this.xmlRepresentation.isAvailable()) { return new InputSource(this.xmlRepresentation.getStream()); } return new InputSource((InputStream) null); }
@Override public InputStream getStream() throws IOException { return getWrappedRepresentation().getStream(); }
ClientResource cr = new ClientResource("http://10.0.2.2:8888/download/"); cr.setRequestEntityBuffering(true); DownloadResource downloadResource = cr.wrap(DownloadResourceProtocol.class); // Remote invocation - seamless: Representation representation = downloadResource.download(); // Using data: ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); IOUtils.copy(representation.getStream(), byteArrayOutputStream); byte[] byteArray = byteArrayOutputStream.toByteArray(); Log.i("Byte array: " + Arrays.toString(byteArray));
/** * 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; }
/** * @see AbstractProvider#writeTo(Object, Class, Type, Annotation[], * MediaType, MultivaluedMap, OutputStream) */ @Override public void writeTo(Form form, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { Representation formRepr = form.getWebRepresentation(); IoUtils.copy(formRepr.getStream(), entityStream); } }
@Override public InputStream getInputStream() { try { return getRequest().getEntity().getStream(); } catch (IOException e) { Context.getCurrentLogger().log(Level.WARNING, "Unable to get the request entity input stream.", e); return null; } }
private Map<String, String> parseUserDetails(Representation repr) throws JAXBException, IOException { JAXBContext context = JAXBContext.newInstance(Authentication.class); Unmarshaller unmarshaller = context.createUnmarshaller(); Authentication auth = (Authentication) unmarshaller.unmarshal(repr.getStream()); Map<String, String> authInfo = new HashMap<>(); authInfo.put("username", auth.getCredintals().getUsername()); authInfo.put("email", auth.getProfile().getEmail()); authInfo.put("firstName", auth.getProfile().getFirstName()); authInfo.put("lastName", auth.getProfile().getLastName()); authInfo.put("enabled", String.valueOf(auth.getProfile().isEnabled())); return authInfo; }
private Status replaceFile(Request request, File file) { File tmp = null; try { tmp = File.createTempFile("restlet-upload", "bin"); if (request.isEntityAvailable()) { Files.copy(request.getEntity().getStream(), tmp.toPath(), REPLACE_EXISTING); } } catch (IOException ioe) { getLogger().log(WARNING, "Unable to create the temporary file", ioe); cleanTemporaryFileIfUploadNotResumed(tmp); return new Status(SERVER_ERROR_INTERNAL, "Unable to create a temporary file"); } return replaceFileByTemporaryFile(request, file, tmp); }
@Override public InputStream getStream() throws IOException { if (canEncode()) { return IoUtils.getStream(this); } else { return getWrappedRepresentation().getStream(); } }
/** * @see MessageBodyWriter#writeTo(Object, Class, Type, Annotation[], * MediaType, MultivaluedMap, OutputStream) */ @Override public void writeTo(MultivaluedMap<String, String> mmap, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException { Form form = Converter.toForm(mmap); Representation formRepr = form.getWebRepresentation(); IoUtils.copy(formRepr.getStream(), entityStream); } }
private void getWctMetadata( SolrRecord solr ) { ClientResource cr = new ClientResource( WctRestletUrl + this.solr.getFieldValue( WctFields.WCT_INSTANCE_ID ) ); try { this.read( cr.get().getStream() ); } catch (ResourceException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
private void getWctMetadata( SolrRecord solr ) { ClientResource cr = new ClientResource( WctRestletUrl + this.solr.getFieldValue( WctFields.WCT_INSTANCE_ID ) ); try { this.read( cr.get().getStream() ); } catch (ResourceException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
@Override public <T> T toObject(Representation source, Class<T> target, Resource resource) throws IOException { LocatorIF base_address = null; // todo from header/params try { TopicMapReaderIF reader = getFragmentReader(source.getStream(), base_address); TopicMapIF fragment = reader.read(); return objectFromFragment(fragment, target, resource); } catch (OntopiaRuntimeException ore) { throw OntopiaRestErrors.COULD_NOT_READ_FRAGMENT.build(ore); } }
/** * Tests whether the RDF/JSON page when there are no annotations is correct. */ @Test public void testAnnotationListEmptyJson() throws Exception { final ClientResource getResource = new ClientResource(this.getUrl(this.propertyUtil.get(OasProps.PROP_BULK_FETCH_ANNOTATION_PATH, OasProps.DEF_BULK_FETCH_ANNOTATION_PATH))); final Representation results = getResource.get(RestletUtilMediaType.APPLICATION_RDF_JSON); // Expecting HTTP 200 OK response Assert.assertEquals(200, getResource.getResponse().getStatus().getCode()); // Expecting application/json MIME type for response Assert.assertEquals(RestletUtilMediaType.APPLICATION_RDF_JSON.getName(), results.getMediaType().getName()); this.assertRdf(results.getStream(), RDFFormat.RDFJSON, 0); }