Skip to content

Instantly share code, notes, and snippets.

@csjx
Created September 24, 2015 16:37
Show Gist options
  • Save csjx/cd7daaa456bebbad20fe to your computer and use it in GitHub Desktop.
Save csjx/cd7daaa456bebbad20fe to your computer and use it in GitHub Desktop.
Some V2 NodeList tests
package org.dataone.tests;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import org.dataone.service.types.v2.NodeList;
import org.dataone.service.util.TypeMarshaller;
import org.jibx.runtime.JiBXException;
public class V2NodeListTest {
public static void main(String[] args) {
try {
// From file
File file = new File("/Users/cjones/dev2v2nodelist.xml");
NodeList nodeListFromFile = TypeMarshaller.unmarshalTypeFromFile(NodeList.class, file);
// From file input stream
InputStream fileInputStream = new FileInputStream("/Users/cjones/dev2v2nodelist.xml");
NodeList nodeListFromStream = TypeMarshaller.unmarshalTypeFromStream(NodeList.class, fileInputStream);
// From URL
URL nodeListURL = new URL("https://cn-dev-2.test.dataone.org/cn/v2/node");
InputStream urlInputStream = nodeListURL.openStream();
NodeList nodeListFromURL = TypeMarshaller.unmarshalTypeFromStream(NodeList.class, urlInputStream);
System.out.println("Number of nodes: " + nodeListFromFile.sizeNodeList());
System.out.println("Number of nodes: " + nodeListFromStream.sizeNodeList());
System.out.println("Number of nodes: " + nodeListFromURL.sizeNodeList());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (JiBXException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment