1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.imaging.formats.png.chunks;
18
19 import java.nio.charset.StandardCharsets;
20 import java.util.logging.Level;
21 import java.util.logging.Logger;
22
23 import org.apache.commons.imaging.ImagingException;
24 import org.apache.commons.imaging.common.BinaryFunctions;
25 import org.apache.commons.imaging.formats.png.AbstractPngText;
26
27 public final class PngChunkText extends AbstractPngTextChunk {
28
29 private static final Logger LOGGER = Logger.getLogger(PngChunkText.class.getName());
30
31 private final String keyword;
32 private final String text;
33
34
35
36
37
38
39
40
41
42
43
44 public PngChunkText(final int length, final int chunkType, final int crc, final byte[] bytes) throws ImagingException {
45 super(length, chunkType, crc, bytes);
46 final int index = BinaryFunctions.indexOf0(bytes, "PNG tEXt chunk keyword is not terminated.");
47 keyword = new String(bytes, 0, index, StandardCharsets.ISO_8859_1);
48 final int textLength = bytes.length - (index + 1);
49 text = new String(bytes, index + 1, textLength, StandardCharsets.ISO_8859_1);
50 if (LOGGER.isLoggable(Level.FINEST)) {
51 LOGGER.finest("Keyword: " + keyword);
52 LOGGER.finest("Text: " + text);
53 }
54 }
55
56 @Override
57 public AbstractPngText getContents() {
58 return new AbstractPngText.Text(keyword, text);
59 }
60
61
62
63
64 @Override
65 public String getKeyword() {
66 return keyword;
67 }
68
69
70
71
72 @Override
73 public String getText() {
74 return text;
75 }
76
77 }