opendap.dap
Class Int16PrimitiveVector

java.lang.Object
  extended by opendap.dap.PrimitiveVector
      extended by opendap.dap.Int16PrimitiveVector
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, ClientIO
Direct Known Subclasses:
UInt16PrimitiveVector

public class Int16PrimitiveVector
extends PrimitiveVector
implements java.lang.Cloneable

A vector of shorts. (as in 16bit ints :)

Version:
$Revision: 23881 $
Author:
npotter
See Also:
PrimitiveVector, Serialized Form

Constructor Summary
Int16PrimitiveVector(BaseType var)
          Constructs a new Int16PrimitiveVector.
 
Method Summary
 java.lang.Object clone()
          Returns a clone of this Int16PrimitiveVector.
 void deserialize(java.io.DataInputStream source, ServerVersion sv, StatusUI statusUI)
          Reads data from a DataInputStream.
 void externalize(java.io.DataOutputStream sink)
          Writes data to a DataOutputStream.
 void externalize(java.io.DataOutputStream sink, int start, int stop, int stride)
          Write a subset of the data to a DataOutputStream.
 java.lang.Object getInternalStorage()
          Returns (a reference to) the internal storage for this PrimitiveVector object.
 int getLength()
          Returns the number of elements in the array.
 short getValue(int i)
          Return the i'th value as a short.
 void printSingleVal(java.io.PrintWriter os, int index)
          Prints the value of a single variable in this vector.
 void printVal(java.io.PrintWriter os, java.lang.String space)
          Prints the value of all variables in this vector.
 void setInternalStorage(java.lang.Object o)
          Set the internal storage for PrimitiveVector.
 void setLength(int len)
          Sets the number of elements in the array.
 void setValue(int i, short newVal)
          Set the i'th value of the array.
 PrimitiveVector subset(int start, int stop, int stride)
          Create a new primitive vector using a subset of the data.
 
Methods inherited from class opendap.dap.PrimitiveVector
getTemplate, printDecl, printDecl
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Int16PrimitiveVector

public Int16PrimitiveVector(BaseType var)
Constructs a new Int16PrimitiveVector.

Parameters:
var - the template BaseType to use.
Method Detail

clone

public java.lang.Object clone()
Returns a clone of this Int16PrimitiveVector. A deep copy is performed on all data inside the variable.

Overrides:
clone in class PrimitiveVector
Returns:
a clone of this Int16PrimitiveVector.

getLength

public int getLength()
Returns the number of elements in the array.

Specified by:
getLength in class PrimitiveVector
Returns:
the number of elements in the array.

setLength

public void setLength(int len)
Sets the number of elements in the array. Allocates a new primitive array of the desired size. Note that if this is called multiple times, the old array and its contents will be lost.

Only called inside of deserialize method or in derived classes on server.

Specified by:
setLength in class PrimitiveVector
Parameters:
len - the number of elements in the array.

getValue

public final short getValue(int i)
Return the i'th value as a short.

Parameters:
i - the index of the value to return.
Returns:
the i'th value.

setValue

public final void setValue(int i,
                           short newVal)
Set the i'th value of the array.

Parameters:
i - the index of the value to set.
newVal - the new value.

printVal

public void printVal(java.io.PrintWriter os,
                     java.lang.String space)
Prints the value of all variables in this vector. This method is primarily intended for debugging OPeNDAP applications and text-based clients such as geturl.

Specified by:
printVal in class PrimitiveVector
Parameters:
os - the PrintWriter on which to print the value.
space - this value is passed to the printDecl method, and controls the leading spaces of the output.
See Also:
BaseType.printVal(PrintWriter, String, boolean)

printSingleVal

public void printSingleVal(java.io.PrintWriter os,
                           int index)
Prints the value of a single variable in this vector. method is used by DArray's printVal method.

Specified by:
printSingleVal in class PrimitiveVector
Parameters:
os - the PrintWriter on which to print the value.
index - the index of the variable to print.
See Also:
DArray.printVal(PrintWriter, String, boolean)

deserialize

public void deserialize(java.io.DataInputStream source,
                        ServerVersion sv,
                        StatusUI statusUI)
                 throws java.io.IOException,
                        java.io.EOFException,
                        DataReadException
Reads data from a DataInputStream. This method is only used on the client side of the OPeNDAP client/server connection.

Specified by:
deserialize in interface ClientIO
Specified by:
deserialize in class PrimitiveVector
Parameters:
source - a DataInputStream to read from.
sv - The ServerVersion returned by the server. (used by DSequence to determine which protocol version was used).
statusUI - The StatusUI object to use for GUI updates and user cancellation notification (may be null).
Throws:
DataReadException - when invalid data is read, or if the user cancels the download.
java.io.EOFException - if EOF is found before the variable is completely deserialized.
java.io.IOException - thrown on any other InputStream exception.
See Also:
ClientIO.deserialize(DataInputStream, ServerVersion, StatusUI)

externalize

public void externalize(java.io.DataOutputStream sink)
                 throws java.io.IOException
Writes data to a DataOutputStream. This method is used primarily by GUI clients which need to download OPeNDAP data, manipulate it, and then re-save it as a binary file.

Specified by:
externalize in interface ClientIO
Specified by:
externalize in class PrimitiveVector
Parameters:
sink - a DataOutputStream to write to.
Throws:
java.io.IOException - thrown on any OutputStream exception.

externalize

public void externalize(java.io.DataOutputStream sink,
                        int start,
                        int stop,
                        int stride)
                 throws java.io.IOException
Write a subset of the data to a DataOutputStream.

Parameters:
sink - a DataOutputStream to write to.
start - starting index (i=start)
stop - ending index (i<=stop)
stride - index stride (i+=stride)
Throws:
java.io.IOException - thrown on any OutputStream exception.

getInternalStorage

public java.lang.Object getInternalStorage()
Returns (a reference to) the internal storage for this PrimitiveVector object.

WARNING:

Because this method breaks encapsulation rules the user must beware! If we (the OPeNDAP prgramming team) choose to change the internal representation(s) of these types your code will probably break.

This method is provided as an optimization to eliminate massive copying of data.

Specified by:
getInternalStorage in class PrimitiveVector
Returns:
The internal array of shorts.

setInternalStorage

public void setInternalStorage(java.lang.Object o)
Set the internal storage for PrimitiveVector.

WARNING:

Because this method breaks encapsulation rules the user must beware! If we (the OPeNDAP prgramming team) choose to change the internal representation(s) of these types your code will probably break.

This method is provided as an optimization to eliminate massive copying of data.

Specified by:
setInternalStorage in class PrimitiveVector

subset

public PrimitiveVector subset(int start,
                              int stop,
                              int stride)
Create a new primitive vector using a subset of the data.

Specified by:
subset in class PrimitiveVector
Parameters:
start - starting index (i=start)
stop - ending index (i<=stop)
stride - index stride (i+=stride)
Returns:
new primitive vector, of type Int16PrimitiveVector.