List of usage examples for org.apache.commons.io IOUtils write
public static void write(StringBuffer data, OutputStream output) throws IOException
StringBuffer
to bytes on an OutputStream
using the default character encoding of the platform. From source file:com.smartitengineering.event.hub.common.EventJsonProvider.java
@Override public void writeTo(Event t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) throws IOException, WebApplicationException { if (isWriteable(type, genericType, annotations, mediaType)) { IOUtils.write(getJsonString(t), entityStream); }/*from w w w . j a v a2 s . c o m*/ }
From source file:com.linkedin.r2.filter.compression.stream.TestStreamingCompression.java
@Test public void testSnappyCompressor() throws IOException, InterruptedException, CompressionException, ExecutionException { StreamingCompressor compressor = new SnappyCompressor(_executor); final byte[] origin = new byte[BUF_SIZE]; Arrays.fill(origin, (byte) 'a'); ByteArrayOutputStream out = new ByteArrayOutputStream(); SnappyFramedOutputStream snappy = new SnappyFramedOutputStream(out); IOUtils.write(origin, snappy); snappy.close();/*from w w w . ja v a2 s .co m*/ byte[] compressed = out.toByteArray(); testCompress(compressor, origin, compressed); testDecompress(compressor, origin, compressed); testCompressThenDecompress(compressor, origin); }
From source file:com.mbrlabs.mundus.core.RuntimeExporter.java
public static void export(KryoManager kryoManager, ProjectContext projectContext, FileHandle destFolder, boolean prettyPrint) throws IOException { ProjectDTO dto = new ProjectDTO(); dto.setName(projectContext.name);// w w w. ja v a2 s . co m // models ModelDTO[] models = new ModelDTO[projectContext.models.size]; for (int i = 0; i < models.length; i++) { models[i] = convert(projectContext.models.get(i)); } dto.setModels(models); // terrains TerrainDTO[] terrains = new TerrainDTO[projectContext.terrains.size]; for (int i = 0; i < terrains.length; i++) { terrains[i] = convert(projectContext.terrains.get(i)); } dto.setTerrains(terrains); // textures TextureDTO[] textures = new TextureDTO[projectContext.textures.size]; for (int i = 0; i < textures.length; i++) { textures[i] = convert(projectContext.textures.get(i)); } dto.setTextures(textures); // scenes SceneDTO[] scenes = new SceneDTO[projectContext.scenes.size]; for (int i = 0; i < scenes.length; i++) { String name = projectContext.scenes.get(i); Scene scene = DescriptorConverter.convert(kryoManager.loadScene(projectContext, name), projectContext.terrains, projectContext.models); scenes[i] = convert(scene); } dto.setScenes(scenes); // write JSON if (!destFolder.exists()) { destFolder.mkdirs(); } FileHandle jsonOutput = Gdx.files.absolute(FilenameUtils.concat(destFolder.path(), "mundus")); OutputStream outputStream = new FileOutputStream(jsonOutput.path()); Json json = new Json(); json.setOutputType(JsonWriter.OutputType.json); String output = prettyPrint ? json.prettyPrint(dto) : json.toJson(dto); IOUtils.write(output, outputStream); // copy assets FileHandle assetOutput = Gdx.files.absolute(FilenameUtils.concat(destFolder.path(), "assets")); Gdx.files.absolute(FilenameUtils.concat(projectContext.path, "assets")).copyTo(assetOutput); }
From source file:net.mindengine.blogix.web.ClassMethodViewResolver.java
@Override public void resolveViewAndRender(Map<String, Object> routeModel, Object objectModel, String view, OutputStream outputStream) throws Exception { Method method = extractClassAndMethod(view).getRight(); if (!method.getReturnType().equals(String.class) && !method.getReturnType().equals(File.class)) { throw new IllegalArgumentException( "Cannot resolve view: '" + view + "'. Reason method does not return String or File type"); }// w w w . ja va 2 s.c om Object result = null; if (method.getParameterTypes().length == 0) { result = method.invoke(null, (Object[]) null); } else if (method.getParameterTypes().length == 1) { result = method.invoke(null, objectModel); } else throw new IllegalArgumentException( "Cannot resolve view: '" + view + "'. Reason is to many method arguments for view resolver"); if (result == null) { throw new IllegalArgumentException("Cannot resolve view: '" + view + "'. Reason method returned null"); } if (result instanceof String) { IOUtils.write((String) result, outputStream); } else if (result instanceof File) { IOUtils.copy(new FileInputStream((File) result), outputStream); } }
From source file:ch.cyberduck.core.spectra.SpectraUploadFeatureTest.java
@Test public void testUpload() throws Exception { final Host host = new Host(new SpectraProtocol() { @Override/* w ww .j a va2 s . c om*/ public Scheme getScheme() { return Scheme.http; } }, System.getProperties().getProperty("spectra.hostname"), Integer.valueOf(System.getProperties().getProperty("spectra.port")), new Credentials(System.getProperties().getProperty("spectra.user"), System.getProperties().getProperty("spectra.key"))); final SpectraSession session = new SpectraSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager()); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString()); final int length = 32770; final byte[] content = RandomUtils.nextBytes(length); final OutputStream out = local.getOutputStream(false); IOUtils.write(content, out); out.close(); final Path container = new Path("cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume)); final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final TransferStatus writeStatus = new TransferStatus().length(content.length); final SpectraBulkService bulk = new SpectraBulkService(session); bulk.pre(Transfer.Type.upload, Collections.singletonMap(test, writeStatus), new DisabledConnectionCallback()); final SpectraUploadFeature upload = new SpectraUploadFeature(new SpectraWriteFeature(session), new SpectraBulkService(session)); upload.upload(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), writeStatus, new DisabledConnectionCallback()); final byte[] buffer = new byte[content.length]; final TransferStatus readStatus = new TransferStatus().length(content.length); bulk.pre(Transfer.Type.download, Collections.singletonMap(test, readStatus), new DisabledConnectionCallback()); final InputStream in = new SpectraReadFeature(session).read(test, readStatus, new DisabledConnectionCallback()); IOUtils.readFully(in, buffer); in.close(); assertArrayEquals(content, buffer); new SpectraDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback()); local.delete(); session.close(); }
From source file:com.formkiq.web.config.TestDataController.java
/** * Provider Sample generic XML data with text/xml content type. * @param request {@link HttpServletRequest} * @param response {@link HttpServletResponse} * @throws IOException IOException// w w w. j ava2s . c o m */ @RequestMapping(value = "/testdata/sample-generic1.json", method = RequestMethod.GET) public void sampleGeneric3(final HttpServletRequest request, final HttpServletResponse response) throws IOException { byte[] data = Resources.getResourceAsBytes("/testdata/sample-generic.json"); response.setContentType("application/json"); response.setContentLengthLong(data.length); IOUtils.write(data, response.getOutputStream()); }
From source file:be.fedict.eid.applet.service.signer.asic.ASiCSignatureOutputStream.java
@Override public void close() throws IOException { super.close(); byte[] signatureData = toByteArray(); /*//from w ww . j a v a 2 s . co m * Copy the original ZIP content. */ ZipOutputStream zipOutputStream = new ZipOutputStream(this.targetOutputStream); ZipInputStream zipInputStream = new ZipInputStream(new FileInputStream(this.originalZipFile)); ZipEntry zipEntry; while (null != (zipEntry = zipInputStream.getNextEntry())) { if (!zipEntry.getName().equals(ASiCUtil.SIGNATURE_FILE)) { ZipEntry newZipEntry = new ZipEntry(zipEntry.getName()); zipOutputStream.putNextEntry(newZipEntry); LOG.debug("copying " + zipEntry.getName()); IOUtils.copy(zipInputStream, zipOutputStream); } } zipInputStream.close(); /* * Add the XML signature file to the ASiC package. */ zipEntry = new ZipEntry(ASiCUtil.SIGNATURE_FILE); LOG.debug("writing " + zipEntry.getName()); zipOutputStream.putNextEntry(zipEntry); IOUtils.write(signatureData, zipOutputStream); zipOutputStream.close(); }
From source file:com.moz.fiji.mapreduce.IntegrationTestFijiBulkLoad.java
private void writeTestResource(Path path, String testResource) throws Exception { final OutputStream ostream = mFS.create(path); IOUtils.write(TestingResources.get(testResource), ostream); ostream.close();/*from w ww.ja v a2s . c om*/ }
From source file:com.btkelly.gnag.tasks.CheckLocalTask.java
@TaskAction public void taskAction() { ViolationComment violationComment = buildViolationComment(); File gnagReportDirectory = new File(getProject().getProjectDir(), "/build/outputs/gnag/"); File gnagReportFile = new File(gnagReportDirectory, REPORT_FILE_NAME); try {// w ww . j av a 2 s .c om gnagReportDirectory.mkdirs(); FileOutputStream reportFileOutputStream = new FileOutputStream(gnagReportFile); final String htmlViolationReportPrefix = "<!DOCTYPE html>" + "<html>" + "<link rel=\"stylesheet\" href=\"github-markdown.css\">" + "<article class=\"markdown-body\">"; final String htmlViolationReportContent = Processor.process(violationComment.getCommentMessage()); final String htmlViolationReportSuffix = "</article></head>"; final String htmlViolationReport = htmlViolationReportPrefix + htmlViolationReportContent + htmlViolationReportSuffix; IOUtils.write(htmlViolationReport, reportFileOutputStream); reportFileOutputStream.close(); copyCssFile(gnagReportDirectory); } catch (IOException ignored) { Logger.logError("Error saving Gnag report"); } if (failBuildOnError() && violationComment.isFailBuild()) { String errorMessage = "Gnag check found failures, report at " + gnagReportFile.toURI(); Logger.logError(errorMessage); throw new GradleException(errorMessage); } else if (violationComment.isFailBuild()) { Logger.logError("Gnag check failed but configuration allows build success"); } }
From source file:Decoder.java
protected void saveBytes(String filename, byte[] b) throws Exception { try {//w ww . j ava2s . c o m FileOutputStream output = new FileOutputStream(new File(filename)); IOUtils.write(b, output); } catch (FileNotFoundException e) { throw new Exception(e); } catch (IOException e) { throw new Exception(e); } }