use of java.io.SequenceInputStream in project hazelcast by hazelcast.
the class Config method loadFromStream.
/**
* Creates a Config from the provided stream (XML or YAML content).
*
* @param source the XML or YAML stream
* @param properties properties to use for variable resolution
* @return Config created from the stream
*/
public static Config loadFromStream(InputStream source, Properties properties) {
isNotNull(source, "(InputStream) source");
try {
ConfigStream cfgStream = new ConfigStream(source);
if (new MemberXmlConfigRootTagRecognizer().isRecognized(cfgStream)) {
cfgStream.reset();
InputStream stream = new SequenceInputStream(cfgStream, source);
return applyEnvAndSystemVariableOverrides(new XmlConfigBuilder(stream).setProperties(properties).build());
}
cfgStream.reset();
if (new MemberYamlConfigRootTagRecognizer().isRecognized(cfgStream)) {
cfgStream.reset();
InputStream stream = new SequenceInputStream(cfgStream, source);
return applyEnvAndSystemVariableOverrides(new YamlConfigBuilder(stream).setProperties(properties).build());
}
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
throw new IllegalArgumentException("interpretation error: the resource is neither valid XML nor valid YAML");
}
use of java.io.SequenceInputStream in project applause by applause.
the class ByteArrayOutputStream method toBufferedInputStream.
/**
* Gets the current contents of this byte stream as a Input Stream. The
* returned stream is backed by buffers of <code>this</code> stream,
* avoiding memory allocation and copy, thus saving space and time.<br>
*
* @return the current contents of this output stream.
* @see java.io.ByteArrayOutputStream#toByteArray()
* @see #reset()
* @since Commons IO 2.0
*/
private InputStream toBufferedInputStream() {
int remaining = count;
if (remaining == 0) {
return new ClosedInputStream();
}
List<ByteArrayInputStream> list = new ArrayList<ByteArrayInputStream>(buffers.size());
for (byte[] buf : buffers) {
int c = Math.min(buf.length, remaining);
list.add(new ByteArrayInputStream(buf, 0, c));
remaining -= c;
if (remaining == 0) {
break;
}
}
return new SequenceInputStream(Collections.enumeration(list));
}
use of java.io.SequenceInputStream in project zm-mailbox by Zimbra.
the class BufferStream method getInputStream.
public InputStream getInputStream() throws IOException {
sync();
if (size > maxSize)
throw new EOFException("data exceeds copy capacity");
if (buf == null)
return file == null ? new ByteArrayInputStream(new byte[0]) : new FileInputStream(file);
InputStream in = new ByteArrayInputStream(buf, 0, (int) Math.min(buf.length, size));
return file == null ? in : new SequenceInputStream(in, new FileInputStream(file));
}
use of java.io.SequenceInputStream in project j2objc by google.
the class OldSequenceInputStreamTest method createSequenceInputStreamWithGaps.
private SequenceInputStream createSequenceInputStreamWithGaps() {
Vector<InputStream> inputs = new Vector<>();
InputStream emptyInputStream = new Support_ASimpleInputStream(new byte[0]);
inputs.add(emptyInputStream);
inputs.add(simple1);
inputs.add(emptyInputStream);
inputs.add(simple2);
inputs.add(emptyInputStream);
return new SequenceInputStream(inputs.elements());
}
use of java.io.SequenceInputStream in project j2objc by google.
the class OldSequenceInputStreamTest method test_readStackOVerflow.
public void test_readStackOVerflow() throws Exception {
// 2^16 should be enough to overflow
Vector<InputStream> inputs = new Vector<>();
InputStream emptyInputStream = new Support_ASimpleInputStream(new byte[0]);
for (int i = 0; i < 32768; i++) {
inputs.add(emptyInputStream);
}
SequenceInputStream sequenceInputStream = new SequenceInputStream(inputs.elements());
assertEquals(-1, sequenceInputStream.read());
byte[] buf = new byte[10];
sequenceInputStream = new SequenceInputStream(inputs.elements());
assertEquals(-1, sequenceInputStream.read(buf, 0, 10));
}
Aggregations