List of usage examples for java.io ByteArrayOutputStream size
public synchronized int size()
From source file:eu.scape_project.fcrepo.integration.IntellectualEntitiesIT.java
@Test public void testIngestAndUpdateBistreamMetadata() throws Exception { IntellectualEntity ie1 = TestUtil.createTestEntity("entity-22"); this.postEntity(ie1); HttpPut put = new HttpPut(SCAPE_URL + "/metadata/entity-22/representation-1/file-1/bitstream-1/TECHNICAL"); ByteArrayOutputStream sink = new ByteArrayOutputStream(); this.marshaller.serialize(TestUtil.createMIXRecord(), sink); put.setEntity(new InputStreamEntity(new ByteArrayInputStream(sink.toByteArray()), sink.size(), ContentType.TEXT_XML));//from w w w.ja va2 s . c o m HttpResponse resp = this.client.execute(put); assertEquals(200, resp.getStatusLine().getStatusCode()); put.releaseConnection(); /* fetch the entity and check that the title has been updated */ HttpGet get = new HttpGet(SCAPE_URL + "/metadata/entity-22/representation-1/file-1/bitstream-1/TECHNICAL"); resp = this.client.execute(get); assertEquals(200, resp.getStatusLine().getStatusCode()); Object fetched = this.marshaller.deserialize(resp.getEntity().getContent()); assertEquals(Mix.class, fetched.getClass()); get.releaseConnection(); }
From source file:eu.scape_project.fcrepo.integration.IntellectualEntitiesIT.java
@Test public void testIngestAndFetchVersionList() throws Exception { IntellectualEntity ie1 = TestUtil.createTestEntity("entity-23"); this.postEntity(ie1); HttpPut put = new HttpPut(SCAPE_URL + "/metadata/entity-23/representation-1/file-1/bitstream-1/TECHNICAL"); ByteArrayOutputStream sink = new ByteArrayOutputStream(); this.marshaller.serialize(TestUtil.createMIXRecord(), sink); put.setEntity(new InputStreamEntity(new ByteArrayInputStream(sink.toByteArray()), sink.size(), ContentType.TEXT_XML));//from ww w.ja va 2s. c o m HttpResponse resp = this.client.execute(put); assertEquals(200, resp.getStatusLine().getStatusCode()); put.releaseConnection(); /* fetch the entity and check that the title has been updated */ HttpGet get = new HttpGet(SCAPE_URL + "/entity-version-list/entity-23"); resp = this.client.execute(get); assertEquals(200, resp.getStatusLine().getStatusCode()); VersionList fetched = (VersionList) this.marshaller.deserialize(resp.getEntity().getContent()); assertEquals(2, fetched.getVersionIdentifiers().size()); get.releaseConnection(); }
From source file:eu.scape_project.fcrepo.integration.IntellectualEntitiesIT.java
@Test public void testIngestAndUpdateBitstreamAndFetchOldVersion() throws Exception { IntellectualEntity ie1 = TestUtil.createTestEntity("entity-26"); this.postEntity(ie1); HttpPut put = new HttpPut(SCAPE_URL + "/metadata/entity-26/representation-1/file-1/bitstream-1/TECHNICAL"); ByteArrayOutputStream sink = new ByteArrayOutputStream(); this.marshaller.serialize(TestUtil.createMIXRecord(), sink); put.setEntity(new InputStreamEntity(new ByteArrayInputStream(sink.toByteArray()), sink.size(), ContentType.TEXT_XML));//ww w. j a va 2s .c o m HttpResponse resp = this.client.execute(put); assertEquals(200, resp.getStatusLine().getStatusCode()); put.releaseConnection(); /* fetch the entity and check that the title has been updated */ HttpGet get = new HttpGet(SCAPE_URL + "/bitstream/entity-26/representation-1/file-1/bitstream-1/1"); resp = this.client.execute(get); assertEquals(200, resp.getStatusLine().getStatusCode()); BitStream fetched = (BitStream) this.marshaller.deserialize(resp.getEntity().getContent()); assertEquals(Fits.class, fetched.getTechnical().getClass()); get.releaseConnection(); }
From source file:at.medevit.elexis.ehc.core.internal.EhcCoreServiceTest.java
@Test public void testWriteXdm() throws Exception { EhcCoreServiceImpl service = new EhcCoreServiceImpl(); CdaChVacd cda = service.getVaccinationsDocument(patient, mandant); ByteArrayOutputStream output = new ByteArrayOutputStream(); CDAUtil.save(cda.getDocRoot().getClinicalDocument(), output); ConvenienceCommunication conCom = new ConvenienceCommunication(); DocumentMetadata metaData = conCom.addChDocument(DocumentDescriptor.CDA_R2, new ByteArrayInputStream(output.toByteArray())); assertNotNull(metaData);/*w w w. j av a2 s . co m*/ List<Identificator> ids = cda.getPatient().getIds(); if (!ids.isEmpty()) { metaData.setDestinationPatientId(ids.get(0)); } output.reset(); conCom.createXdmContents(output); assertTrue(output.size() > 0); }
From source file:eu.scape_project.fcrepo.integration.IntellectualEntitiesIT.java
@Test public void testIngestAndUpdateFileMetadata() throws Exception { IntellectualEntity ie1 = TestUtil.createTestEntity("entity-21"); this.postEntity(ie1); HttpPut put = new HttpPut(SCAPE_URL + "/metadata/entity-21/representation-1/file-1/TECHNICAL"); ByteArrayOutputStream sink = new ByteArrayOutputStream(); this.marshaller.serialize(TestUtil.createFITSRecord(), sink); put.setEntity(new InputStreamEntity(new ByteArrayInputStream(sink.toByteArray()), sink.size(), ContentType.TEXT_XML));//ww w .j a v a 2 s . c o m HttpResponse resp = this.client.execute(put); assertEquals(200, resp.getStatusLine().getStatusCode()); put.releaseConnection(); /* fetch the entity and check that the title has been updated */ HttpGet get = new HttpGet(SCAPE_URL + "/metadata/entity-21/representation-1/file-1/TECHNICAL"); resp = this.client.execute(get); assertEquals(200, resp.getStatusLine().getStatusCode()); Object fetched = this.marshaller.deserialize(resp.getEntity().getContent()); assertEquals(Fits.class, fetched.getClass()); get.releaseConnection(); }
From source file:eu.scape_project.fcrepo.integration.IntellectualEntitiesIT.java
@Test public void testIngestAndUpdateIntellectualEntity() throws Exception { IntellectualEntity ie1 = TestUtil.createTestEntity("entity-17"); this.postEntity(ie1); org.purl.dc.elements._1.ObjectFactory dcFac = new org.purl.dc.elements._1.ObjectFactory(); ElementContainer cnt = dcFac.createElementContainer(); SimpleLiteral lit_title = new SimpleLiteral(); lit_title.getContent().add("Object Updated"); cnt.getAny().add(dcFac.createTitle(lit_title)); IntellectualEntity ie2 = new IntellectualEntity.Builder(ie1).descriptive(cnt).build(); /* update the current object */ HttpPut put = new HttpPut(SCAPE_URL + "/entity/entity-17"); ByteArrayOutputStream sink = new ByteArrayOutputStream(); this.marshaller.serialize(ie2, sink); put.setEntity(new InputStreamEntity(new ByteArrayInputStream(sink.toByteArray()), sink.size(), ContentType.TEXT_XML));/*from www . j ava2 s. c om*/ HttpResponse resp = this.client.execute(put); assertEquals(200, resp.getStatusLine().getStatusCode()); put.releaseConnection(); /* check that the new version is returned */ HttpGet get = new HttpGet(SCAPE_URL + "/entity/entity-17"); resp = this.client.execute(get); assertEquals(200, resp.getStatusLine().getStatusCode()); IntellectualEntity fetched = this.marshaller.deserialize(IntellectualEntity.class, resp.getEntity().getContent()); get.releaseConnection(); assertNotNull(fetched.getDescriptive()); assertEquals(ElementContainer.class, fetched.getDescriptive().getClass()); ElementContainer dc = (ElementContainer) fetched.getDescriptive(); assertEquals("Object Updated", dc.getAny().get(0).getValue().getContent().get(0)); /* check that the old version is returned when specifically asked for */ get = new HttpGet(SCAPE_URL + "/entity/entity-17/1"); resp = this.client.execute(get); assertEquals(200, resp.getStatusLine().getStatusCode()); fetched = this.marshaller.deserialize(IntellectualEntity.class, resp.getEntity().getContent()); get.releaseConnection(); assertNotNull(fetched.getDescriptive()); assertEquals(ElementContainer.class, fetched.getDescriptive().getClass()); dc = (ElementContainer) fetched.getDescriptive(); assertEquals("Object 1", dc.getAny().get(0).getValue().getContent().get(0)); /* check that the new version is returned when specifically asked for */ get = new HttpGet(SCAPE_URL + "/entity/entity-17/2"); resp = this.client.execute(get); assertEquals(200, resp.getStatusLine().getStatusCode()); fetched = this.marshaller.deserialize(IntellectualEntity.class, resp.getEntity().getContent()); get.releaseConnection(); assertNotNull(fetched.getDescriptive()); assertEquals(ElementContainer.class, fetched.getDescriptive().getClass()); dc = (ElementContainer) fetched.getDescriptive(); assertEquals("Object Updated", dc.getAny().get(0).getValue().getContent().get(0)); }
From source file:de.undercouch.bson4jackson.BsonGeneratorTest.java
@Test public void stream() throws Exception { ByteArrayOutputStream baos = new ByteArrayOutputStream(); BsonFactory fac = new BsonFactory(); fac.enable(BsonGenerator.Feature.ENABLE_STREAMING); BsonGenerator gen = fac.createGenerator(baos); byte[] dummy = new byte[DynamicOutputBuffer.DEFAULT_BUFFER_SIZE * 3 / 2]; gen.writeStartObject();/* w w w . jav a2 s .c o m*/ gen.writeFieldName("Test"); gen.writeBinary(dummy); assertEquals(DynamicOutputBuffer.DEFAULT_BUFFER_SIZE, baos.size()); gen.writeEndObject(); gen.writeStartObject(); gen.writeFieldName("Test"); gen.writeBinary(dummy); assertEquals(DynamicOutputBuffer.DEFAULT_BUFFER_SIZE * 3, baos.size()); gen.writeEndObject(); gen.close(); assertTrue(baos.size() > DynamicOutputBuffer.DEFAULT_BUFFER_SIZE * 3); }
From source file:org.apache.jmeter.protocol.tcp.sampler.P2PTCP.java
/** * Reads data until the defined EOM byte is reached. * If there is no EOM byte defined, then reads until * the end of the stream is reached./*from w ww . j ava 2 s.c o m*/ * Response data is converted to hex-encoded binary * @return hex-encoded binary string * @throws ReadException when reading fails */ @Override public String read(InputStream is) throws ReadException { ByteArrayOutputStream w = new ByteArrayOutputStream(); try { byte[] buffer = new byte[4096]; int x = 0; /*while ((x = is.read(buffer)) > -1) { w.write(buffer, 0, x); if (useEolByte && (buffer[x - 1] == eolByte)) { break; } }*/ for (int i = 0; i < readLoopCount; i++) { if ((x = is.read(buffer)) > -1) { w.write(buffer, 0, x); } } IOUtils.closeQuietly(w); // For completeness final String hexString = JOrphanUtils.baToHexString(w.toByteArray()); if (log.isDebugEnabled()) { log.debug("Read: " + w.size() + "(size)\n" + hexString); System.out .println("============TCP==========" + new Date().toString() + "=================="); System.out.println(); System.out.println(BU.bytes2HexGoodLook(BU.hex2Bytes(hexString))); System.out.println(); } return hexString; } catch (IOException e) { throw new ReadException("", e, JOrphanUtils.baToHexString(w.toByteArray())); } }
From source file:com.msopentech.odatajclient.testservice.utils.JSONUtilities.java
@Override public InputStream readEntities(final List<String> links, final String linkName, final String next, final boolean forceFeed) throws Exception { if (links.isEmpty()) { throw new NotFoundException(); }// w ww . j av a 2 s . c o m final ObjectMapper mapper = new ObjectMapper(); final ObjectNode node = mapper.createObjectNode(); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); if (forceFeed || links.size() > 1) { bos.write("[".getBytes()); } for (String link : links) { try { final Map.Entry<String, String> uri = Commons.parseEntityURI(link); final Map.Entry<String, InputStream> entity = readEntity(uri.getKey(), uri.getValue(), Accept.JSON_FULLMETA); if (bos.size() > 1) { bos.write(",".getBytes()); } IOUtils.copy(entity.getValue(), bos); } catch (Exception e) { // log and ignore link LOG.warn("Error parsing uri {}", link, e); } } if (forceFeed || links.size() > 1) { bos.write("]".getBytes()); } node.set(JSON_VALUE_NAME, mapper.readTree(new ByteArrayInputStream(bos.toByteArray()))); if (StringUtils.isNotBlank(next)) { node.set(JSON_NEXTLINK_NAME, new TextNode(next)); } return IOUtils.toInputStream(node.toString()); }
From source file:org.apache.fop.fonts.type1.Type1SubsetFile.java
protected byte[] stitchFont(ByteArrayOutputStream boasHeader, ByteArrayOutputStream boasMain, ByteArrayOutputStream boasTrailer) throws IOException { int headerLength = boasHeader.size(); int mainLength = boasMain.size(); boasMain.write(128);// ww w . jav a 2s.c o m boasMain.write(1); updateSectionSize(boasTrailer.size()).writeTo(boasMain); boasTrailer.write(128); boasTrailer.write(3); boasTrailer.writeTo(boasMain); boasHeader.write(128); boasHeader.write(2); //You need to encode the main section first before getting it's size!!! updateSectionSize(mainLength).writeTo(boasHeader); boasMain.writeTo(boasHeader); ByteArrayOutputStream fullFont = new ByteArrayOutputStream(); fullFont.write(128); fullFont.write(1); updateSectionSize(headerLength).writeTo(fullFont); boasHeader.writeTo(fullFont); return fullFont.toByteArray(); }