Search in sources :

Example 81 with SequenceInputStream

use of java.io.SequenceInputStream in project Bytecoder by mirkosertic.

the class GZIPInputStream method readTrailer.

/*
     * Reads GZIP member trailer and returns true if the eos
     * reached, false if there are more (concatenated gzip
     * data set)
     */
private boolean readTrailer() throws IOException {
    InputStream in = this.in;
    int n = inf.getRemaining();
    if (n > 0) {
        in = new SequenceInputStream(new ByteArrayInputStream(buf, len - n, n), new FilterInputStream(in) {

            public void close() throws IOException {
            }
        });
    }
    // Uses left-to-right evaluation order
    if ((readUInt(in) != crc.getValue()) || // rfc1952; ISIZE is the input size modulo 2^32
    (readUInt(in) != (inf.getBytesWritten() & 0xffffffffL)))
        throw new ZipException("Corrupt GZIP trailer");
    // try concatenated case
    if (this.in.available() > 0 || n > 26) {
        // this.trailer
        int m = 8;
        try {
            // next.header
            m += readHeader(in);
        } catch (IOException ze) {
            // ignore any malformed, do nothing
            return true;
        }
        inf.reset();
        if (n > m)
            inf.setInput(buf, len - n + m, n - m);
        return false;
    }
    return true;
}
Also used : FilterInputStream(java.io.FilterInputStream) SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FilterInputStream(java.io.FilterInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 82 with SequenceInputStream

use of java.io.SequenceInputStream in project jackrabbit-oak by apache.

the class OakBufferedIndexFile method flushBlob.

private void flushBlob() throws IOException {
    if (blobModified) {
        int n = (int) Math.min(blobSize, length - (long) index * blobSize);
        InputStream in = new ByteArrayInputStream(blob, 0, n);
        if (uniqueKey != null) {
            in = new SequenceInputStream(in, new ByteArrayInputStream(uniqueKey));
        }
        Blob b = blobFactory.createBlob(in);
        if (index < data.size()) {
            data.set(index, b);
        } else {
            checkState(index == data.size());
            data.add(b);
        }
        dataModified = true;
        blobModified = false;
    }
}
Also used : Blob(org.apache.jackrabbit.oak.api.Blob) SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream)

Example 83 with SequenceInputStream

use of java.io.SequenceInputStream in project jackrabbit-oak by apache.

the class OakStreamingIndexFile method pushData.

private void pushData(InputStream in) throws IOException {
    if (uniqueKey != null) {
        in = new SequenceInputStream(in, new ByteArrayInputStream(uniqueKey));
    }
    blob = blobFactory.createBlob(in);
    blobModified = true;
}
Also used : SequenceInputStream(java.io.SequenceInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 84 with SequenceInputStream

use of java.io.SequenceInputStream in project javacore by wang125631.

the class demo03 method merge02.

@SuppressWarnings("all")
public static // ʹ��SequenceInputStream�ϲ��ļ���
void merge02() throws IOException {
    // �ҵ�(�򴴽�)Ŀ���ļ�
    File inFile1 = new File("D:/demo01.java");
    File inFile2 = new File("D:/demo02.java");
    File outFile = new File("D:/demo03.java");
    // �������ݵ�����/���ͨ��
    FileInputStream fileInputStream1 = new FileInputStream(inFile1);
    FileInputStream fileInputStream2 = new FileInputStream(inFile2);
    FileOutputStream fileOutputStream = new FileOutputStream(outFile);
    // ��������������
    SequenceInputStream sequenceInputStream = new SequenceInputStream(fileInputStream1, fileInputStream2);
    byte[] buf = new byte[1024];
    int length = 0;
    while ((length = sequenceInputStream.read(buf)) != -1) {
        fileOutputStream.write(buf, 0, length);
    }
    sequenceInputStream.close();
    fileOutputStream.close();
}
Also used : SequenceInputStream(java.io.SequenceInputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 85 with SequenceInputStream

use of java.io.SequenceInputStream in project h2database by h2database.

the class Recover method readBlobMap.

/**
 * INTERNAL
 */
public static InputStream readBlobMap(Connection conn, long lobId, long precision) throws SQLException {
    final PreparedStatement prep = conn.prepareStatement("SELECT DATA FROM INFORMATION_SCHEMA.LOB_BLOCKS " + "WHERE LOB_ID = ? AND SEQ = ? AND ? > 0");
    prep.setLong(1, lobId);
    // precision is currently not really used,
    // it is just to improve readability of the script
    prep.setLong(3, precision);
    return new SequenceInputStream(new Enumeration<InputStream>() {

        private int seq;

        private byte[] data = fetch();

        private byte[] fetch() {
            try {
                prep.setInt(2, seq++);
                ResultSet rs = prep.executeQuery();
                if (rs.next()) {
                    return rs.getBytes(1);
                }
                return null;
            } catch (SQLException e) {
                throw DbException.convert(e);
            }
        }

        @Override
        public boolean hasMoreElements() {
            return data != null;
        }

        @Override
        public InputStream nextElement() {
            ByteArrayInputStream in = new ByteArrayInputStream(data);
            data = fetch();
            return in;
        }
    });
}
Also used : SequenceInputStream(java.io.SequenceInputStream) SQLException(java.sql.SQLException) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileStoreInputStream(org.h2.store.FileStoreInputStream) SequenceInputStream(java.io.SequenceInputStream) InputStream(java.io.InputStream) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

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