Skip to content

Support reading GZIPInputStream log files #74

Closed
@hbswn

Description

@hbswn

I often have quite big log files, so I tested, whether I could read them as gzip'd files.

A small modification of DataReaderFactory.getDataReader() does the job :-)

public DataReader getDataReader(InputStream inStream) throws IOException {
    BufferedInputStream in = new BufferedInputStream(inStream, FOUR_KB);
    if (in.markSupported()) {
        if (readUShortAndReset(in) == GZIPInputStream.GZIP_MAGIC) {
            in = new BufferedInputStream(new GZIPInputStream(in, FOUR_KB), FOUR_KB);
        }
    }

private static int readUShortAndReset(final InputStream in) throws IOException {
    in.mark(2);
    final int b = in.read();
    final int result = ((int)in.read() << 8) | b;
    in.reset();
    return result;
}

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions