List of usage examples for org.apache.commons.imaging ImageInfo toString
@Override
public String toString()
From source file:adams.data.image.ImageMetaDataHelper.java
/** * Reads the meta-data from the file (Commons Imaging). * * @param file the file to read the meta-data from * @return the meta-data/*w ww . j a v a 2 s. c o m*/ * @throws Exception if failed to read meta-data */ public static SpreadSheet commons(File file) throws Exception { SpreadSheet sheet; Row row; org.apache.commons.imaging.common.ImageMetadata meta; String[] parts; String key; String value; org.apache.commons.imaging.ImageInfo info; String infoStr; String[] lines; HashSet<String> keys; sheet = new DefaultSpreadSheet(); // header row = sheet.getHeaderRow(); row.addCell("K").setContent("Key"); row.addCell("V").setContent("Value"); keys = new HashSet<String>(); // meta-data meta = Imaging.getMetadata(file.getAbsoluteFile()); if (meta != null) { for (Object item : meta.getItems()) { key = null; value = null; if (item instanceof ImageMetadata.Item) { key = ((ImageMetadata.Item) item).getKeyword().trim(); value = ((ImageMetadata.Item) item).getText().trim(); } else { parts = item.toString().split(": "); if (parts.length == 2) { key = parts[0].trim(); value = parts[1].trim(); } } if (key != null) { if (!keys.contains(key)) { keys.add(key); row = sheet.addRow(); row.addCell("K").setContent(key); row.addCell("V").setContent(fixDateTime(Utils.unquote(value))); } } } } // image info info = Imaging.getImageInfo(file.getAbsoluteFile()); if (info != null) { infoStr = info.toString(); lines = infoStr.split(System.lineSeparator()); for (String line : lines) { parts = line.split(": "); if (parts.length == 2) { key = parts[0].trim(); value = parts[1].trim(); if (!keys.contains(key)) { row = sheet.addRow(); row.addCell("K").setContent(key); row.addCell("V").setContent(Utils.unquote(value)); keys.add(key); } } } } return sheet; }