src/java.base/share/classes/java/util/zip/ZipUtils.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 23,32 **** --- 23,34 ---- * questions. */ package java.util.zip; + import java.nio.Buffer; + import java.nio.ByteBuffer; import java.nio.file.attribute.FileTime; import java.security.AccessController; import java.security.PrivilegedAction; import java.time.DateTimeException; import java.time.Instant;
*** 35,52 **** --- 37,60 ---- import java.util.Date; import java.util.concurrent.TimeUnit; import static java.util.zip.ZipConstants.ENDHDR; + import jdk.internal.misc.Unsafe; + import sun.nio.ch.DirectBuffer; + class ZipUtils { // used to adjust values between Windows and java epoch private static final long WINDOWS_EPOCH_IN_MICROSECONDS = -11644473600000000L; // used to indicate the corresponding windows time is not available public static final long WINDOWS_TIME_NOT_AVAILABLE = Long.MIN_VALUE; + // static final ByteBuffer defaultBuf = ByteBuffer.allocateDirect(0); + static final ByteBuffer defaultBuf = ByteBuffer.allocate(0); + /** * Converts Windows time (in microseconds, UTC/GMT) time to FileTime. */ public static final FileTime winTimeToFileTime(long wtime) { return FileTime.from(wtime / 10 + WINDOWS_EPOCH_IN_MICROSECONDS,
*** 279,284 **** --- 287,305 ---- } else { PrivilegedAction<Void> pa = () -> { System.loadLibrary("zip"); return null; }; AccessController.doPrivileged(pa); } } + + private static final Unsafe unsafe = Unsafe.getUnsafe(); + + private static final long byteBufferArrayOffset = unsafe.objectFieldOffset(ByteBuffer.class, "hb"); + private static final long byteBufferOffsetOffset = unsafe.objectFieldOffset(ByteBuffer.class, "offset"); + + static byte[] getBufferArray(ByteBuffer byteBuffer) { + return (byte[]) unsafe.getObject(byteBuffer, byteBufferArrayOffset); + } + + static int getBufferOffset(ByteBuffer byteBuffer) { + return unsafe.getInt(byteBuffer, byteBufferOffsetOffset); + } }