@Override public void writeTo(final OutputStream outstream) throws IOException { entity.write(outstream); }
@Override public void write(Writer writer) throws IOException { getWrappedRepresentation().write(writer); } }
@Override public void write(OutputStream outputStream) throws IOException { getWrappedRepresentation().write(outputStream); }
@Override public void write(WritableByteChannel writableChannel) throws IOException { getWrappedRepresentation().write(writableChannel); }
public void run() { try { final WritableByteChannel wbc = pipe.sink(); representation.write(wbc); wbc.close(); } catch (IOException ioe) { Context.getCurrentLogger().log(Level.FINE, "Error while writing to the piped channel.", ioe); } } });
public void run() { try { final OutputStream os = pipe.getOutputStream(); representation.write(os); os.write(-1); os.close(); } catch (IOException ioe) { Context.getCurrentLogger().log(Level.FINE, "Error while writing to the piped input stream.", ioe); } } });
/** * {@inheritDoc}<br> * * The output stream is wrapped with a new instance of the * {@link DigestOutputStream} class, which allows to compute progressively * the digest value. */ @Override public void write(OutputStream outputStream) throws IOException { getWrappedRepresentation().write( new DigestOutputStream(outputStream, this.computedDigest)); }
/** * 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; }
public void testGetAllCSVQuery() throws Exception { RequestResource.CSVFormat format = new RequestResource.CSVFormat( new String[]{"id", "path", "startTime"}, monitor); ByteArrayOutputStream out = new ByteArrayOutputStream(); format.toRepresentation(new Query()).write(out); BufferedReader in = new BufferedReader(new InputStreamReader( new ByteArrayInputStream(out.toByteArray()))); String line = in.readLine(); assertEquals("id,path,startTime", line); Iterator<RequestData> it = monitor.getDAO().getRequests().iterator(); while((line = in.readLine()) != null) { assertTrue(it.hasNext()); RequestData data = it.next(); String expected = data.getId() + "," + data.getPath() + "," + DateUtil.serializeDateTime(data.getStartTime()); assertEquals(expected, line); } assertFalse(it.hasNext()); }
@Test public void testGetByIdHTML() throws Exception { Request req = new Request(); Response res = new Response(req); RequestResource.HTMLFormat format = new RequestResource.HTMLFormat(req, res, resource, monitor); ByteArrayOutputStream out = new ByteArrayOutputStream(); format.toRepresentation(monitor.getDAO().getRequest(2)).write(out); assertTrue(new String(out.toByteArray()).startsWith("<html>")); }
@Test public void testGetAllCSV() throws Exception { RequestResource.CSVFormat format = new RequestResource.CSVFormat( new String[]{"id", "path", "startTime"}, monitor); ByteArrayOutputStream out = new ByteArrayOutputStream(); format.toRepresentation(monitor.getDAO().getRequests()).write(out); BufferedReader in = new BufferedReader(new InputStreamReader( new ByteArrayInputStream(out.toByteArray()))); String line = in.readLine(); assertEquals("id,path,startTime", line); Iterator<RequestData> it = monitor.getDAO().getRequests().iterator(); while((line = in.readLine()) != null) { assertTrue(it.hasNext()); RequestData data = it.next(); String expected = data.getId() + "," + data.getPath() + "," + DateUtil.serializeDateTime(data.getStartTime()); assertEquals(expected, line); } assertFalse(it.hasNext()); }
zip.toRepresentation(data).write(out);
@Test public void testGetAllHTML() throws Exception { Request req = new Request(); PageInfo page = new PageInfo(); page.setBasePath("foo"); page.setPagePath("bar"); page.setBaseURL("baz"); req.getAttributes().put(PageInfo.KEY, page); Response res = new Response(req); RequestResource.HTMLFormat format = new RequestResource.HTMLFormat(req, res, resource, monitor); ByteArrayOutputStream out = new ByteArrayOutputStream(); format.toRepresentation(monitor.getDAO().getRequests()).write(out); assertTrue(new String(out.toByteArray()).startsWith("<html>")); }
format.toRepresentation(monitor.getDAO().getRequests()).write(out);
format.toRepresentation(style).write(out);