X-Git-Url: http://source.jalview.org/gitweb/?p=jalviewjs.git;a=blobdiff_plain;f=site%2Fj2s%2Fjava%2Futil%2Fzip%2FGZIPInputStream.js;fp=site%2Fj2s%2Fjava%2Futil%2Fzip%2FGZIPInputStream.js;h=f21829cef130122538a10bde31315edc56202dd5;hp=5c2fc7da36d31bf19df7a8149d334dfc97206e04;hb=b9b7a352eee79b7764c3b09c9d19663075061d8c;hpb=7301a2415adab88038b291fc54caeeb3a5a47a44 diff --git a/site/j2s/java/util/zip/GZIPInputStream.js b/site/j2s/java/util/zip/GZIPInputStream.js index 5c2fc7d..f21829c 100644 --- a/site/j2s/java/util/zip/GZIPInputStream.js +++ b/site/j2s/java/util/zip/GZIPInputStream.js @@ -1,108 +1,108 @@ -Clazz.declarePackage ("java.util.zip"); -Clazz.load (["java.util.zip.InflaterInputStream", "$.CRC32"], "java.util.zip.GZIPInputStream", ["java.io.EOFException", "$.IOException", "java.util.zip.CheckedInputStream", "$.Inflater", "$.ZipException"], function () { -c$ = Clazz.decorateAsClass (function () { -this.crc = null; -this.eos = false; -this.$closed = false; -this.tmpbuf = null; -Clazz.instantialize (this, arguments); -}, java.util.zip, "GZIPInputStream", java.util.zip.InflaterInputStream); -Clazz.prepareFields (c$, function () { -this.crc = new java.util.zip.CRC32 (); -this.tmpbuf = Clazz.newByteArray (128, 0); -}); -Clazz.defineMethod (c$, "ensureOpen", - function () { -if (this.$closed) { -throw new java.io.IOException ("Stream closed"); -}}); -Clazz.makeConstructor (c$, -function ($in, size) { -Clazz.superConstructor (this, java.util.zip.GZIPInputStream, [$in, new java.util.zip.Inflater ().init (0, true), size]); -this.readHeader ($in); -}, "java.io.InputStream,~N"); -Clazz.overrideMethod (c$, "read", -function (buf, off, len) { -this.ensureOpen (); -if (this.eos) { -return -1; -}var n = this.readInf (buf, off, len); -if (n == -1) { -if (this.readTrailer ()) this.eos = true; - else return this.read (buf, off, len); -} else { -this.crc.update (buf, off, n); -}return n; -}, "~A,~N,~N"); -Clazz.defineMethod (c$, "close", -function () { -if (!this.$closed) { -Clazz.superCall (this, java.util.zip.GZIPInputStream, "close", []); -this.eos = true; -this.$closed = true; -}}); -Clazz.defineMethod (c$, "readHeader", - function (this_in) { -var $in = new java.util.zip.CheckedInputStream (this_in).set (this.crc); -this.crc.reset (); -if (this.readUShort ($in) != 35615) { -throw new java.util.zip.ZipException ("Not in GZIP format"); -}if (this.readUByte ($in) != 8) { -throw new java.util.zip.ZipException ("Unsupported compression method"); -}var flg = this.readUByte ($in); -this.skipBytes ($in, 6); -var n = 10; -if ((flg & 4) == 4) { -var m = this.readUShort ($in); -this.skipBytes ($in, m); -n += m + 2; -}if ((flg & 8) == 8) { -do { -n++; -} while (this.readUByte ($in) != 0); -}if ((flg & 16) == 16) { -do { -n++; -} while (this.readUByte ($in) != 0); -}if ((flg & 2) == 2) { -var v = this.crc.getValue () & 0xffff; -if (this.readUShort ($in) != v) { -throw new java.util.zip.ZipException ("Corrupt GZIP header"); -}n += 2; -}this.crc.reset (); -return n; -}, "java.io.InputStream"); -Clazz.defineMethod (c$, "readTrailer", - function () { -return true; -}); -Clazz.defineMethod (c$, "readUShort", - function ($in) { -var b = this.readUByte ($in); -return (this.readUByte ($in) << 8) | b; -}, "java.io.InputStream"); -Clazz.defineMethod (c$, "readUByte", - function ($in) { -var b = $in.readByteAsInt (); -if (b == -1) { -throw new java.io.EOFException (); -}if (b < -1 || b > 255) { -throw new java.io.IOException (this.$in.getClass ().getName () + ".read() returned value out of range -1..255: " + b); -}return b; -}, "java.io.InputStream"); -Clazz.defineMethod (c$, "skipBytes", - function ($in, n) { -while (n > 0) { -var len = $in.read (this.tmpbuf, 0, n < this.tmpbuf.length ? n : this.tmpbuf.length); -if (len == -1) { -throw new java.io.EOFException (); -}n -= len; -} -}, "java.io.InputStream,~N"); -Clazz.defineStatics (c$, -"GZIP_MAGIC", 0x8b1f, -"FHCRC", 2, -"FEXTRA", 4, -"FNAME", 8, -"FCOMMENT", 16); -}); +Clazz.declarePackage ("java.util.zip"); +Clazz.load (["java.util.zip.InflaterInputStream", "$.CRC32"], "java.util.zip.GZIPInputStream", ["java.io.EOFException", "$.IOException", "java.util.zip.CheckedInputStream", "$.Inflater", "$.ZipException"], function () { +c$ = Clazz.decorateAsClass (function () { +this.crc = null; +this.eos = false; +this.$closed = false; +this.tmpbuf = null; +Clazz.instantialize (this, arguments); +}, java.util.zip, "GZIPInputStream", java.util.zip.InflaterInputStream); +Clazz.prepareFields (c$, function () { +this.crc = new java.util.zip.CRC32 (); +this.tmpbuf = Clazz.newByteArray (128, 0); +}); +Clazz.defineMethod (c$, "ensureOpen", + function () { +if (this.$closed) { +throw new java.io.IOException ("Stream closed"); +}}); +Clazz.makeConstructor (c$, +function ($in, size) { +Clazz.superConstructor (this, java.util.zip.GZIPInputStream, [$in, new java.util.zip.Inflater ().init (0, true), size]); +this.readHeader ($in); +}, "java.io.InputStream,~N"); +Clazz.overrideMethod (c$, "read", +function (buf, off, len) { +this.ensureOpen (); +if (this.eos) { +return -1; +}var n = this.readInf (buf, off, len); +if (n == -1) { +if (this.readTrailer ()) this.eos = true; + else return this.read (buf, off, len); +} else { +this.crc.update (buf, off, n); +}return n; +}, "~A,~N,~N"); +Clazz.defineMethod (c$, "close", +function () { +if (!this.$closed) { +Clazz.superCall (this, java.util.zip.GZIPInputStream, "close", []); +this.eos = true; +this.$closed = true; +}}); +Clazz.defineMethod (c$, "readHeader", + function (this_in) { +var $in = new java.util.zip.CheckedInputStream (this_in).set (this.crc); +this.crc.reset (); +if (this.readUShort ($in) != 35615) { +throw new java.util.zip.ZipException ("Not in GZIP format"); +}if (this.readUByte ($in) != 8) { +throw new java.util.zip.ZipException ("Unsupported compression method"); +}var flg = this.readUByte ($in); +this.skipBytes ($in, 6); +var n = 10; +if ((flg & 4) == 4) { +var m = this.readUShort ($in); +this.skipBytes ($in, m); +n += m + 2; +}if ((flg & 8) == 8) { +do { +n++; +} while (this.readUByte ($in) != 0); +}if ((flg & 16) == 16) { +do { +n++; +} while (this.readUByte ($in) != 0); +}if ((flg & 2) == 2) { +var v = this.crc.getValue () & 0xffff; +if (this.readUShort ($in) != v) { +throw new java.util.zip.ZipException ("Corrupt GZIP header"); +}n += 2; +}this.crc.reset (); +return n; +}, "java.io.InputStream"); +Clazz.defineMethod (c$, "readTrailer", + function () { +return true; +}); +Clazz.defineMethod (c$, "readUShort", + function ($in) { +var b = this.readUByte ($in); +return (this.readUByte ($in) << 8) | b; +}, "java.io.InputStream"); +Clazz.defineMethod (c$, "readUByte", + function ($in) { +var b = $in.readByteAsInt (); +if (b == -1) { +throw new java.io.EOFException (); +}if (b < -1 || b > 255) { +throw new java.io.IOException (this.$in.getClass ().getName () + ".read() returned value out of range -1..255: " + b); +}return b; +}, "java.io.InputStream"); +Clazz.defineMethod (c$, "skipBytes", + function ($in, n) { +while (n > 0) { +var len = $in.read (this.tmpbuf, 0, n < this.tmpbuf.length ? n : this.tmpbuf.length); +if (len == -1) { +throw new java.io.EOFException (); +}n -= len; +} +}, "java.io.InputStream,~N"); +Clazz.defineStatics (c$, +"GZIP_MAGIC", 0x8b1f, +"FHCRC", 2, +"FEXTRA", 4, +"FNAME", 8, +"FCOMMENT", 16); +});