Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
lukehutch committed Feb 16, 2020
1 parent 91070f4 commit 6fd0dff
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
import nonapi.io.github.classgraph.fileslice.FileSlice;
import nonapi.io.github.classgraph.fileslice.Slice;
import nonapi.io.github.classgraph.recycler.Recycler;
import nonapi.io.github.classgraph.recycler.Resettable;
import nonapi.io.github.classgraph.scanspec.ScanSpec;
import nonapi.io.github.classgraph.utils.FastPathResolver;
import nonapi.io.github.classgraph.utils.FileUtils;
Expand Down Expand Up @@ -561,6 +562,40 @@ private PhysicalZipFile downloadJarFromURL(final String jarURL, final LogNode lo

// -------------------------------------------------------------------------------------------------------------

/**
* Wrapper class that allows an {@link Inflater} instance to be reset for reuse and then recycled by a
* {@link Recycler}.
*/
private static class RecyclableInflater implements Resettable, AutoCloseable {
/**
* Create a new {@link Inflater} instance with the "nowrap" option (which is needed for zipfile entries).
*/
private final Inflater inflater = new Inflater(/* nowrap = */ true);

/**
* Get the {@link Inflater} instance.
*
* @return the {@link Inflater} instance.
*/
public Inflater getInflater() {
return inflater;
}

/**
* Called when an {@link Inflater} instance is recycled, to reset the inflater so it can accept new input.
*/
@Override
public void reset() {
inflater.reset();
}

/** Called when the {@link Recycler} instance is closed, to destroy the {@link Inflater} instance. */
@Override
public void close() {
inflater.end();
}
}

/**
* Wrap an {@link InputStream} with an {@link InflaterInputStream}, recycling the {@link Inflater} instance.
*
Expand Down Expand Up @@ -709,6 +744,8 @@ public void close() {
};
}

// -------------------------------------------------------------------------------------------------------------

/**
* Read all the bytes in an {@link InputStream}, with spillover to a temporary file on disk if a maximum buffer
* size is exceeded.
Expand Down

This file was deleted.

0 comments on commit 6fd0dff

Please sign in to comment.