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.allogy.mime.MimeGeneratingInputStream.java
public MimeGeneratingInputStream(Iterable<Header> headers, InputStream bodyInputStream) { Iterable<InputStream> inputStreamHeaders = Iterables.transform(headers, new Function<Header, InputStream>() { public InputStream apply(@Nullable Header s) { InputStream headerStream = new ByteArrayInputStream(s.toString().getBytes()); return new SequenceInputStream(headerStream, new ByteArrayInputStream(MimeUtilities.CRLFEnding.getBytes())); }//from ww w .j a v a 2 s. co m }); InputStream givenHeadersInputStream = new SequenceInputStream( new IteratorEnumeration(inputStreamHeaders.iterator())); InputStream headerInputStream = new SequenceInputStream(givenHeadersInputStream, new ByteArrayInputStream(MimeUtilities.CRLFEnding.getBytes())); innerInputStream = new SequenceInputStream(headerInputStream, bodyInputStream); }
From source file:org.fejoa.library.messages.PublicCryptoEnvelope.java
static public InputStream encrypt(InputStream data, boolean isRawData, KeyId keyId, PublicKey key, FejoaContext context) throws JSONException, CryptoException, IOException { JSONObject object = new JSONObject(); object.put(Envelope.PACK_TYPE_KEY, CRYPTO_TYPE); if (isRawData) object.put(Envelope.CONTAINS_DATA_KEY, 1); ICryptoInterface crypto = context.getCrypto(); CryptoSettings.Asymmetric pubKeySettings = context.getCryptoSettings().publicKey; CryptoSettings.Symmetric symSettings = context.getCryptoSettings().symmetric; byte[] iv = crypto.generateInitializationVector(symSettings.ivSize); String base64IV = DatatypeConverter.printBase64Binary(iv); SecretKey symKey = crypto.generateSymmetricKey(symSettings); // encrypt the key byte[] encSymKey = crypto.encryptAsymmetric(symKey.getEncoded(), key, pubKeySettings); String base64EncSymKey = DatatypeConverter.printBase64Binary(encSymKey); object.put(PUBLIC_KEY_ID_KEY, keyId.getKeyId()); object.put(PUBLIC_KEY_SETTINGS_KEY, JsonCryptoSettings.toJson(pubKeySettings)); object.put(IV_KEY, base64IV);/* w w w.j a v a 2 s .com*/ object.put(ENC_SYMMETRIC_KEY_KEY, base64EncSymKey); object.put(SYMMETRIC_SETTINGS_KEY, JsonCryptoSettings.toJson(symSettings)); String header = object.toString() + "\n"; InputStream crytoStream = crypto.encryptSymmetric(data, symKey, iv, symSettings); return new SequenceInputStream(new ByteArrayInputStream(header.getBytes()), crytoStream); }
From source file:com.apigee.sdk.apm.http.impl.client.cache.CombinedEntity.java
CombinedEntity(final Resource resource, final InputStream instream) throws IOException { super();/*from ww w . ja v a 2s . com*/ this.resource = resource; this.combinedStream = new SequenceInputStream(new ResourceStream(resource.getInputStream()), instream); }
From source file:org.openhab.voice.marytts.internal.MaryTTSAudioStream.java
/** * Constructs an instance with the passed properties * * @param inputStream The InputStream of this instance * @param audioFormat The AudioFormat of this instance * @throws IOException//www .j ava 2s .co m */ public MaryTTSAudioStream(AudioInputStream inputStream, AudioFormat audioFormat) throws IOException { rawAudio = IOUtils.toByteArray(inputStream); this.length = rawAudio.length + 36; this.inputStream = new SequenceInputStream(getWavHeaderInputStream(length), new ByteArrayInputStream(rawAudio)); this.audioFormat = audioFormat; }
From source file:com.allogy.io.BulkUpdateInputStream.java
private void moveToNextInnerInputStream() { currentInputStream = currentInputStreamIterator.next(); if (currentInputStreamIterator.hasNext()) currentInputStream = new SequenceInputStream(currentInputStream, IOUtils.toInputStream(",")); }
From source file:com.jonbanjo.cups.operations.HttpPoster.java
static OperationResult sendRequest(URL url, ByteBuffer ippBuf, InputStream documentStream, final AuthInfo auth) throws IOException { final OperationResult opResult = new OperationResult(); if (ippBuf == null) { return null; }//w w w .j a v a2 s . c om if (url == null) { return null; } DefaultHttpClient client = new DefaultHttpClient(); // will not work with older versions of CUPS! client.getParams().setParameter("http.protocol.version", HttpVersion.HTTP_1_1); client.getParams().setParameter("http.socket.timeout", SOCKET_TIMEOUT); client.getParams().setParameter("http.connection.timeout", CONNECTION_TIMEOUT); client.getParams().setParameter("http.protocol.content-charset", "UTF-8"); client.getParams().setParameter("http.method.response.buffer.warnlimit", new Integer(8092)); // probabaly not working with older CUPS versions client.getParams().setParameter("http.protocol.expect-continue", Boolean.valueOf(true)); HttpPost httpPost; try { httpPost = new HttpPost(url.toURI()); } catch (Exception e) { System.out.println(e.toString()); return null; } httpPost.getParams().setParameter("http.socket.timeout", SOCKET_TIMEOUT); byte[] bytes = new byte[ippBuf.limit()]; ippBuf.get(bytes); ByteArrayInputStream headerStream = new ByteArrayInputStream(bytes); // If we need to send a document, concatenate InputStreams InputStream inputStream = headerStream; if (documentStream != null) { inputStream = new SequenceInputStream(headerStream, documentStream); } // set length to -1 to advice the entity to read until EOF InputStreamEntity requestEntity = new InputStreamEntity(inputStream, -1); requestEntity.setContentType(IPP_MIME_TYPE); httpPost.setEntity(requestEntity); if (auth.reason == AuthInfo.AUTH_REQUESTED) { AuthHeader.makeAuthHeader(httpPost, auth); if (auth.reason == AuthInfo.AUTH_OK) { httpPost.addHeader(auth.getAuthHeader()); //httpPost.addHeader("Authorization", "Basic am9uOmpvbmJveQ=="); } } ResponseHandler<byte[]> handler = new ResponseHandler<byte[]>() { @Override public byte[] handleResponse(HttpResponse response) throws ClientProtocolException, IOException { if (response.getStatusLine().getStatusCode() == 401) { auth.setHttpHeader(response.getFirstHeader("WWW-Authenticate")); } else { auth.reason = AuthInfo.AUTH_OK; } HttpEntity entity = response.getEntity(); opResult.setHttResult(response.getStatusLine().toString()); if (entity != null) { return EntityUtils.toByteArray(entity); } else { return null; } } }; if (url.getProtocol().equals("https")) { Scheme scheme = JfSSLScheme.getScheme(); if (scheme == null) return null; client.getConnectionManager().getSchemeRegistry().register(scheme); } byte[] result = client.execute(httpPost, handler); //String test = new String(result); IppResponse ippResponse = new IppResponse(); opResult.setIppResult(ippResponse.getResponse(ByteBuffer.wrap(result))); opResult.setAuthInfo(auth); client.getConnectionManager().shutdown(); return opResult; }
From source file:uk.ac.ucl.excites.sapelli.shared.compression.BZIP2Compressor.java
@Override public InputStream getInputStream(InputStream source) throws IOException { return new BZip2CompressorInputStream( headerless ? new SequenceInputStream(new ByteArrayInputStream(BZIP2_HEADER), source) : source); }
From source file:pl.otros.logview.io.Utils.java
public static LoadingInfo openFileObject(FileObject fileObject, boolean tailing) throws Exception { LoadingInfo loadingInfo = new LoadingInfo(); loadingInfo.setFileObject(fileObject); loadingInfo.setFriendlyUrl(fileObject.getName().getFriendlyURI()); InputStream httpInputStream = fileObject.getContent().getInputStream(); byte[] buff = Utils.loadProbe(httpInputStream, 10000); loadingInfo.setGziped(checkIfIsGzipped(buff, buff.length)); ByteArrayInputStream bin = new ByteArrayInputStream(buff); SequenceInputStream sequenceInputStream = new SequenceInputStream(bin, httpInputStream); ObservableInputStreamImpl observableInputStreamImpl = new ObservableInputStreamImpl(sequenceInputStream); if (loadingInfo.isGziped()) { loadingInfo.setContentInputStream(new GZIPInputStream(observableInputStreamImpl)); loadingInfo.setInputStreamBufferedStart(ungzip(buff)); } else {/*from w w w.j av a2 s . c om*/ loadingInfo.setContentInputStream(observableInputStreamImpl); loadingInfo.setInputStreamBufferedStart(buff); } loadingInfo.setObserableInputStreamImpl(observableInputStreamImpl); loadingInfo.setTailing(tailing); return loadingInfo; }
From source file:pl.otros.logview.api.io.Utils.java
public static LoadingInfo openFileObject(FileObject fileObject, boolean tailing) throws Exception { LoadingInfo loadingInfo = new LoadingInfo(); loadingInfo.setFileObject(fileObject); loadingInfo.setFriendlyUrl(fileObject.getName().getFriendlyURI()); final FileContent content = fileObject.getContent(); InputStream httpInputStream = content.getInputStream(); byte[] buff = Utils.loadProbe(httpInputStream, 10000); loadingInfo.setGziped(checkIfIsGzipped(buff, buff.length)); ByteArrayInputStream bin = new ByteArrayInputStream(buff); SequenceInputStream sequenceInputStream = new SequenceInputStream(bin, httpInputStream); ObservableInputStreamImpl observableInputStreamImpl = new ObservableInputStreamImpl(sequenceInputStream); if (loadingInfo.isGziped()) { loadingInfo.setContentInputStream(new GZIPInputStream(observableInputStreamImpl)); loadingInfo.setInputStreamBufferedStart(ungzip(buff)); } else {/* w w w . j a va 2s . c om*/ loadingInfo.setContentInputStream(observableInputStreamImpl); loadingInfo.setInputStreamBufferedStart(buff); } loadingInfo.setObserableInputStreamImpl(observableInputStreamImpl); loadingInfo.setTailing(tailing); if (fileObject.getType().hasContent()) { loadingInfo.setLastFileSize(content.getSize()); } return loadingInfo; }
From source file:de.hybris.platform.addonsupport.setup.impl.DefaultSetupImpexAddOnService.java
protected InputStream getMergedInputStream(final Map<String, Object> macroParameters, final InputStream fileStream) { if (macroParameters != null && !macroParameters.isEmpty()) { final String header = buildMacroHeader(macroParameters); return new SequenceInputStream(IOUtils.toInputStream(header), fileStream); } else {/* w w w . j av a 2s . com*/ return fileStream; } }