List of usage examples for java.io SequenceInputStream SequenceInputStream
public SequenceInputStream(Enumeration<? extends InputStream> e)
SequenceInputStream
by remembering the argument, which must be an Enumeration
that produces objects whose run-time type is InputStream
. From source file:com.github.benmanes.caffeine.cache.simulator.parser.TextTraceReader.java
private InputStream readFiles() throws IOException { List<InputStream> inputs = new ArrayList<>(filePaths.size()); for (String filePath : filePaths) { inputs.add(readFile(filePath));/* w w w. j a v a 2 s. c o m*/ } return new SequenceInputStream(Collections.enumeration(inputs)); }
From source file:org.trustedanalytics.resourceserver.data.InputStreamProvider.java
/** * Gets an InputStream for a path on HDFS. * * If given path is a directory, it will read files inside that dir and create * a SequenceInputStream from them, which emulates reading from directory just like from * a regular file. Notice that this method is not meant to read huge datasets * (as well as the whole project).// ww w. j a v a 2s.c o m * @param path * @return * @throws IOException */ public InputStream getInputStream(Path path) throws IOException { Objects.requireNonNull(path); if (fs.isFile(path)) { return fs.open(path); } else if (fs.isDirectory(path)) { FileStatus[] files = fs.listStatus(path); List<InputStream> paths = Arrays.stream(files).map(f -> { try { return fs.open(f.getPath()); } catch (IOException e) { LOGGER.log(Level.SEVERE, "Cannot read file " + f.getPath().toString(), e); return null; } }).filter(f -> f != null).collect(Collectors.toList()); return new SequenceInputStream(Collections.enumeration(paths)); } else { throw new IllegalArgumentException("Given path " + path.toString() + " is neither file nor directory"); } }
From source file:cloudlens.parser.FileReader.java
public static InputStream readFiles(String[] fileNames) throws IOException { try {/*from w w w .j a v a 2 s . c o m*/ final List<InputStream> streams = new ArrayList<>(); for (final String name : fileNames) { streams.add(new FileInputStream(new File(name))); } final Enumeration<InputStream> files = Collections.enumeration(streams); return new SequenceInputStream(files); } catch (final IOException e) { throw new CLException(e.getMessage()); } }
From source file:com.github.horrorho.inflatabledonkey.pcs.xfile.FileAssembler.java
static InputStream inputStream(List<Chunk> chunkData) throws UncheckedIOException { List<InputStream> inputStreams = chunkData.stream().map(Chunk::inputStream).collect(Collectors.toList()); Enumeration<InputStream> enumeration = Collections.enumeration(inputStreams); return new BufferedInputStream(new SequenceInputStream(enumeration), BUFFER_SIZE); }
From source file:com.autentia.wuija.i18n.SequenceResource.java
/** * Devuelve un nico <code>InputStream</code> que es el resultado de concatenar todos los <code>InputStream</code> * de los <code>Resource</code> que se pasaron en el constructor. * <p>/*from ww w . jav a 2 s . co m*/ * Para conseguir esto, esta clase utiliza la clase <code>java.io.SequenceInputStream</code> de Java. * * @return un nico <code>InputStream</code> que es el resultado de concatenar todos los <code>InputStream</code> de * los <code>Resource</code> que se pasaron en el constructor. */ public InputStream getInputStream() throws IOException { final List<InputStream> ins = new ArrayList<InputStream>(resources.length); for (Resource resource : resources) { ins.add(resource.getInputStream()); } final Enumeration<InputStream> streamsEnumeration = Collections.enumeration(ins); return new SequenceInputStream(streamsEnumeration); }
From source file:org.apache.axis2.format.ElementHelperTest.java
public void testGetTextAsStreamWithoutCaching() throws Exception { DataSource ds = new RandomDataSource(654321, 64, 128, 20000000); Vector<InputStream> v = new Vector<InputStream>(); v.add(new ByteArrayInputStream("<a>".getBytes("ascii"))); v.add(ds.getInputStream());//from www.j a v a2 s .c o m v.add(new ByteArrayInputStream("</a>".getBytes("ascii"))); XMLInputFactory factory = XMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE); XMLStreamReader reader = factory.createXMLStreamReader(new SequenceInputStream(v.elements()), "ascii"); OMElement element = new StAXOMBuilder(reader).getDocumentElement(); Reader in = ElementHelper.getTextAsStream(element, false); compareStreams(new InputStreamReader(ds.getInputStream(), "ascii"), in); }
From source file:com.metamolecular.pubcouch.pubchem.Snapshot.java
public InputStream getStream() throws IOException { return new SequenceInputStream(new StreamEnumerator(getFilenames())); }
From source file:main.java.miro.browser.util.DownloadHandler.java
public void sendDownload(List<RepositoryObject> objects) { List<InputStream> stream_collection = new ArrayList<InputStream>(); for (RepositoryObject obj : objects) { stream_collection.add(objectToStream(obj, false)); }//from w ww. j a va 2 s . c o m SequenceInputStream seq_stream = new SequenceInputStream( java.util.Collections.enumeration(stream_collection)); runDownloadService(seq_stream, "object_list"); }
From source file:org.openhab.io.multimedia.internal.tts.TTSServiceGoogleTTS.java
/** * Converts the given sentences into audio and returns it as an {@link InputStream}. * /*w w w .j a v a 2s.c o m*/ * @param sentences * The text to be converted to audio * @return {@link InputStream} with audio output * @throws IOException * Exception if the connection could not be established properly */ private InputStream getSpeechForText(List<String> sentences) throws IOException { Vector<InputStream> inputStreams = new Vector<InputStream>(sentences.size()); for (String sentence : sentences) { String encodedSentence = GoogleTTSTextProcessor.urlEncodeSentence(sentence); URL url = new URL(String.format(translateUrl, ttsLanguage, encodedSentence)); inputStreams.add(getInputStreamFromUrl(url)); } return new SequenceInputStream(inputStreams.elements()); }
From source file:org.apache.axiom.om.util.ElementHelperTest.java
public void testGetTextAsStreamWithoutCaching() throws Exception { XMLInputFactory factory = XMLInputFactory.newInstance(); if (factory.getClass().getName().equals("com.bea.xml.stream.MXParserFactory")) { // Skip the test on the StAX reference implementation because it // causes an out of memory error return;//from ww w.j a va 2 s . c om } DataSource ds = new RandomDataSource(654321, 64, 128, 20000000); Vector/*<InputStream>*/ v = new Vector/*<InputStream>*/(); v.add(new ByteArrayInputStream("<a>".getBytes("ascii"))); v.add(ds.getInputStream()); v.add(new ByteArrayInputStream("</a>".getBytes("ascii"))); factory.setProperty(XMLInputFactory.IS_COALESCING, Boolean.FALSE); XMLStreamReader reader = factory.createXMLStreamReader(new SequenceInputStream(v.elements()), "ascii"); OMElement element = new StAXOMBuilder(reader).getDocumentElement(); Reader in = ElementHelper.getTextAsStream(element, false); IOTestUtils.compareStreams(new InputStreamReader(ds.getInputStream(), "ascii"), in); }