UCAR Library

pull/1/head
Fabio Sinibaldi 3 years ago
parent 8d8005f0c0
commit 05ff46dc6f

@ -1,36 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>

@ -1,5 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.source=1.8

@ -1,4 +1,5 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
@ -96,6 +97,36 @@
<artifactId>sis-netcdf</artifactId>
<version>${sis.utils.modules}</version>
</dependency>
<dependency>
<groupId>org.apache.sis.storage</groupId>
<artifactId>sis-earth-observation</artifactId>
<version>${sis.utils.modules}</version>
</dependency>
<dependency>
<groupId>org.apache.sis.storage</groupId>
<artifactId>sis-geotiff</artifactId>
<version>${sis.utils.modules}</version>
</dependency>
<!-- EPSG Dataset. NB Check Performances -->
<dependency>
<groupId>org.apache.sis.non-free</groupId>
<artifactId>sis-embedded-data</artifactId>
<version>${sis.version}</version>
<scope>runtime</scope>
</dependency>
<!-- UCAR Library used by SIS if embedded can't decode -->
<!-- https://mvnrepository.com/artifact/edu.ucar/netcdf -->
<dependency>
<groupId>edu.ucar</groupId>
<artifactId>netcdf</artifactId>
<version>4.3.22</version>
</dependency>
<!-- TEST -->
<dependency>
@ -117,11 +148,19 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.opengis</groupId>
<artifactId>geoapi-conformance</artifactId>
<version>3.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>

@ -21,48 +21,71 @@ 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",
};
File temp=File.createTempFile("temp", ".temp");
File original=new File("/home/fabio/Downloads/oscar_vel2011_180.nc");
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));
for(String f:toCheckFiles) {
System.out.println("checking "+f);
check(false,f);
}
System.out.println("Done");
}
private static void check(boolean checkCopy,String src) throws UnsupportedStorageException, DataStoreException, IOException, NoSuchAlgorithmException {
File original=new File(src);
File dataset=original;
Files.move(temp.toPath(), copied.toPath(),StandardCopyOption.ATOMIC_MOVE,StandardCopyOption.REPLACE_EXISTING);
if(copied.length()<original.length()) throw new RuntimeException("Different size after moving");
System.out.println(SisPlugin.getMetaFromFile(copied));
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()<original.length()) throw new RuntimeException("Different size after moving");
dataset=copied;
}
System.out.println(SisPlugin.getMetaFromFile(dataset));
}
private static String getChecksum(File datafile) throws NoSuchAlgorithmException, IOException {
MessageDigest md = MessageDigest.getInstance("SHA1");
FileInputStream fis = new FileInputStream(datafile);
byte[] dataBytes = new byte[1024];
FileInputStream fis = new FileInputStream(datafile);
byte[] dataBytes = new byte[1024];
int nread = 0;
int nread = 0;
while ((nread = fis.read(dataBytes)) != -1) {
md.update(dataBytes, 0, nread);
};
while ((nread = fis.read(dataBytes)) != -1) {
md.update(dataBytes, 0, nread);
};
byte[] mdbytes = md.digest();
byte[] mdbytes = md.digest();
//convert the byte to hex format
StringBuffer sb = new StringBuffer("");
for (int i = 0; i < mdbytes.length; i++) {
sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
}
//convert the byte to hex format
StringBuffer sb = new StringBuffer("");
for (int i = 0; i < mdbytes.length; i++) {
sb.append(Integer.toString((mdbytes[i] & 0xff) + 0x100, 16).substring(1));
}
return sb.toString();
}
private static void transferStream(InputStream in, OutputStream out){
@ -74,12 +97,12 @@ public class TestGetMetadata {
while ((received=in.read(internalBuf))!=-1){
out.write(internalBuf,0,received);
receivedTotal+=received;
}
out.flush();
}catch(IOException e){
throw new RuntimeException("Unable to read from source.");
}
}
}

Loading…
Cancel
Save