src/share/classes/com/sun/imageio/plugins/png/PNGImageWriter.java

Print this page
rev 9343 : 8033716: Fix raw and unchecked lint warnings in com.sun.imageio
Reviewed-by: darcy, prr, bae


 639                 }
 640             }
 641             cs.finish();
 642         }
 643     }
 644 
 645     private void write_tIME() throws IOException {
 646         if (metadata.tIME_present) {
 647             ChunkStream cs = new ChunkStream(PNGImageReader.tIME_TYPE, stream);
 648             cs.writeShort(metadata.tIME_year);
 649             cs.writeByte(metadata.tIME_month);
 650             cs.writeByte(metadata.tIME_day);
 651             cs.writeByte(metadata.tIME_hour);
 652             cs.writeByte(metadata.tIME_minute);
 653             cs.writeByte(metadata.tIME_second);
 654             cs.finish();
 655         }
 656     }
 657 
 658     private void write_tEXt() throws IOException {
 659         Iterator keywordIter = metadata.tEXt_keyword.iterator();
 660         Iterator textIter = metadata.tEXt_text.iterator();
 661 
 662         while (keywordIter.hasNext()) {
 663             ChunkStream cs = new ChunkStream(PNGImageReader.tEXt_TYPE, stream);
 664             String keyword = (String)keywordIter.next();
 665             cs.writeBytes(keyword);
 666             cs.writeByte(0);
 667 
 668             String text = (String)textIter.next();
 669             cs.writeBytes(text);
 670             cs.finish();
 671         }
 672     }
 673 
 674     private byte[] deflate(byte[] b) throws IOException {
 675         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 676         DeflaterOutputStream dos = new DeflaterOutputStream(baos);
 677         dos.write(b);
 678         dos.close();
 679         return baos.toByteArray();
 680     }
 681 
 682     private void write_iTXt() throws IOException {
 683         Iterator<String> keywordIter = metadata.iTXt_keyword.iterator();
 684         Iterator<Boolean> flagIter = metadata.iTXt_compressionFlag.iterator();
 685         Iterator<Integer> methodIter = metadata.iTXt_compressionMethod.iterator();
 686         Iterator<String> languageIter = metadata.iTXt_languageTag.iterator();
 687         Iterator<String> translatedKeywordIter =
 688             metadata.iTXt_translatedKeyword.iterator();


 700             cs.writeByte(methodIter.next().intValue());
 701 
 702             cs.writeBytes(languageIter.next());
 703             cs.writeByte(0);
 704 
 705 
 706             cs.write(translatedKeywordIter.next().getBytes("UTF8"));
 707             cs.writeByte(0);
 708 
 709             String text = textIter.next();
 710             if (compressed) {
 711                 cs.write(deflate(text.getBytes("UTF8")));
 712             } else {
 713                 cs.write(text.getBytes("UTF8"));
 714             }
 715             cs.finish();
 716         }
 717     }
 718 
 719     private void write_zTXt() throws IOException {
 720         Iterator keywordIter = metadata.zTXt_keyword.iterator();
 721         Iterator methodIter = metadata.zTXt_compressionMethod.iterator();
 722         Iterator textIter = metadata.zTXt_text.iterator();
 723 
 724         while (keywordIter.hasNext()) {
 725             ChunkStream cs = new ChunkStream(PNGImageReader.zTXt_TYPE, stream);
 726             String keyword = (String)keywordIter.next();
 727             cs.writeBytes(keyword);
 728             cs.writeByte(0);
 729 
 730             int compressionMethod = ((Integer)methodIter.next()).intValue();
 731             cs.writeByte(compressionMethod);
 732 
 733             String text = (String)textIter.next();
 734             cs.write(deflate(text.getBytes("ISO-8859-1")));
 735             cs.finish();
 736         }
 737     }
 738 
 739     private void writeUnknownChunks() throws IOException {
 740         Iterator typeIter = metadata.unknownChunkType.iterator();
 741         Iterator dataIter = metadata.unknownChunkData.iterator();
 742 
 743         while (typeIter.hasNext() && dataIter.hasNext()) {
 744             String type = (String)typeIter.next();
 745             ChunkStream cs = new ChunkStream(chunkType(type), stream);
 746             byte[] data = (byte[])dataIter.next();
 747             cs.write(data);
 748             cs.finish();
 749         }
 750     }
 751 
 752     private static int chunkType(String typeString) {
 753         char c0 = typeString.charAt(0);
 754         char c1 = typeString.charAt(1);
 755         char c2 = typeString.charAt(2);
 756         char c3 = typeString.charAt(3);
 757 
 758         int type = (c0 << 24) | (c1 << 16) | (c2 << 8) | c3;
 759         return type;
 760     }
 761 
 762     private void encodePass(ImageOutputStream os,
 763                             RenderedImage image,
 764                             int xOffset, int yOffset,
 765                             int xSkip, int ySkip) throws IOException {
 766         int minX = sourceXOffset;




 639                 }
 640             }
 641             cs.finish();
 642         }
 643     }
 644 
 645     private void write_tIME() throws IOException {
 646         if (metadata.tIME_present) {
 647             ChunkStream cs = new ChunkStream(PNGImageReader.tIME_TYPE, stream);
 648             cs.writeShort(metadata.tIME_year);
 649             cs.writeByte(metadata.tIME_month);
 650             cs.writeByte(metadata.tIME_day);
 651             cs.writeByte(metadata.tIME_hour);
 652             cs.writeByte(metadata.tIME_minute);
 653             cs.writeByte(metadata.tIME_second);
 654             cs.finish();
 655         }
 656     }
 657 
 658     private void write_tEXt() throws IOException {
 659         Iterator<String> keywordIter = metadata.tEXt_keyword.iterator();
 660         Iterator<String> textIter = metadata.tEXt_text.iterator();
 661 
 662         while (keywordIter.hasNext()) {
 663             ChunkStream cs = new ChunkStream(PNGImageReader.tEXt_TYPE, stream);
 664             String keyword = keywordIter.next();
 665             cs.writeBytes(keyword);
 666             cs.writeByte(0);
 667 
 668             String text = textIter.next();
 669             cs.writeBytes(text);
 670             cs.finish();
 671         }
 672     }
 673 
 674     private byte[] deflate(byte[] b) throws IOException {
 675         ByteArrayOutputStream baos = new ByteArrayOutputStream();
 676         DeflaterOutputStream dos = new DeflaterOutputStream(baos);
 677         dos.write(b);
 678         dos.close();
 679         return baos.toByteArray();
 680     }
 681 
 682     private void write_iTXt() throws IOException {
 683         Iterator<String> keywordIter = metadata.iTXt_keyword.iterator();
 684         Iterator<Boolean> flagIter = metadata.iTXt_compressionFlag.iterator();
 685         Iterator<Integer> methodIter = metadata.iTXt_compressionMethod.iterator();
 686         Iterator<String> languageIter = metadata.iTXt_languageTag.iterator();
 687         Iterator<String> translatedKeywordIter =
 688             metadata.iTXt_translatedKeyword.iterator();


 700             cs.writeByte(methodIter.next().intValue());
 701 
 702             cs.writeBytes(languageIter.next());
 703             cs.writeByte(0);
 704 
 705 
 706             cs.write(translatedKeywordIter.next().getBytes("UTF8"));
 707             cs.writeByte(0);
 708 
 709             String text = textIter.next();
 710             if (compressed) {
 711                 cs.write(deflate(text.getBytes("UTF8")));
 712             } else {
 713                 cs.write(text.getBytes("UTF8"));
 714             }
 715             cs.finish();
 716         }
 717     }
 718 
 719     private void write_zTXt() throws IOException {
 720         Iterator<String> keywordIter = metadata.zTXt_keyword.iterator();
 721         Iterator<Integer> methodIter = metadata.zTXt_compressionMethod.iterator();
 722         Iterator<String> textIter = metadata.zTXt_text.iterator();
 723 
 724         while (keywordIter.hasNext()) {
 725             ChunkStream cs = new ChunkStream(PNGImageReader.zTXt_TYPE, stream);
 726             String keyword = keywordIter.next();
 727             cs.writeBytes(keyword);
 728             cs.writeByte(0);
 729 
 730             int compressionMethod = (methodIter.next()).intValue();
 731             cs.writeByte(compressionMethod);
 732 
 733             String text = textIter.next();
 734             cs.write(deflate(text.getBytes("ISO-8859-1")));
 735             cs.finish();
 736         }
 737     }
 738 
 739     private void writeUnknownChunks() throws IOException {
 740         Iterator<String> typeIter = metadata.unknownChunkType.iterator();
 741         Iterator<byte[]> dataIter = metadata.unknownChunkData.iterator();
 742 
 743         while (typeIter.hasNext() && dataIter.hasNext()) {
 744             String type = typeIter.next();
 745             ChunkStream cs = new ChunkStream(chunkType(type), stream);
 746             byte[] data = dataIter.next();
 747             cs.write(data);
 748             cs.finish();
 749         }
 750     }
 751 
 752     private static int chunkType(String typeString) {
 753         char c0 = typeString.charAt(0);
 754         char c1 = typeString.charAt(1);
 755         char c2 = typeString.charAt(2);
 756         char c3 = typeString.charAt(3);
 757 
 758         int type = (c0 << 24) | (c1 << 16) | (c2 << 8) | c3;
 759         return type;
 760     }
 761 
 762     private void encodePass(ImageOutputStream os,
 763                             RenderedImage image,
 764                             int xOffset, int yOffset,
 765                             int xSkip, int ySkip) throws IOException {
 766         int minX = sourceXOffset;