package org.gcube.data.transfer.plugins.sis; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.StandardCopyOption; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import org.apache.sis.storage.DataStoreException; import org.apache.sis.storage.UnsupportedStorageException; import org.gcube.data.transfer.plugins.thredds.sis.SisPlugin; public class TestGetMetadata { public static void main(String[] args) throws UnsupportedStorageException, DataStoreException, IOException, NoSuchAlgorithmException { String[] toCheckFiles=new String[] { "/Users/FabioISTI/Downloads/Aaptos_aaptos.nc", "/Users/FabioISTI/Downloads/NASA_Precipitations_1950_2100_rcp45.nc", }; for(String f:toCheckFiles) { System.out.println("checking "+f); try{ check(false,f); }catch(UnsupportedStorageException e) { System.err.println(e.getMessage()); // System.out.println("Trying opening "+f+" manually"); // open(f); } } System.out.println("Done"); } // private static void open(String path) throws IOException, UnsupportedStorageException, DataStoreException { // System.out.println("Opening "+path); // NetcdfFile f=NetcdfFiles.open(path); // System.out.println(f.getFileTypeDescription()+"\t"+f.getFileTypeId()); // // // NetcdfDataset ncDs=NetcdfDatasets.openDataset(path); //// NcMLReaderNew. //// // System.out.println(ncDs.getFileTypeDescription()+"\t"+ncDs.getFileTypeId()); // //// NetcdfDatasets.openFile(path,null); // // // } private static void check(boolean checkCopy,String src) throws UnsupportedStorageException, DataStoreException, IOException, NoSuchAlgorithmException { File original=new File(src); File dataset=original; if(checkCopy) { File temp=File.createTempFile("temp", ".temp"); File copied=File.createTempFile("copied", ".nc"); transferStream(new FileInputStream(original),new FileOutputStream(temp)); System.out.println("copied. Moving.."); System.out.println("Checksum original : "+getChecksum(original)); System.out.println("Checksum temp : "+getChecksum(temp)); Files.move(temp.toPath(), copied.toPath(),StandardCopyOption.ATOMIC_MOVE,StandardCopyOption.REPLACE_EXISTING); if(copied.length()