List of usage examples for java.io SequenceInputStream SequenceInputStream
public SequenceInputStream(InputStream s1, InputStream s2)
SequenceInputStream
by remembering the two arguments, which will be read in order, first s1
and then s2
, to provide the bytes to be read from this SequenceInputStream
. From source file:com.walmart.retailtech.move.innovationte.startersprestplus.listeners.LogWriterInterceptor.java
protected StringBuilder logInputStream(Message message, InputStream is, LoggingMessage buffer, String encoding, String ct) {//w w w . j a v a 2 s.c o m StringBuilder sb = new StringBuilder(); CachedOutputStream bos = new CachedOutputStream(); if (threshold > 0) { bos.setThreshold(threshold); } try { // use the appropriate input stream and restore it later InputStream bis = is instanceof DelegatingInputStream ? ((DelegatingInputStream) is).getInputStream() : is; //only copy up to the limit since that's all we need to log //we can stream the rest IOUtils.copyAtLeast(bis, bos, limit == -1 ? Integer.MAX_VALUE : limit); bos.flush(); bis = new SequenceInputStream(bos.getInputStream(), bis); // restore the delegating input stream or the input stream if (is instanceof DelegatingInputStream) { ((DelegatingInputStream) is).setInputStream(bis); } else { message.setContent(InputStream.class, bis); } if (bos.getTempFile() != null) { //large thing on disk... buffer.getMessage().append("\nMessage (saved to tmp file):\n"); buffer.getMessage().append("Filename: " + bos.getTempFile().getAbsolutePath() + "\n"); } if (bos.size() > limit && limit != -1) { buffer.getMessage().append("(message truncated to " + limit + " bytes)\n"); } writePayload(buffer.getPayload(), bos, encoding, ct); sb = buffer.getPayload(); bos.close(); } catch (Exception e) { throw new Fault(e); } return sb; }
From source file:org.jahia.modules.bootstrap.rules.BootstrapCompiler.java
private void compileBootstrap(JCRNodeWrapper siteOrModuleVersion, List<Resource> lessResources, String variables) throws IOException, LessException, RepositoryException { if (lessResources != null && !lessResources.isEmpty()) { File tmpLessFolder = new File(FileUtils.getTempDirectory(), "less-" + System.currentTimeMillis()); tmpLessFolder.mkdir();//from w w w.j av a 2 s . co m try { List<String> allContent = new ArrayList<String>(); for (Resource lessResource : lessResources) { File lessFile = new File(tmpLessFolder, lessResource.getFilename()); if (!lessFile.exists()) { InputStream inputStream; if (variables != null && VARIABLES_LESS.equals(lessResource.getFilename())) { inputStream = new SequenceInputStream(lessResource.getInputStream(), new ByteArrayInputStream(variables.getBytes())); } else { inputStream = lessResource.getInputStream(); } final FileOutputStream output = new FileOutputStream(lessFile); IOUtils.copy(inputStream, output); IOUtils.closeQuietly(inputStream); IOUtils.closeQuietly(output); } final FileInputStream input = new FileInputStream(lessFile); allContent.addAll(IOUtils.readLines(input)); IOUtils.closeQuietly(input); } String md5 = DigestUtils.md5Hex(StringUtils.join(allContent, '\n')); JCRNodeWrapper node = siteOrModuleVersion; for (String pathPart : StringUtils.split(CSS_FOLDER_PATH, '/')) { if (node.hasNode(pathPart)) { node = node.getNode(pathPart); } else { node = node.addNode(pathPart, "jnt:folder"); } } boolean compileCss = true; JCRNodeWrapper bootstrapCssNode; if (node.hasNode(BOOTSTRAP_CSS)) { bootstrapCssNode = node.getNode(BOOTSTRAP_CSS); String content = bootstrapCssNode.getFileContent().getText(); String timestamp = StringUtils.substringBetween(content, "/* sources hash ", " */"); if (timestamp != null && md5.equals(timestamp)) { compileCss = false; } } else { bootstrapCssNode = node.addNode(BOOTSTRAP_CSS, "jnt:file"); } if (compileCss) { File bootstrapCss = new File(tmpLessFolder, BOOTSTRAP_CSS); lessCompiler.compile(new File(tmpLessFolder, "bootstrap.less"), bootstrapCss); FileOutputStream f = new FileOutputStream(bootstrapCss, true); IOUtils.write("\n/* sources hash " + md5 + " */\n", f); IOUtils.closeQuietly(f); FileInputStream inputStream = new FileInputStream(bootstrapCss); bootstrapCssNode.getFileContent().uploadFile(inputStream, "text/css"); bootstrapCssNode.getSession().save(); IOUtils.closeQuietly(inputStream); } } catch (IOException e) { throw new RepositoryException(e); } catch (LessException e) { throw new RepositoryException(e); } finally { FileUtils.deleteQuietly(tmpLessFolder); } } }
From source file:org.sipfoundry.voicemail.mailbox.AbstractMailboxManager.java
protected void concatAudio(File newFile, File orig1, File orig2) throws Exception { String operation = "dunno"; AudioInputStream clip1 = null; AudioInputStream clip2 = null; AudioInputStream concatStream = null; try {//from w w w . j a va 2 s.c o m operation = "getting AudioInputStream from " + orig1.getPath(); clip1 = AudioSystem.getAudioInputStream(orig1); operation = "getting AudioInputStream from " + orig2.getPath(); clip2 = AudioSystem.getAudioInputStream(orig2); operation = "building SequnceInputStream"; concatStream = new AudioInputStream(new SequenceInputStream(clip1, clip2), clip1.getFormat(), clip1.getFrameLength() + clip2.getFrameLength()); operation = "writing SequnceInputStream to " + newFile.getPath(); AudioSystem.write(concatStream, AudioFileFormat.Type.WAVE, newFile); LOG.info("VmMessage::concatAudio created combined file " + newFile.getPath()); } catch (Exception e) { String trouble = "VmMessage::concatAudio Problem while " + operation; throw new Exception(trouble, e); } finally { IOUtils.closeQuietly(clip1); IOUtils.closeQuietly(clip2); IOUtils.closeQuietly(concatStream); } }
From source file:org.codehaus.plexus.archiver.zip.AbstractZipArchiver.java
private InputStream maybeSequence(byte[] header, int hdrBytes, InputStream in) { return hdrBytes > 0 ? new SequenceInputStream(new ByteArrayInputStream(header, 0, hdrBytes), in) : in; }
From source file:org.alfresco.repo.imap.ImapMessageTest.java
public void testMessageRenamedBetweenReads() throws Exception { // Get test message UID final Long uid = getMessageUid(folder, 1); // Get Message size final int count = getMessageSize(folder, uid); // Get first part // Split the message into 2 part using a non multiple of 4 - 103 is a prime number // as the BASE64Decoder may not throw the IOException // see MNT-12995 BODY body = getMessageBodyPart(folder, uid, 0, count - 103); // Rename message. The size of letter describing the node will change // These changes should be committed because it should be visible from client NodeRef contentNode = findNode(companyHomePathInStore + TEST_FILE); UserTransaction txn = transactionService.getUserTransaction(); txn.begin();/* w w w . j a v a2s . c o m*/ fileFolderService.rename(contentNode, "testtesttesttesttesttesttesttesttesttest"); txn.commit(); // Read second message part BODY bodyRest = getMessageBodyPart(folder, uid, count - 103, 103); // Creating and parsing message from 2 parts MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()), new SequenceInputStream(new BufferedInputStream(body.getByteArrayInputStream()), new BufferedInputStream(bodyRest.getByteArrayInputStream()))); // Reading first part - should be successful MimeMultipart content = (MimeMultipart) message.getContent(); assertNotNull(content.getBodyPart(0).getContent()); try { // Reading second part cause error content.getBodyPart(1).getContent(); fail("Should raise an IOException"); } catch (IOException e) { } }
From source file:com.photon.phresco.util.Utility.java
public static BufferedReader executeCommand(String commandString, String workingDirectory) { InputStream inputStream = null; InputStream errorStream = null; SequenceInputStream sequenceInputStream = null; BufferedReader bufferedReader = null; try {// www . java 2 s. co m Commandline cl = new Commandline(commandString); cl.setWorkingDirectory(workingDirectory); Process process = cl.execute(); inputStream = process.getInputStream(); errorStream = process.getErrorStream(); sequenceInputStream = new SequenceInputStream(inputStream, errorStream); bufferedReader = new BufferedReader(new InputStreamReader(sequenceInputStream)); } catch (CommandLineException e) { //FIXME : log exception e.printStackTrace(); } return bufferedReader; }
From source file:org.alfresco.repo.imap.ImapMessageTest.java
public void dontTestMessageCache() throws Exception { // Create messages NodeRef contentNode = findNode(companyHomePathInStore + TEST_FILE); UserTransaction txn = transactionService.getUserTransaction(); txn.begin();// ww w.j av a 2 s.c o m // Create messages more than cache capacity for (int i = 0; i < 51; i++) { FileInfo fi = fileFolderService.create(nodeService.getParentAssocs(contentNode).get(0).getParentRef(), "test" + i, ContentModel.TYPE_CONTENT); ContentWriter writer = fileFolderService.getWriter(fi.getNodeRef()); writer.putContent("test"); } txn.commit(); // Reload folder folder.close(false); folder = (IMAPFolder) store.getFolder(TEST_FOLDER); folder.open(Folder.READ_ONLY); // Read all messages for (int i = 1; i < 51; i++) { // Get test message UID final Long uid = getMessageUid(folder, i); // Get Message size final int count = getMessageSize(folder, uid); // Get first part BODY body = getMessageBodyPart(folder, uid, 0, count - 100); // Read second message part BODY bodyRest = getMessageBodyPart(folder, uid, count - 100, 100); // Creating and parsing message from 2 parts MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()), new SequenceInputStream(new BufferedInputStream(body.getByteArrayInputStream()), new BufferedInputStream(bodyRest.getByteArrayInputStream()))); // Reading first part - should be successful MimeMultipart content = (MimeMultipart) message.getContent(); assertNotNull(content.getBodyPart(0).getContent()); assertNotNull(content.getBodyPart(1).getContent()); } }
From source file:org.cloudifysource.dsl.internal.DSLReader.java
@SuppressWarnings("deprecation") private Object evaluateGroovyScript(final GroovyShell gs) throws DSLValidationException { // Evaluate class using a FileReader, as the *-service files create a // class with an illegal name Object result = null;//from w ww. ja v a2 s . co m if (this.dslContents == null) { //FileReader reader = null; SequenceInputStream sis = null; try { final FileInputStream fis = new FileInputStream(dslFile); final ByteArrayInputStream bis = new ByteArrayInputStream(GROOVY_SERVICE_PREFIX.getBytes()); sis = new SequenceInputStream(bis, fis); //reader = new FileReader(dslFile); // using a deprecated method here as we do not have a multireader in the dependencies // and not really worth another jar just for this. result = gs.evaluate(sis, "dslEntity"); } catch (final IOException e) { throw new IllegalStateException("The file " + dslFile + " could not be read", e); } catch (final MissingMethodException e) { throw new IllegalArgumentException("Could not resolve DSL entry with name: " + e.getMethod(), e); } catch (final MissingPropertyException e) { throw new IllegalArgumentException("Could not resolve DSL entry with name: " + e.getProperty(), e); } catch (final DSLValidationRuntimeException e) { throw e.getDSLValidationException(); } finally { if (sis != null) { try { sis.close(); } catch (final IOException e) { // ignore } } } } else { try { result = gs.evaluate(this.dslContents, "dslEntity"); } catch (final CompilationFailedException e) { throw new IllegalArgumentException("The file " + dslFile + " could not be compiled", e); } } return result; }
From source file:org.zaizi.alfresco.redlink.service.redlink.RedLinkEnhancerServiceImpl.java
/** * @param nodeRef/* w w w . ja v a 2 s. c o m*/ * @return * @throws IOException */ private Enhancements getEnhancements(final NodeRef nodeRef) throws IOException { // read content ContentReader reader = getTextContentReader(nodeRef); String name = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); String title = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_TITLE); String description = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_DESCRIPTION); String metadataInfo = name + " " + title + " " + description; InputStream metadataStream = null; try { metadataStream = new ByteArrayInputStream(metadataInfo.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { logger.error("Error when building inputstream from metadata to be enhanced: " + e.getMessage(), e); } // Get enhancements InputStream inputStream = null; if (reader != null) { inputStream = new SequenceInputStream(metadataStream, reader.getContentInputStream()); // reader.getcon } else { inputStream = metadataStream; } AnalysisRequest request = AnalysisRequest.builder().setAnalysis(redlinkAnalysisName).setContent(inputStream) .setOutputFormat(OutputFormat.TURTLE).build(); Enhancements enhancements = redlinkEnhancer.enhance(request); return enhancements; }
From source file:org.alfresco.repo.imap.ImapMessageTest.java
public void testUnmodifiedMessage() throws Exception { // Get test message UID final Long uid = getMessageUid(folder, 1); // Get Message size final int count = getMessageSize(folder, uid); // Make multiple message reading for (int i = 0; i < 100; i++) { // Get random offset int n = (int) ((int) 100 * Math.random()); // Get first part BODY body = getMessageBodyPart(folder, uid, 0, count - n); // Read second message part BODY bodyRest = getMessageBodyPart(folder, uid, count - n, n); // Creating and parsing message from 2 parts MimeMessage message = new MimeMessage(Session.getDefaultInstance(new Properties()), new SequenceInputStream(new BufferedInputStream(body.getByteArrayInputStream()), new BufferedInputStream(bodyRest.getByteArrayInputStream()))); MimeMultipart content = (MimeMultipart) message.getContent(); // Reading first part - should be successful assertNotNull(content.getBodyPart(0).getContent()); // Reading second part - should be successful assertNotNull(content.getBodyPart(1).getContent()); }/*from w w w. j av a 2 s.c om*/ }