Search in sources :

Example 56 with SequenceInputStream

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");
}
Also used : MemberYamlConfigRootTagRecognizer(com.hazelcast.internal.config.MemberYamlConfigRootTagRecognizer) SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MemberXmlConfigRootTagRecognizer(com.hazelcast.internal.config.MemberXmlConfigRootTagRecognizer) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 57 with SequenceInputStream

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));
}
Also used : SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ClosedInputStream(org.apache.commons.io.input.ClosedInputStream) ArrayList(java.util.ArrayList)

Example 58 with SequenceInputStream

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));
}
Also used : SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) EOFException(java.io.EOFException) FileInputStream(java.io.FileInputStream)

Example 59 with SequenceInputStream

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());
}
Also used : SequenceInputStream(java.io.SequenceInputStream) Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) Vector(java.util.Vector)

Example 60 with SequenceInputStream

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));
}
Also used : SequenceInputStream(java.io.SequenceInputStream) Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) Support_ASimpleInputStream(tests.support.Support_ASimpleInputStream) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) Vector(java.util.Vector)

Aggregations

SequenceInputStream (java.io.SequenceInputStream)123 InputStream (java.io.InputStream)78 ByteArrayInputStream (java.io.ByteArrayInputStream)67 IOException (java.io.IOException)47 ArrayList (java.util.ArrayList)32 FileInputStream (java.io.FileInputStream)24 BufferedInputStream (java.io.BufferedInputStream)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)12 Vector (java.util.Vector)10 Test (org.junit.Test)10 FileOutputStream (java.io.FileOutputStream)9 List (java.util.List)9 lombok.val (lombok.val)9 File (java.io.File)8 OutputStream (java.io.OutputStream)8 HashMap (java.util.HashMap)8 InputStreamReader (java.io.InputStreamReader)7 ByteBuffer (java.nio.ByteBuffer)6 Support_ASimpleInputStream (tests.support.Support_ASimpleInputStream)6 Reader (java.io.Reader)5