646 if (comment != null) { // zip file comment 647 writeShort(comment.length); 648 writeBytes(comment, 0, comment.length); 649 } else { 650 writeShort(0); 651 } 652 } 653 654 /* 655 * Returns the length of extra data without EXTT and ZIP64. 656 */ 657 private int getExtraLen(byte[] extra) { 658 if (extra == null) 659 return 0; 660 int skipped = 0; 661 int len = extra.length; 662 int off = 0; 663 while (off + 4 <= len) { 664 int tag = get16(extra, off); 665 int sz = get16(extra, off + 2); 666 if (tag == EXTID_EXTT || tag == EXTID_ZIP64) { 667 skipped += (sz + 4); 668 } 669 off += (sz + 4); 670 } 671 return len - skipped; 672 } 673 674 /* 675 * Writes extra data without EXTT and ZIP64. 676 * 677 * Extra timestamp and ZIP64 data is handled/output separately 678 * in writeLOC and writeCEN. 679 */ 680 private void writeExtra(byte[] extra) throws IOException { 681 if (extra != null) { 682 int len = extra.length; 683 int off = 0; 684 while (off + 4 <= len) { 685 int tag = get16(extra, off); 686 int sz = get16(extra, off + 2); 687 if (tag != EXTID_EXTT && tag != EXTID_ZIP64) { 688 writeBytes(extra, off, sz + 4); 689 } 690 off += (sz + 4); 691 } 692 } 693 } 694 695 /* 696 * Writes a 8-bit byte to the output stream. 697 */ 698 private void writeByte(int v) throws IOException { 699 OutputStream out = this.out; 700 out.write(v & 0xff); 701 written += 1; 702 } 703 704 /* 705 * Writes a 16-bit short to the output stream in little-endian byte order. 706 */ 707 private void writeShort(int v) throws IOException { 708 OutputStream out = this.out; 709 out.write((v >>> 0) & 0xff); 710 out.write((v >>> 8) & 0xff); 711 written += 2; | 646 if (comment != null) { // zip file comment 647 writeShort(comment.length); 648 writeBytes(comment, 0, comment.length); 649 } else { 650 writeShort(0); 651 } 652 } 653 654 /* 655 * Returns the length of extra data without EXTT and ZIP64. 656 */ 657 private int getExtraLen(byte[] extra) { 658 if (extra == null) 659 return 0; 660 int skipped = 0; 661 int len = extra.length; 662 int off = 0; 663 while (off + 4 <= len) { 664 int tag = get16(extra, off); 665 int sz = get16(extra, off + 2); 666 if (sz < 0 || (off + 4 + sz) > len) { 667 break; 668 } 669 if (tag == EXTID_EXTT || tag == EXTID_ZIP64) { 670 skipped += (sz + 4); 671 } 672 off += (sz + 4); 673 } 674 return len - skipped; 675 } 676 677 /* 678 * Writes extra data without EXTT and ZIP64. 679 * 680 * Extra timestamp and ZIP64 data is handled/output separately 681 * in writeLOC and writeCEN. 682 */ 683 private void writeExtra(byte[] extra) throws IOException { 684 if (extra != null) { 685 int len = extra.length; 686 int off = 0; 687 while (off + 4 <= len) { 688 int tag = get16(extra, off); 689 int sz = get16(extra, off + 2); 690 if (sz < 0 || (off + 4 + sz) > len) { 691 writeBytes(extra, off, len - off); 692 return; 693 } 694 if (tag != EXTID_EXTT && tag != EXTID_ZIP64) { 695 writeBytes(extra, off, sz + 4); 696 } 697 off += (sz + 4); 698 } 699 if (off < len) { 700 writeBytes(extra, off, len - off); 701 } 702 } 703 } 704 705 /* 706 * Writes a 8-bit byte to the output stream. 707 */ 708 private void writeByte(int v) throws IOException { 709 OutputStream out = this.out; 710 out.write(v & 0xff); 711 written += 1; 712 } 713 714 /* 715 * Writes a 16-bit short to the output stream in little-endian byte order. 716 */ 717 private void writeShort(int v) throws IOException { 718 OutputStream out = this.out; 719 out.write((v >>> 0) & 0xff); 720 out.write((v >>> 8) & 0xff); 721 written += 2; |