git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/data-transfer/sis-geotk-plugin@157651 82a268e6-3cf1-43bd-a215-b396298e98cf
parent
976494a484
commit
b89dc09428
@ -0,0 +1,20 @@
|
||||
<assembly>
|
||||
<id>uberjar</id>
|
||||
<formats>
|
||||
<format>jar</format>
|
||||
</formats>
|
||||
<includeBaseDirectory>false</includeBaseDirectory>
|
||||
<dependencySets>
|
||||
<dependencySet>
|
||||
<unpack>false</unpack>
|
||||
<scope>runtime</scope>
|
||||
<useProjectArtifact>false</useProjectArtifact>
|
||||
</dependencySet>
|
||||
</dependencySets>
|
||||
<fileSets>
|
||||
<fileSet>
|
||||
<directory>${project.build.outputDirectory}</directory>
|
||||
<outputDirectory>.</outputDirectory>
|
||||
</fileSet>
|
||||
</fileSets>
|
||||
</assembly>
|
@ -0,0 +1,11 @@
|
||||
package org.gcube.data.transfer.plugins.sis;
|
||||
|
||||
public class TestGetCatalog {
|
||||
|
||||
public static void main(String[] args) {
|
||||
String path="/home/gcube/tomcat/content/thredds/public/netcdf/myCatalog/CERSAT-GLO-CLIM_WIND_L4-OBS_FULL_TIME_SERIE_CLIMATOLOGY_METEOROLOGY_ATMOSPHERE_1366217956317.nc";
|
||||
String publicLocation="/home/gcube/tomcat/content/thredds/public/netcdf/";
|
||||
System.out.println(SisPlugin.getCatalogFromPath(path, publicLocation));
|
||||
}
|
||||
|
||||
}
|
@ -1,16 +1,84 @@
|
||||
package org.gcube.data.transfer.plugins.sis;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
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.model.TransferTicket.Status;
|
||||
|
||||
public class TestGetMetadata {
|
||||
|
||||
public static void main(String[] args) throws UnsupportedStorageException, MalformedURLException, DataStoreException {
|
||||
System.out.println(SisPlugin.getMetaFromFile(new URL("https://github.com/opengeospatial/geoapi/raw/master/geoapi-netcdf/src/test/resources/org/opengis/wrapper/netcdf/NCEP-SST.nc")));
|
||||
public static void main(String[] args) throws UnsupportedStorageException, DataStoreException, IOException, NoSuchAlgorithmException {
|
||||
|
||||
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));
|
||||
|
||||
|
||||
|
||||
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));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static String getChecksum(File datafile) throws NoSuchAlgorithmException, IOException {
|
||||
MessageDigest md = MessageDigest.getInstance("SHA1");
|
||||
FileInputStream fis = new FileInputStream(datafile);
|
||||
byte[] dataBytes = new byte[1024];
|
||||
|
||||
int nread = 0;
|
||||
|
||||
while ((nread = fis.read(dataBytes)) != -1) {
|
||||
md.update(dataBytes, 0, nread);
|
||||
};
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
private static void transferStream(InputStream in, OutputStream out){
|
||||
|
||||
long receivedTotal=0l;
|
||||
|
||||
try{
|
||||
byte[] internalBuf=new byte[1024];
|
||||
int received=0;
|
||||
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…
Reference in New Issue