JDK-8158786 : ZIP libraries could benefit from new intrinsic accessors to byte arrays
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.nio
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • Submitted: 2016-06-06
  • Updated: 2017-08-23
Related Reports
Blocks :  
Relates :  
Description
Currently only ByteBuffer access profits from bug JDK-8026049.
Please see this report as motivation to fix bug JDK-6914113

code example from ZipFileSystem:
-----------------------------
            // Now scan the block backwards for END header signature
            for (int i = buf.length - ENDHDR; i >= 0; i--) {
                if (buf[i+0] == (byte)'P'    &&
                    buf[i+1] == (byte)'K'    &&
                    buf[i+2] == (byte)'\005' &&
                    buf[i+3] == (byte)'\006' &&
-----------------------------
code examples from ZipUtils:
-----------------------------
    /**
     * Fetches unsigned 16-bit value from byte array at specified offset.
     * The bytes are assumed to be in Intel (little-endian) byte order.
     */
    public static final int get16(byte b[], int off) {
        return (b[off] & 0xff) | ((b[off + 1] & 0xff) << 8);
    }

    // fields access methods
    static final int CH(byte[] b, int n) {
        return b[n] & 0xff ;
    }

    static final int SH(byte[] b, int n) {
        return (b[n] & 0xff) | ((b[n + 1] & 0xff) << 8);
    }