List of usage examples for org.apache.commons.io IOUtils toByteArray
public static byte[] toByteArray(String input) throws IOException
String
as a byte[]
using the default character encoding of the platform. From source file:com.haulmont.yarg.structure.impl.ReportTemplateBuilder.java
public ReportTemplateBuilder documentContent(InputStream documentContent) throws IOException { Preconditions.checkNotNull(documentContent, "\"documentContent\" parameter can not be null"); reportTemplate.documentContent = IOUtils.toByteArray(documentContent); return this; }
From source file:com.yoncabt.ebr.logger.fs.FileSystemReportLogger.java
@Override public byte[] getReportData(String uuid) throws IOException { //burada sktrma zellii akken kpatlm olabilir diye kontrol yapyorum File saveDir = new File(EBRConf.INSTANCE.getValue(EBRParams.REPORT_LOGGER_FSLOGGER_PATH, "/tmp")); File reportFile = new File(saveDir, uuid + ".gz"); if (reportFile.exists()) { try (FileInputStream fis = new FileInputStream(reportFile); GZIPInputStream gzis = new GZIPInputStream(fis);) { return IOUtils.toByteArray(gzis); }//from w w w . ja va2 s .com } else { reportFile = new File(saveDir, uuid); try (FileInputStream fis = new FileInputStream(reportFile)) { return IOUtils.toByteArray(fis); } } }
From source file:com.seer.datacruncher.spring.ValidateFilePopupController.java
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { String idSchema = request.getParameter("idSchema"); MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; MultipartFile multipartFile = multipartRequest.getFile("file"); String resMsg = ""; if (multipartFile.getOriginalFilename().endsWith(FileExtensionType.ZIP.getAbbreviation())) { // Case 1: When user upload a Zip file - All ZIP entries should be validate one by one ZipInputStream inStream = null; try {//from w w w. j av a 2 s .co m inStream = new ZipInputStream(multipartFile.getInputStream()); ZipEntry entry; while (!(isStreamClose(inStream)) && (entry = inStream.getNextEntry()) != null) { if (!entry.isDirectory()) { DatastreamsInput datastreamsInput = new DatastreamsInput(); datastreamsInput.setUploadedFileName(entry.getName()); byte[] byteInput = IOUtils.toByteArray(inStream); resMsg += datastreamsInput.datastreamsInput(new String(byteInput), Long.parseLong(idSchema), byteInput); } inStream.closeEntry(); } } catch (IOException ex) { resMsg = "Error occured during fetch records from ZIP file."; } finally { if (inStream != null) inStream.close(); } } else { // Case 1: When user upload a single file. In this cae just validate a single stream String datastream = new String(multipartFile.getBytes()); DatastreamsInput datastreamsInput = new DatastreamsInput(); datastreamsInput.setUploadedFileName(multipartFile.getOriginalFilename()); resMsg = datastreamsInput.datastreamsInput(datastream, Long.parseLong(idSchema), multipartFile.getBytes()); } String msg = resMsg.replaceAll("'", "\"").replaceAll("\\n", " "); msg = msg.trim(); response.setContentType("text/html"); ServletOutputStream out = null; out = response.getOutputStream(); out.write(("{success: " + true + " , message:'" + msg + "', " + "}").getBytes()); out.flush(); out.close(); return null; }
From source file:com.surevine.alfresco.audit.MultiReadHttpServletRequestTest.java
MultiReadHttpServletRequest testRequestWithSize(int size) throws Exception { MockHttpServletRequest mockRequest = new MockHttpServletRequest(); byte[] testData = getTestData(size); mockRequest.setContent(testData); // A request MultiReadHttpServletRequest request = new MultiReadHttpServletRequest(mockRequest); byte[] result1 = IOUtils.toByteArray(request.getInputStream()); assertTrue("result1 should equal the input array. [" + testData.length + ", " + result1.length + "]", Arrays.equals(testData, result1)); result1 = null;//from ww w . ja va 2 s .co m System.gc(); byte[] result2 = IOUtils.toByteArray(request.getInputStream()); assertTrue("result2 should equal the output array [" + testData.length + ", " + result2.length + "]", Arrays.equals(testData, result2)); testData = null; result2 = null; System.gc(); return request; }
From source file:at.gv.egiz.pdfas.web.client.test.BulkRequestThread.java
public BulkRequestThread(String name, URL endpoint, int queries, int bulkSize) throws IOException { threadName = name;/*w w w.j av a2 s.c o m*/ this.queries = queries; this.bulkSize = bulkSize; System.out.println("Creating " + threadName); signer = new RemotePDFSigner(endpoint, false); FileInputStream fis = new FileInputStream("/home/afitzek/simple.pdf"); inputData = IOUtils.toByteArray(fis); signParameters = new PDFASSignParameters(); signParameters.setConnector(Connector.BKU); signParameters.setPosition(null); signParameters.setProfile("SIGNATURBLOCK_DE"); }
From source file:com.haulmont.cuba.desktop.DesktopResources.java
protected byte[] getImageBytes(String name) { if (!name.startsWith("/") && !name.startsWith("classpath:")) name = "/" + name; boolean fromClassPath = false; if (name.startsWith(CLASSPATH_PREFIX)) { fromClassPath = true;//from ww w . j a va 2 s . c o m name = name.substring("classpath:".length()); } byte[] bytes = cache.get(name); if (bytes == null) { for (String root : roots) { String fullPath = fromClassPath ? name : root + name; InputStream stream = resources.getResourceAsStream(fullPath); if (stream != null) { try { bytes = IOUtils.toByteArray(stream); cache.put(name, bytes); break; } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(stream); } } } if (bytes == null) { log.warn("Resource " + name + " not found in " + roots); InputStream stream = resources .getResourceAsStream("/com/haulmont/cuba/desktop/res/nimbus/icons/attention.png"); if (stream != null) { try { bytes = IOUtils.toByteArray(stream); } catch (IOException e) { throw new RuntimeException(e); } finally { IOUtils.closeQuietly(stream); } } } } return bytes; }
From source file:my.custom.transformer.SourceModuleIntegrationTest.java
@Test public void test() throws IOException { SingleNodeProcessingChain chain = chain(application, "unZipStream", String.format("unZip")); final Resource resource = application.adminContext().getResource("classpath:testzipdata/single.zip"); final InputStream is = resource.getInputStream(); byte[] zipdata = IOUtils.toByteArray(is); //final Message<byte[]> message = MessageBuilder.withPayload(zipdata).build(); chain.sendPayload(zipdata);/*from ww w. j a v a 2 s . c o m*/ Object payload = chain.receivePayload(RECEIVE_TIMEOUT); System.out.println("payload: " + payload); //assertTrue(payload instanceof String); chain.destroy(); }
From source file:fr.chaffottem.bonita.connector.ftp.UploadFilesToDirectoryConnectorTest.java
@Test public void uploadAFile() throws Exception { final byte[] content = IOUtils.toByteArray(new FileInputStream(new File("./LICENSE"))); final Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put(FTPClientConnector.HOSTNAME, HOSTNAME); parameters.put(FTPClientConnector.PORT, getListeningPort()); parameters.put(FTPClientConnector.USER_NAME, USER_NAME); parameters.put(FTPClientConnector.PASSWORD, PASSWORD); parameters.put(UploadFilesToDirectoryConnector.DIRECTORY_PATH, "docs"); parameters.put(UploadFilesToDirectoryConnector.FILE_PATHS, Arrays.asList("./LICENSE")); final Map<String, Object> result = execute(parameters); final FileEntry file = getFile("c:\\share\\docs\\LICENSE"); assertThat(file).isNotNull();// w w w. j av a2s . c o m final byte[] fileContent = getFileContent(file); assertThat(fileContent).isEqualTo(content); assertThat(getStatusOfFile(result, "./LICENSE")).isTrue(); }
From source file:mycontrollers.MyCarController.java
public String submit() { // setCurrent(new Car()); // getFacade().create(getCurrent()); final String fileName = getFile().getName(); InputStream filecontent;/*w ww . j a v a 2 s. co m*/ byte[] bytes = null; try { filecontent = getFile().getInputStream(); int read = 0; // IOUtils.toByteArray(filecontent); // Apache commons IO. getCurrent().setImage(IOUtils.toByteArray(filecontent)); //while ((read = filecontent.read(current.getImage())) != -1) { // } getFacade().edit(getCurrent()); } catch (IOException ex) { Logger.getLogger(MyCarController.class.getName()).log(Level.SEVERE, null, ex); } setFilename(FilenameUtils.getBaseName(getFile().getSubmittedFileName())); setExtension(FilenameUtils.getExtension(getFile().getSubmittedFileName())); return "jsfUpload"; }
From source file:com.smartitengineering.cms.spi.impl.type.validator.XMLSchemaBasedTypeValidator.java
@Override public boolean isValid(InputStream documentStream) throws Exception { if (!documentStream.markSupported()) { throw new IOException("Only markeable input stream expected!"); }//from w w w .j a va 2 s . c om documentStream.mark(Integer.MAX_VALUE); InputStream cloneStream = new ByteArrayInputStream(IOUtils.toByteArray(documentStream)); documentStream.reset(); Document document = getDocumentForSource(cloneStream); return isValid(document); }