Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support reading GZIPInputStream log files #74

Closed
hbswn opened this issue Aug 17, 2013 · 7 comments
Closed

Support reading GZIPInputStream log files #74

hbswn opened this issue Aug 17, 2013 · 7 comments
Assignees
Milestone

Comments

@hbswn
Copy link

hbswn commented Aug 17, 2013

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;
}
@hbswn
Copy link
Author

hbswn commented Aug 17, 2013

Also works over HTTP, which is very convenient, if you have Apache transparently gzip the files.

@chewiebug
Copy link
Owner

Hi Hans,

This looks like an interesting feature! Do you know that you could submit a patch as a pull request? Alternatively you can tell me the email address that is associated to your github account so I can author a commit in your name (write it here or send me an email to gcviewer@gmx.ch).

Please let me know how you would like to proceed.

Regards, Jörg

@hbswn
Copy link
Author

hbswn commented Aug 21, 2013

New code is on https://github.com/hbswn/GCViewer

and I've sent a Pull Request ... but I do not see it.

@chewiebug
Copy link
Owner

Thank you for the pull request! I'll probably pull it in within the next two weeks.

I am not sure if you can see it in your repository. It appears in my list of pull requests and as another issue.

...yes, a testcase for gzip'd data would be nice!

Regards, Jörg

@hbswn
Copy link
Author

hbswn commented Sep 1, 2013

I've added:
TestDataReaderFactory.testReadUShortAndReset()
TestDataReaderFactory.testGetDataReaderJDK6GZipped()

... and made DataReaderFactory.readUShortAndReset() protected to make it accessible for the test class.

Tests run: 177, Failures: 0, Errors: 0, Skipped: 0

@chewiebug
Copy link
Owner

cool, thank you!

I'll be on vacation for a week and merge your pull request, when I'm back.

Regards, Jörg

Am 01.09.2013 11:59, schrieb Hans Bausewein:

I've added:
TestDataReaderFactory.testReadUShortAndReset()
TestDataReaderFactory.testGetDataReaderJDK6GZipped()

... and made DataReaderFactory.readUShortAndReset() protected to make
it accessible for the test class.

Tests run: 177, Failures: 0, Errors: 0, Skipped: 0


Reply to this email directly or view it on GitHub
#74 (comment).

@ghost ghost assigned chewiebug Sep 8, 2013
@chewiebug
Copy link
Owner

Hi Hans,

I have integrated your pull request (#75) and now close this issue. If it shouldn't work for you, please reopen it.

Regards, Jörg

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants