< prev index next >

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

Print this page




 155      * Converts Java time to DOS time, encoding any milliseconds lost
 156      * in the conversion into the upper half of the returned long.
 157      *
 158      * @param time milliseconds since epoch
 159      * @return DOS time with 2s remainder encoded into upper half
 160      */
 161     public static long javaToExtendedDosTime(long time) {
 162         if (time < 0) {
 163             return ZipEntry.DOSTIME_BEFORE_1980;
 164         }
 165         long dostime = javaToDosTime(time);
 166         return (dostime != ZipEntry.DOSTIME_BEFORE_1980)
 167                 ? dostime + ((time % 2000) << 32)
 168                 : ZipEntry.DOSTIME_BEFORE_1980;
 169     }
 170 
 171     /**
 172      * Fetches unsigned 16-bit value from byte array at specified offset.
 173      * The bytes are assumed to be in Intel (little-endian) byte order.
 174      */
 175     public static final int get16(byte b[], int off) {
 176         return (b[off] & 0xff) | ((b[off + 1] & 0xff) << 8);
 177     }
 178 
 179     /**
 180      * Fetches unsigned 32-bit value from byte array at specified offset.
 181      * The bytes are assumed to be in Intel (little-endian) byte order.
 182      */
 183     public static final long get32(byte b[], int off) {
 184         return (get16(b, off) | ((long)get16(b, off+2) << 16)) & 0xffffffffL;
 185     }
 186 
 187     /**
 188      * Fetches signed 64-bit value from byte array at specified offset.
 189      * The bytes are assumed to be in Intel (little-endian) byte order.
 190      */
 191     public static final long get64(byte b[], int off) {
 192         return get32(b, off) | (get32(b, off+4) << 32);
 193     }
 194 
 195     /**
 196      * Fetches signed 32-bit value from byte array at specified offset.
 197      * The bytes are assumed to be in Intel (little-endian) byte order.
 198      *
 199      */
 200     public static final int get32S(byte b[], int off) {
 201         return (get16(b, off) | (get16(b, off+2) << 16));
 202     }
 203 
 204     // fields access methods
 205     static final int CH(byte[] b, int n) {
 206         return b[n] & 0xff ;
 207     }
 208 
 209     static final int SH(byte[] b, int n) {
 210         return (b[n] & 0xff) | ((b[n + 1] & 0xff) << 8);
 211     }
 212 
 213     static final long LG(byte[] b, int n) {
 214         return ((SH(b, n)) | (SH(b, n + 2) << 16)) & 0xffffffffL;
 215     }
 216 
 217     static final long LL(byte[] b, int n) {
 218         return (LG(b, n)) | (LG(b, n + 4) << 32);
 219     }
 220 




 155      * Converts Java time to DOS time, encoding any milliseconds lost
 156      * in the conversion into the upper half of the returned long.
 157      *
 158      * @param time milliseconds since epoch
 159      * @return DOS time with 2s remainder encoded into upper half
 160      */
 161     public static long javaToExtendedDosTime(long time) {
 162         if (time < 0) {
 163             return ZipEntry.DOSTIME_BEFORE_1980;
 164         }
 165         long dostime = javaToDosTime(time);
 166         return (dostime != ZipEntry.DOSTIME_BEFORE_1980)
 167                 ? dostime + ((time % 2000) << 32)
 168                 : ZipEntry.DOSTIME_BEFORE_1980;
 169     }
 170 
 171     /**
 172      * Fetches unsigned 16-bit value from byte array at specified offset.
 173      * The bytes are assumed to be in Intel (little-endian) byte order.
 174      */
 175     public static final int get16(byte[] b, int off) {
 176         return (b[off] & 0xff) | ((b[off + 1] & 0xff) << 8);
 177     }
 178 
 179     /**
 180      * Fetches unsigned 32-bit value from byte array at specified offset.
 181      * The bytes are assumed to be in Intel (little-endian) byte order.
 182      */
 183     public static final long get32(byte[] b, int off) {
 184         return (get16(b, off) | ((long)get16(b, off+2) << 16)) & 0xffffffffL;
 185     }
 186 
 187     /**
 188      * Fetches signed 64-bit value from byte array at specified offset.
 189      * The bytes are assumed to be in Intel (little-endian) byte order.
 190      */
 191     public static final long get64(byte[] b, int off) {
 192         return get32(b, off) | (get32(b, off+4) << 32);
 193     }
 194 
 195     /**
 196      * Fetches signed 32-bit value from byte array at specified offset.
 197      * The bytes are assumed to be in Intel (little-endian) byte order.
 198      *
 199      */
 200     public static final int get32S(byte[] b, int off) {
 201         return (get16(b, off) | (get16(b, off+2) << 16));
 202     }
 203 
 204     // fields access methods
 205     static final int CH(byte[] b, int n) {
 206         return b[n] & 0xff ;
 207     }
 208 
 209     static final int SH(byte[] b, int n) {
 210         return (b[n] & 0xff) | ((b[n + 1] & 0xff) << 8);
 211     }
 212 
 213     static final long LG(byte[] b, int n) {
 214         return ((SH(b, n)) | (SH(b, n + 2) << 16)) & 0xffffffffL;
 215     }
 216 
 217     static final long LL(byte[] b, int n) {
 218         return (LG(b, n)) | (LG(b, n + 4) << 32);
 219     }
 220 


< prev index next >