Changeset 6843950 for core


Ignore:
Timestamp:
Jan 4, 2017 1:25:49 PM (4 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
57be0df
Parents:
134cbd4
Message:

DataHelper?: Release resources in finally block

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/data/DataHelper.java

    r134cbd4 r6843950  
    16781678    /**
    16791679     *  Decompress the GZIP compressed data (returning null on error).
    1680      *  @throws IOE if uncompressed is over 40 KB
     1680     *  @throws IOException if uncompressed is over 40 KB
    16811681     */
    16821682    public static byte[] decompress(byte orig[]) throws IOException {
     
    16861686    /**
    16871687     *  Decompress the GZIP compressed data (returning null on error).
    1688      *  @throws IOE if uncompressed is over 40 KB
     1688     *  @throws IOException if uncompressed is over 40 KB
    16891689     */
    16901690    public static byte[] decompress(byte orig[], int offset, int length) throws IOException {
     
    16991699        ByteCache cache = ByteCache.getInstance(8, MAX_UNCOMPRESSED);
    17001700        ByteArray outBuf = cache.acquire();
    1701         int written = 0;
    1702         while (true) {
    1703             int read = in.read(outBuf.getData(), written, MAX_UNCOMPRESSED-written);
    1704             if (read == -1)
    1705                 break;
    1706             written += read;
    1707             if (written >= MAX_UNCOMPRESSED) {
    1708                 if (in.available() > 0)
    1709                     throw new IOException("Uncompressed data larger than " + MAX_UNCOMPRESSED);
    1710                 break;
     1701        try {
     1702            int written = 0;
     1703            while (true) {
     1704                int read = in.read(outBuf.getData(), written, MAX_UNCOMPRESSED-written);
     1705                if (read == -1)
     1706                    break;
     1707                written += read;
     1708                if (written >= MAX_UNCOMPRESSED) {
     1709                    if (in.available() > 0)
     1710                        throw new IOException("Uncompressed data larger than " + MAX_UNCOMPRESSED);
     1711                    break;
     1712                }
    17111713            }
    1712         }
    1713         byte rv[] = new byte[written];
    1714         System.arraycopy(outBuf.getData(), 0, rv, 0, written);
    1715         cache.release(outBuf);
    1716         // TODO release in finally block
    1717         ReusableGZIPInputStream.release(in);
    1718         return rv;
     1714            byte rv[] = new byte[written];
     1715            System.arraycopy(outBuf.getData(), 0, rv, 0, written);
     1716            return rv;
     1717        } finally {
     1718            cache.release(outBuf);
     1719            ReusableGZIPInputStream.release(in);
     1720        }
    17191721    }
    17201722
Note: See TracChangeset for help on using the changeset viewer.