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 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 public PngChunkText(final int length, final int chunkType, final int crc, final byte[] bytes) throws ImagingException {
35 super(length, chunkType, crc, bytes);
36 final int index = BinaryFunctions.findNull(bytes, "PNG tEXt chunk keyword is not terminated.");
37 keyword = new String(bytes, 0, index, StandardCharsets.ISO_8859_1);
38 final int textLength = bytes.length - (index + 1);
39 text = new String(bytes, index + 1, textLength, StandardCharsets.ISO_8859_1);
40 if (LOGGER.isLoggable(Level.FINEST)) {
41 LOGGER.finest("Keyword: " + keyword);
42 LOGGER.finest("Text: " + text);
43 }
44 }
45
46 @Override
47 public AbstractPngText getContents() {
48 return new AbstractPngText.Text(keyword, text);
49 }
50
51
52
53
54 @Override
55 public String getKeyword() {
56 return keyword;
57 }
58
59
60
61
62 @Override
63 public String getText() {
64 return text;
65 }
66
67 }