@Nullable protected String getByteLengthDescription(final int tagType) { byte[] bytes = _directory.getByteArray(tagType); if (bytes == null) return null; return String.format("(%d byte%s)", bytes.length, bytes.length == 1 ? "" : "s"); }
@Nullable public String getString(int tagType, String charset) { byte[] bytes = getByteArray(tagType); if (bytes==null) return null; try { return new String(bytes, charset); } catch (UnsupportedEncodingException e) { return null; } }
@Nullable protected String getStringFromBytes(int tag, Charset cs) { byte[] values = _directory.getByteArray(tag); if (values == null) return null; try { return new String(values, cs.name()).trim(); } catch (UnsupportedEncodingException e) { return null; } }
/** The Windows specific tags uses plain Unicode. */ @Nullable private String getUnicodeDescription(int tag) { byte[] bytes = _directory.getByteArray(tag); if (bytes == null) return null; try { // Decode the unicode string and trim the unicode zero "\0" from the end. return new String(bytes, "UTF-16LE").trim(); } catch (UnsupportedEncodingException ex) { return null; } }
@Nullable protected String get7BitStringFromBytes(final int tagType) { final byte[] bytes = _directory.getByteArray(tagType); if (bytes == null) return null; int length = bytes.length; for (int index = 0; index < bytes.length; index++) { int i = bytes[index] & 0xFF; if (i == 0 || i > 0x7F) { length = index; break; } } return new String(bytes, 0, length); }
@Nullable protected String getEncodedTextDescription(int tagType) byte[] commentBytes = _directory.getByteArray(tagType); if (commentBytes == null) return null;
@Nullable public String getCfaPattern2Description() { byte[] values = _directory.getByteArray(TAG_CFA_PATTERN_2); if (values == null) return null; int[] repeatPattern = _directory.getIntArray(TAG_CFA_REPEAT_PATTERN_DIM); if (repeatPattern == null) return String.format("Repeat Pattern not found for CFAPattern (%s)", super.getDescription(TAG_CFA_PATTERN_2)); if (repeatPattern.length == 2 && values.length == (repeatPattern[0] * repeatPattern[1])) { int[] intpattern = new int[2 + values.length]; intpattern[0] = repeatPattern[0]; intpattern[1] = repeatPattern[1]; for (int i = 0; i < values.length; i++) intpattern[i + 2] = values[i] & 0xFF; // convert the values[i] byte to unsigned return formatCFAPattern(intpattern); } return String.format("Unknown Pattern (%s)", super.getDescription(TAG_CFA_PATTERN_2)); }
byte[] values = _directory.getByteArray(tagType); if (values == null) return null;
@Nullable protected String getByteLengthDescription(final int tagType) { byte[] bytes = _directory.getByteArray(tagType); if (bytes == null) return null; return String.format("(%d byte%s)", bytes.length, bytes.length == 1 ? "" : "s"); }
@Nullable protected String getStringFromBytes(int tag, Charset cs) { byte[] values = _directory.getByteArray(tag); if (values == null) return null; try { return new String(values, cs.name()).trim(); } catch (UnsupportedEncodingException e) { return null; } }
@Nullable public String getString(int tagType, String charset) { byte[] bytes = getByteArray(tagType); if (bytes==null) return null; try { return new String(bytes, charset); } catch (UnsupportedEncodingException e) { return null; } }
/** The Windows specific tags uses plain Unicode. */ @Nullable private String getUnicodeDescription(int tag) { byte[] bytes = _directory.getByteArray(tag); if (bytes == null) return null; try { // Decode the unicode string and trim the unicode zero "\0" from the end. return new String(bytes, "UTF-16LE").trim(); } catch (UnsupportedEncodingException ex) { return null; } }
@Nullable protected String get7BitStringFromBytes(final int tagType) { final byte[] bytes = _directory.getByteArray(tagType); if (bytes == null) return null; int length = bytes.length; for (int index = 0; index < bytes.length; index++) { int i = bytes[index] & 0xFF; if (i == 0 || i > 0x7F) { length = index; break; } } return new String(bytes, 0, length); }
@Nullable public String getUserCommentDescription() byte[] commentBytes = _directory.getByteArray(TAG_USER_COMMENT); if (commentBytes == null) return null;
@Override public void extractMetadata(byte[] bytes, Map<String, String> md) { BufferedInputStream bis = new BufferedInputStream(new ByteArrayInputStream(bytes)); try { Metadata metadata = ImageMetadataReader.readMetadata(bis, false); for (Directory directory : metadata.getDirectories()) { for (Tag tag : directory.getTags()) { String key = tag.getTagName(); if (md.containsKey(key)) { key = String.format("%s (%s)", tag.getTagName(), tag.getDirectoryName()); } String value = directory.getDescription(tag.getTagType()); if (StringUtils.isNotEmpty(value) && value.startsWith("[") && value.endsWith("bytes]")) { byte[] tagBytes = directory.getByteArray(tag.getTagType()); value = Base64.encodeBase64String(tagBytes); } md.put(key, value); } } } catch (Exception ex) { ex.printStackTrace(); } } }
@Nullable public String getCfaPattern2Description() { byte[] values = _directory.getByteArray(TAG_CFA_PATTERN_2); if (values == null) return null; int[] repeatPattern = _directory.getIntArray(TAG_CFA_REPEAT_PATTERN_DIM); if (repeatPattern == null) return String.format("Repeat Pattern not found for CFAPattern (%s)", super.getDescription(TAG_CFA_PATTERN_2)); if (repeatPattern.length == 2 && values.length == (repeatPattern[0] * repeatPattern[1])) { int[] intpattern = new int[2 + values.length]; intpattern[0] = repeatPattern[0]; intpattern[1] = repeatPattern[1]; for (int i = 0; i < values.length; i++) intpattern[i + 2] = values[i] & 0xFF; // convert the values[i] byte to unsigned return formatCFAPattern(intpattern); } return String.format("Unknown Pattern (%s)", super.getDescription(TAG_CFA_PATTERN_2)); }
byte[] values = _directory.getByteArray(tagType); if (values == null) return null;