Merge "Issue #1543 Add ability to save/read dods files back to net.dods" into development
Former-commit-id:7b2adf535e
[formerlydf987e6204
] [formerly0ceb35c131
[formerly 062ed14d60a8b3d29650ce78fa449f69f40d413b]] Former-commit-id:0ceb35c131
Former-commit-id:d08a9b3b13
This commit is contained in:
commit
81d0423913
7 changed files with 80 additions and 50 deletions
|
@ -6,6 +6,5 @@
|
|||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="src" path="resources"/>
|
||||
<classpathentry kind="src" path="unit-test"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
|
|
|
@ -11,8 +11,10 @@
|
|||
|
||||
package dods.dap;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.PrintWriter;
|
||||
import java.util.Enumeration;
|
||||
|
||||
|
@ -105,6 +107,7 @@ public class DAS implements Cloneable {
|
|||
*
|
||||
* @return a clone of this <code>DAS</code>.
|
||||
*/
|
||||
@Override
|
||||
public Object clone() {
|
||||
try {
|
||||
DAS d = (DAS) super.clone();
|
||||
|
@ -189,15 +192,15 @@ public class DAS implements Cloneable {
|
|||
* the <code>PrintWriter</code> to use for output.
|
||||
*/
|
||||
public void print(PrintWriter os) {
|
||||
// os.println("Attributes {");
|
||||
// for (Enumeration e = getNames(); e.hasMoreElements();) {
|
||||
// String name = (String) e.nextElement();
|
||||
// os.println(" " + name + " {");
|
||||
// getAttributeTable(name).print(os, " ");
|
||||
// os.println(" }");
|
||||
// }
|
||||
// os.println("}");
|
||||
// os.flush();
|
||||
os.println("Attributes {");
|
||||
for (Enumeration e = getNames(); e.hasMoreElements();) {
|
||||
String name = (String) e.nextElement();
|
||||
os.println(" " + name + " {");
|
||||
getAttributeTable(name).print(os, " ");
|
||||
os.println(" }");
|
||||
}
|
||||
os.println("}");
|
||||
os.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -208,8 +211,7 @@ public class DAS implements Cloneable {
|
|||
* @see DAS#print(PrintWriter)
|
||||
*/
|
||||
public final void print(OutputStream os) {
|
||||
// print(new PrintWriter(new BufferedWriter(new
|
||||
// OutputStreamWriter(os))));
|
||||
print(new PrintWriter(new BufferedWriter(new OutputStreamWriter(os))));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -175,6 +175,7 @@ public class DDS implements Cloneable {
|
|||
*
|
||||
* @return a clone of this <code>DDS</code>.
|
||||
*/
|
||||
@Override
|
||||
public Object clone() {
|
||||
try {
|
||||
DDS d = (DDS) super.clone();
|
||||
|
@ -516,16 +517,16 @@ public class DDS implements Cloneable {
|
|||
* the <code>PrintWriter</code> to use for output.
|
||||
*/
|
||||
public void print(PrintWriter os) {
|
||||
// os.println("Dataset {");
|
||||
// for (Enumeration e = vars.elements(); e.hasMoreElements();) {
|
||||
// BaseType bt = (BaseType) e.nextElement();
|
||||
//
|
||||
// bt.printDecl(os);
|
||||
// }
|
||||
// os.print("} ");
|
||||
// if (name != null)
|
||||
// os.print(name);
|
||||
// os.println(";");
|
||||
os.println("Dataset {");
|
||||
for (Enumeration e = vars.elements(); e.hasMoreElements();) {
|
||||
BaseType bt = (BaseType) e.nextElement();
|
||||
|
||||
bt.printDecl(os);
|
||||
}
|
||||
os.print("} ");
|
||||
if (name != null)
|
||||
os.print(name);
|
||||
os.println(";");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -538,7 +539,7 @@ public class DDS implements Cloneable {
|
|||
public final void print(OutputStream os) {
|
||||
PrintWriter pw = new PrintWriter(new BufferedWriter(
|
||||
new OutputStreamWriter(os)));
|
||||
// print(pw);
|
||||
print(pw);
|
||||
pw.flush();
|
||||
}
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ import java.util.zip.DeflaterOutputStream;
|
|||
*/
|
||||
public class DataDDS extends DDS {
|
||||
/** The ServerVersion returned from the open DODS connection. */
|
||||
private ServerVersion ver;
|
||||
private final ServerVersion ver;
|
||||
|
||||
/**
|
||||
* Construct the DataDDS with the given server version.
|
||||
|
@ -167,16 +167,16 @@ public class DataDDS extends DDS {
|
|||
}
|
||||
|
||||
// Redefine PrintWriter here, so the DDS is also compressed if necessary
|
||||
// PrintWriter pw = new PrintWriter(new OutputStreamWriter(bufferedOS));
|
||||
// print(pw);
|
||||
PrintWriter pw = new PrintWriter(new OutputStreamWriter(bufferedOS));
|
||||
print(pw);
|
||||
// pw.println("Data:"); // JCARON CHANGED
|
||||
// pw.flush();
|
||||
// bufferedOS.write("\nData:\n".getBytes()); // JCARON CHANGED
|
||||
// bufferedOS.flush();
|
||||
pw.flush();
|
||||
bufferedOS.write("\nData:\n".getBytes()); // JCARON CHANGED
|
||||
bufferedOS.flush();
|
||||
|
||||
// Use a DataOutputStream for serialize
|
||||
DataOutputStream dataOS = new DataOutputStream(bufferedOS);
|
||||
for (Enumeration<?> e = getVariables(); e.hasMoreElements();) {
|
||||
for (Enumeration e = getVariables(); e.hasMoreElements();) {
|
||||
ClientIO bt = (ClientIO) e.nextElement();
|
||||
bt.externalize(dataOS);
|
||||
}
|
||||
|
|
|
@ -20,12 +20,19 @@
|
|||
package dods.dap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.raytheon.dods.DodsOriginalHttpConnectStrategy;
|
||||
import com.raytheon.uf.common.util.TestUtil;
|
||||
|
||||
import dods.dap.parser.ParseException;
|
||||
|
||||
/**
|
||||
* Test {@link DConnect}.
|
||||
|
@ -36,34 +43,16 @@ import com.raytheon.dods.DodsOriginalHttpConnectStrategy;
|
|||
*
|
||||
* Date Ticket# Engineer Description
|
||||
* ------------ ---------- ----------- --------------------------
|
||||
* Jul 9, 2012 634 djohnson Initial creation
|
||||
* Jul 09, 2012 0634 djohnson Initial creation
|
||||
* Feb 05, 2013 1543 djohnson Moved to tests project, add tests for reading dods files.
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @author djohnson
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
public class DConnectTest {
|
||||
|
||||
@Test
|
||||
public void testSystemPropertyTimeoutsAreSetOnHttpStrategy()
|
||||
throws FileNotFoundException {
|
||||
final int connectionTimeout = 10;
|
||||
final int socketTimeout = 11;
|
||||
|
||||
System.setProperty(DConnect.DODS_CONNECTION_TIMEOUT_MILLISECONDS,
|
||||
Integer.toString(connectionTimeout));
|
||||
System.setProperty(DConnect.DODS_SOCKET_TIMEOUT_MILLISECONDS,
|
||||
Integer.toString(socketTimeout));
|
||||
|
||||
MockHttpConnectStrategy mockHttpStrategy = new MockHttpConnectStrategy();
|
||||
new DConnect("file://", null, null, true,
|
||||
mockHttpStrategy);
|
||||
|
||||
assertEquals(connectionTimeout, mockHttpStrategy.connectionTimeout);
|
||||
assertEquals(socketTimeout, mockHttpStrategy.socketTimeout);
|
||||
}
|
||||
|
||||
private class MockHttpConnectStrategy extends
|
||||
DodsOriginalHttpConnectStrategy {
|
||||
|
@ -83,4 +72,43 @@ public class DConnectTest {
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSystemPropertyTimeoutsAreSetOnHttpStrategy()
|
||||
throws FileNotFoundException {
|
||||
final int connectionTimeout = 10;
|
||||
final int socketTimeout = 11;
|
||||
|
||||
System.setProperty(DConnect.DODS_CONNECTION_TIMEOUT_MILLISECONDS,
|
||||
Integer.toString(connectionTimeout));
|
||||
System.setProperty(DConnect.DODS_SOCKET_TIMEOUT_MILLISECONDS,
|
||||
Integer.toString(socketTimeout));
|
||||
|
||||
MockHttpConnectStrategy mockHttpStrategy = new MockHttpConnectStrategy();
|
||||
new DConnect("file://", null, null, true, mockHttpStrategy);
|
||||
|
||||
assertEquals(connectionTimeout, mockHttpStrategy.connectionTimeout);
|
||||
assertEquals(socketTimeout, mockHttpStrategy.socketTimeout);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ableToReadCompressedFormat() throws MalformedURLException,
|
||||
DDSException, IOException, ParseException, DODSException {
|
||||
DConnect dconnect = new DConnect(new ByteArrayInputStream(
|
||||
TestUtil.readResource(DConnectTest.class, "compressed.dods")));
|
||||
final DataDDS data = dconnect.getData(null);
|
||||
|
||||
assertNotNull(data);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void ableToReadUncompressedFormat() throws MalformedURLException,
|
||||
DDSException,
|
||||
IOException, ParseException, DODSException {
|
||||
DConnect dconnect = new DConnect(new ByteArrayInputStream(
|
||||
TestUtil.readResource(DConnectTest.class, "uncompressed.dods")));
|
||||
final DataDDS data = dconnect.getData(null);
|
||||
|
||||
assertNotNull(data);
|
||||
}
|
||||
}
|
BIN
tests/unit/dods/dap/compressed.dods
Normal file
BIN
tests/unit/dods/dap/compressed.dods
Normal file
Binary file not shown.
BIN
tests/unit/dods/dap/uncompressed.dods
Normal file
BIN
tests/unit/dods/dap/uncompressed.dods
Normal file
Binary file not shown.
Loading…
Add table
Reference in a new issue