List of usage examples for java.io ByteArrayOutputStream size
public synchronized int size()
From source file:org.bimserver.tests.TestSimultaniousDownloadWithCaching.java
private void start() { BimServerConfig config = new BimServerConfig(); Path homeDir = Paths.get("home"); try {/*w w w. j a va 2 s. co m*/ if (Files.isDirectory(homeDir)) { PathUtils.removeDirectoryWithContent(homeDir); } } catch (IOException e) { e.printStackTrace(); } config.setClassPath(System.getProperty("java.class.path")); config.setHomeDir(homeDir); config.setPort(8080); config.setStartEmbeddedWebServer(true); config.setResourceFetcher(new LocalDevelopmentResourceFetcher(Paths.get("../"))); final BimServer bimServer = new BimServer(config); try { LocalDevPluginLoader.loadPlugins(bimServer.getPluginManager(), null); bimServer.start(); if (bimServer.getServerInfo().getServerState() == ServerState.NOT_SETUP) { bimServer.getService(AdminInterface.class).setup("http://localhost", "Administrator", "admin@bimserver.org", "admin", null, null, null); } } catch (PluginException e2) { e2.printStackTrace(); } catch (ServerException e) { e.printStackTrace(); } catch (DatabaseInitException e) { e.printStackTrace(); } catch (BimserverDatabaseException e) { e.printStackTrace(); } catch (DatabaseRestartRequiredException e) { e.printStackTrace(); } catch (UserException e) { e.printStackTrace(); } try { final ServiceMap serviceMap = bimServer.getServiceFactory().get(AccessMethod.INTERNAL); ServiceInterface serviceInterface = serviceMap.get(ServiceInterface.class); SettingsInterface settingsInterface = serviceMap.get(SettingsInterface.class); final AuthInterface authInterface = serviceMap.get(AuthInterface.class); serviceInterface = bimServer.getServiceFactory() .get(authInterface.login("admin@bimserver.org", "admin"), AccessMethod.INTERNAL) .get(ServiceInterface.class); settingsInterface.setCacheOutputFiles(true); settingsInterface.setGenerateGeometryOnCheckin(false); final SProject project = serviceMap.getServiceInterface().addProject("test", "ifc2x3tc1"); SDeserializerPluginConfiguration deserializerByName = serviceMap.getServiceInterface() .getDeserializerByName("IfcStepDeserializer"); Path file = Paths.get("../TestData/data/AC11-Institute-Var-2-IFC.ifc"); serviceInterface.checkin(project.getOid(), "test", deserializerByName.getOid(), file.toFile().length(), file.getFileName().toString(), new DataHandler(new FileDataSource(file.toFile())), false, true); final SProject projectUpdate = serviceMap.getServiceInterface().getProjectByPoid(project.getOid()); ThreadPoolExecutor executor = new ThreadPoolExecutor(20, 20, 1, TimeUnit.HOURS, new ArrayBlockingQueue<Runnable>(1000)); for (int i = 0; i < 20; i++) { executor.execute(new Runnable() { @Override public void run() { try { ServiceMap serviceMap2 = bimServer.getServiceFactory().get( authInterface.login("admin@bimserver.org", "admin"), AccessMethod.INTERNAL); SSerializerPluginConfiguration serializerPluginConfiguration = serviceMap .getServiceInterface().getSerializerByName("Ifc2x3"); Long download = serviceMap2.getServiceInterface().download( Collections.singleton(projectUpdate.getLastRevisionId()), DefaultQueries.allAsString(), serializerPluginConfiguration.getOid(), true); SDownloadResult downloadData = serviceMap2.getServiceInterface() .getDownloadData(download); if (downloadData.getFile() .getDataSource() instanceof CacheStoringEmfSerializerDataSource) { CacheStoringEmfSerializerDataSource c = (CacheStoringEmfSerializerDataSource) downloadData .getFile().getDataSource(); try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); c.writeToOutputStream(baos, null); System.out.println(baos.size()); } catch (SerializerException e) { e.printStackTrace(); } } else { ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(downloadData.getFile().getInputStream(), baos); System.out.println(baos.size()); } serviceMap2.getServiceInterface().cleanupLongAction(download); } catch (ServerException e) { e.printStackTrace(); } catch (UserException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (PublicInterfaceNotFoundException e1) { e1.printStackTrace(); } } }); } executor.shutdown(); executor.awaitTermination(1, TimeUnit.HOURS); bimServer.stop(); } catch (ServerException e1) { e1.printStackTrace(); } catch (UserException e1) { e1.printStackTrace(); } catch (InterruptedException e) { e.printStackTrace(); } catch (PublicInterfaceNotFoundException e2) { e2.printStackTrace(); } }
From source file:com.jayway.restassured.itest.java.FileDownloadITest.java
@Test public void loggingWithBinaryCharsetWorks() throws Exception { int expectedSize = IOUtils .toByteArray(getClass().getResourceAsStream("/powermock-easymock-junit-1.4.12.zip")).length; final StringWriter writer = new StringWriter(); final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true); final InputStream inputStream = given().config(config().logConfig(new LogConfig(captor, false))).expect() .log().all().when().get("http://powermock.googlecode.com/files/powermock-easymock-junit-1.4.12.zip") .asInputStream();//from w w w . jav a 2 s .c o m final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); IOUtils.copy(inputStream, byteArrayOutputStream); IOUtils.closeQuietly(byteArrayOutputStream); IOUtils.closeQuietly(inputStream); assertThat(writer.toString(), not(isEmptyOrNullString())); assertThat(byteArrayOutputStream.size(), equalTo(expectedSize)); }
From source file:gov.nih.nci.cacis.transform.XSLTv2TransformerTest.java
@Test public void transformStream() throws XMLStreamException, TransformerException, URISyntaxException, IOException, SAXException, ParserConfigurationException, XPathExpressionException { final ByteArrayOutputStream os = new ByteArrayOutputStream(); final Map<String, String> params = new HashMap<String, String>(); params.put("BaseURI", "http://yadda.com/someUUID"); transform.transform(params, sampleMessageIS, os); assertNotNull(os);//from w w w .jav a2s. c om assertTrue(os.size() > 0); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); // never forget this! DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(new ByteArrayInputStream(os.toByteArray())); assertNotNull(doc); XPathFactory xPathFactory = XPathFactory.newInstance(); XPath xpath = xPathFactory.newXPath(); XPathExpression expr = xpath.compile("/world/country[1]/city[1]"); assertEquals("Tokyo", expr.evaluate(doc)); }
From source file:at.medevit.elexis.ehc.core.internal.EhcCoreServiceTest.java
@Test public void testGetDocument() throws Exception { EhcCoreServiceImpl service = new EhcCoreServiceImpl(); CdaCh cda = service.getCdaChDocument(patient, mandant); ByteArrayOutputStream output = new ByteArrayOutputStream(); CDAUtil.save(cda.getDocRoot().getClinicalDocument(), output); assertTrue(output.size() > 0); ByteArrayInputStream documentInput = new ByteArrayInputStream(output.toByteArray()); ClinicalDocument document = service.getDocument(documentInput); assertNotNull(document);/*from w w w. j ava 2 s . c o m*/ CdaCh<?> cdach = service.getCdaChDocument(document); assertNotNull(cdach); org.ehealth_connector.common.Patient readPatient = cdach.getPatient(); assertEquals("name", readPatient.getName().getFamilyName()); assertEquals("firstname", readPatient.getName().getGivenNames()); assertEquals(AdministrativeGender.FEMALE, readPatient.getAdministrativeGenderCode()); }
From source file:io.restassured.itest.java.FileDownloadITest.java
@Test public void loggingWithBinaryCharsetWorks() throws Exception { int expectedSize = IOUtils .toByteArray(getClass().getResourceAsStream("/powermock-easymock-junit-1.4.12.zip")).length; final StringWriter writer = new StringWriter(); final PrintStream captor = new PrintStream(new WriterOutputStream(writer), true); final InputStream inputStream = given() .config(RestAssuredConfig.config().logConfig(new LogConfig(captor, false))).expect().log().all() .when().get("http://powermock.googlecode.com/files/powermock-easymock-junit-1.4.12.zip") .asInputStream();//from ww w. j av a 2 s . co m final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); IOUtils.copy(inputStream, byteArrayOutputStream); IOUtils.closeQuietly(byteArrayOutputStream); IOUtils.closeQuietly(inputStream); assertThat(writer.toString(), not(isEmptyOrNullString())); assertThat(byteArrayOutputStream.size(), equalTo(expectedSize)); }
From source file:org.dcm4chee.storage.tar.TarContainerProvider.java
@Override public void writeEntriesTo(StorageContext context, List<ContainerEntry> entries, OutputStream out) throws IOException { TarArchiveOutputStream tar = new TarArchiveOutputStream(out); String checksumEntry = container.getChecksumEntry(); if (checksumEntry != null) { ByteArrayOutputStream bout = new ByteArrayOutputStream(); ContainerEntry.writeChecksumsTo(entries, bout); TarArchiveEntry tarEntry = new TarArchiveEntry(checksumEntry); tarEntry.setSize(bout.size()); tar.putArchiveEntry(tarEntry);//from w w w.j av a2s .co m tar.write(bout.toByteArray()); tar.closeArchiveEntry(); } for (ContainerEntry entry : entries) { Path path = entry.getSourcePath(); TarArchiveEntry tarEntry = new TarArchiveEntry(entry.getName()); tarEntry.setModTime(Files.getLastModifiedTime(path).toMillis()); tarEntry.setSize(Files.size(path)); tar.putArchiveEntry(tarEntry); Files.copy(path, tar); tar.closeArchiveEntry(); } tar.finish(); }
From source file:org.gradle.caching.internal.tasks.TarTaskOutputPacker.java
private void packMetadata(TaskOutputOriginWriter writeMetadata, TarOutputStream outputStream) throws IOException { TarEntry entry = new TarEntry(METADATA_PATH); entry.setMode(UnixStat.FILE_FLAG | UnixStat.DEFAULT_FILE_PERM); ByteArrayOutputStream baos = new ByteArrayOutputStream(); writeMetadata.execute(baos);//from w ww . j av a 2 s . c om entry.setSize(baos.size()); outputStream.putNextEntry(entry); try { outputStream.write(baos.toByteArray()); } finally { outputStream.closeEntry(); } }
From source file:org.apache.olingo.fit.V3ActionOverloading.java
private Response replaceServiceName(final Response response) { try {// w w w . ja v a2s .c om final String content = IOUtils.toString((InputStream) response.getEntity(), Constants.ENCODING) .replaceAll("Static\\.svc", "ActionOverloading.svc"); final Response.ResponseBuilder builder = Response.status(response.getStatus()); for (String headerName : response.getHeaders().keySet()) { for (Object headerValue : response.getHeaders().get(headerName)) { builder.header(headerName, headerValue); } } final InputStream toBeStreamedBack = IOUtils.toInputStream(content, Constants.ENCODING); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); IOUtils.copy(toBeStreamedBack, baos); IOUtils.closeQuietly(toBeStreamedBack); builder.header("Content-Length", baos.size()); builder.entity(new ByteArrayInputStream(baos.toByteArray())); return builder.build(); } catch (Exception e) { return response; } }
From source file:org.bigloupe.web.filemanager.command.UploadCommand.java
protected void checkUploadFile(String fileName, ByteArrayOutputStream os) throws ConnectorException { if (!_checkName(fileName)) { throw new ConnectorException("Invalid name"); }// w w w. j ava 2 s . c o m if (!_isUploadAllow(fileName)) { throw new ConnectorException("Not allowed file type"); } // check uploaded size int uploadSizeOctets = os.size(); checkUploadSizes(uploadSizeOctets); }
From source file:de.tudarmstadt.ukp.csniper.resbuild.BinaryCasWriter.java
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { OutputStream docOS = null;/*ww w.j a va 2 s . co m*/ try { w1.resume(); ByteArrayOutputStream bos = new ByteArrayOutputStream(500 * 1024); ObjectOutputStream oos = new ObjectOutputStream(bos); CASCompleteSerializer serializer = new CASCompleteSerializer(aJCas.getCasImpl()); oos.writeObject(serializer); closeQuietly(oos); size1 += bos.size(); w1.suspend(); w3.resume(); ByteArrayOutputStream bo2s = new ByteArrayOutputStream(500 * 1024); XmiCasSerializer.serialize(aJCas.getCas(), bo2s); size2 += bo2s.size(); w3.suspend(); // w2.resume(); // docOS = getOutputStream(aJCas, ".bin"); // docOS.write(bos.toByteArray()); // w2.suspend(); } catch (Exception e) { throw new AnalysisEngineProcessException(e); } finally { closeQuietly(docOS); } System.out.printf("bin: %s %d %n", w1, size1); System.out.printf("xmi: %s %d %n", w3, size2); }