List of usage examples for java.util Formatter Formatter
public Formatter()
From source file:org.ramadda.geodata.cdmdata.PointDatabaseTypeHandler.java
/** * _more_//from w w w . j ava 2s .c o m * * @param entry _more_ * @param parent _more_ * @param file _more_ * * @return _more_ * * @throws Exception _more_ */ protected FeatureDatasetPoint getDataset(Entry entry, Entry parent, File file) throws Exception { Formatter buf = new Formatter(); getStorageManager().checkReadFile(file); if (file.toString().toLowerCase().endsWith(".csv")) { TextPointDataSource dataSource = new TextPointDataSource("dummy.csv"); String contents = getStorageManager().readSystemResource(file); FieldImpl field = dataSource.makeObs(contents, ",", null, null, null, false, false); file = getStorageManager().getTmpFile(null, "test.nc"); PointObFactory.writeToNetcdf(file, field); } List<Metadata> metadataList = getMetadataManager().findMetadata(null, entry, ContentMetadataHandler.TYPE_ATTACHMENT, true); if (metadataList == null) { if (parent != null) { metadataList = getMetadataManager().findMetadata(null, parent, ContentMetadataHandler.TYPE_ATTACHMENT, true, false); } } if (metadataList != null) { for (Metadata metadata : metadataList) { if (metadata.getAttr1().endsWith(".ncml")) { File templateNcmlFile = new File(IOUtil.joinDir( getRepository().getStorageManager().getEntryDir(metadata.getEntryId(), false), metadata.getAttr1())); String ncml = getStorageManager().readSystemResource(templateNcmlFile); String filePath = file.toString(); filePath = filePath.replace("\\", "/"); if (filePath.indexOf(":") >= 0) { filePath = IOUtil.getURL(filePath, getClass()).toString(); } ncml = ncml.replace("${location}", filePath); File ncmlFile = getStorageManager() .getScratchFile(entry.getId() + "_" + metadata.getId() + ".ncml"); IOUtil.writeBytes(ncmlFile, ncml.getBytes()); file = new File(ncmlFile.toString()); break; } } } FeatureDatasetPoint pods = (FeatureDatasetPoint) FeatureDatasetFactoryManager .open(ucar.nc2.constants.FeatureType.POINT, file.toString(), null, buf); if (pods == null) { // try as ANY_POINT pods = (FeatureDatasetPoint) FeatureDatasetFactoryManager.open(ucar.nc2.constants.FeatureType.ANY_POINT, file.toString(), null, buf); } return pods; }
From source file:com.flexoodb.common.FlexUtils.java
/** * computes the SHA1 hashcode for the passed byte array. * * @param ba byte array.//from ww w . j a v a 2 s . com * @return SHA1 string. */ public static String computeSHA1(byte[] ba) { String hash = null; try { MessageDigest sha1 = MessageDigest.getInstance("SHA1"); InputStream is = new ByteArrayInputStream(ba); BufferedInputStream bis = new BufferedInputStream(is); DigestInputStream dis = new DigestInputStream(bis, sha1); while (dis.read() != -1) { } ; byte[] h = sha1.digest(); Formatter formatter = new Formatter(); for (byte b : h) { formatter.format("%02x", b); } hash = formatter.toString(); } catch (Exception e) { e.printStackTrace(); } return hash; }