opendap/src/main/java/opendap/servers/SDArray.java
public void serialize(String dataset, DataOutputStream sink, CEEvaluator ce, Object specialO)
            throws NoSuchVariableException, DAP2ServerSideException, IOException {
        PrimitiveVector vals = getPrimitiveVector();

        if (!isRead())
            read(dataset, specialO);

        if (vals.getTemplate() instanceof DSequence || ce.evalClauses(specialO)) {
            // Because arrays of primitive types (ie int32, float32, byte,
            // etc) are handled in the C++ core using the XDR package we must
            // write the length twice for those types. For BaseType vectors,
            // we should write it only once. This is in effect a work around
            // for a bug in the C++ core as the C++ core does not consume 2
            // length values for thge BaseType vectors. Bummer...
            int length = vals.getLength();
            sink.writeInt(length);

            // Gotta check for this to make sure that DConstructor types
            // (Especially SDSequence) get handled correctly!!!
            if (vals instanceof BaseTypePrimitiveVector) {
                for (int i = 0; i < length; i++) {
                    ServerMethods sm = (ServerMethods)
                            ((BaseTypePrimitiveVector) vals).getValue(i);
                    sm.serialize(dataset, sink, ce, specialO);
                }
            } else {
                // Because both XDR and OPeNDAP read the length, we must write
                // it twice.
                sink.writeInt(length);
                vals.externalize(sink);
            }
        }
    }
public void serialize(String dataset, DataOutputStream sink, CEEvaluator ce, Object specialO)
            throws NoSuchVariableException, DAP2ServerSideException, IOException {
        PrimitiveVector vals = getPrimitiveVector();

        if (!isRead())
            read(dataset, specialO);

        if (vals.getTemplate() instanceof DSequence || ce.evalClauses(specialO)) {
            // Because arrays of primitive types (ie int32, float32, byte,
            // etc) are handled in the C++ core using the XDR package we must
            // write the length twice for those types. For BaseType vectors,
            // we should write it only once. This is in effect a work around
            // for a bug in the C++ core as the C++ core does not consume 2
            // length values for thge BaseType vectors. Bummer...
            int length = vals.getLength();
            sink.writeInt(length);

            // Gotta check for this to make sure that DConstructor types
            // (Especially SDSequence) get handled correctly!!!
            if (vals instanceof BaseTypePrimitiveVector) {
                for (int i = 0; i < length; i++) {
                    ServerMethods sm = (ServerMethods)
                            ((BaseTypePrimitiveVector) vals).getValue(i);
                    sm.serialize(dataset, sink, ce, specialO);
                }
            } else {
                // Because both XDR and OPeNDAP read the length, we must write
                // it twice.
                sink.writeInt(length);
                vals.externalize(sink);
            }
        }
    }
public void serialize ( String dataset , DataOutputStream sink , CEEvaluator ce , Object specialO ) throws NoSuchVariableException , DAP2ServerSideException , IOException { PrimitiveVector vals = getPrimitiveVector ( ) ; if ( ! isRead ( ) ) read ( dataset , specialO ) ; if ( vals . getTemplate ( ) instanceof DSequence || ce . evalClauses ( specialO ) ) { // Because arrays of primitive types (ie int32, float32, byte, // etc) are handled in the C++ core using the XDR package we must // write the length twice for those types. For BaseType vectors, // we should write it only once. This is in effect a work around // for a bug in the C++ core as the C++ core does not consume 2 // length values for thge BaseType vectors. Bummer... int length = vals . getLength ( ) ; sink . writeInt ( length ) ; // Gotta check for this to make sure that DConstructor types // (Especially SDSequence) get handled correctly!!! if ( vals instanceof BaseTypePrimitiveVector ) { for ( int i = 0 ; i < length ; i ++ ) { ServerMethods sm = ( ServerMethods ) ( ( BaseTypePrimitiveVector ) vals ) . getValue ( i ) ; sm . serialize ( dataset , sink , ce , specialO ) ; } } else { // Because both XDR and OPeNDAP read the length, we must write // it twice. sink . writeInt ( length ) ; vals . externalize ( sink ) ; } } }
<p/>
Server-side serialization for OPeNDAP variables (sub-classes of
<code>BaseType</code>). This does not send the entire class as the Java
<code>Serializable</code> interface does, rather it sends only the
binary data values. Other software is responsible for sending variable
type information (see <code>DDS</code>).
</p><p>
Writes data to a <code>DataOutputStream</code>. This method is used
on the server side of the OPeNDAP client/server connection, and possibly
by GUI clients which need to download OPeNDAP data, manipulate it, and
then re-save it as a binary file.
</p>
<h2>Caution:</h2>
When serializing arrays of sequences (children of DSequence) it is crucial
that it be handled with great care. Sequences have been implemented so that
only one instance (or row if you will) is retained in memory at a given time.
In order to correctly serialize an array of sequences the read() method for the
array must create an instance of the sequence for each member of the array, typically
by repeatedly cloning the template variable in the PrimitiveVector. The important next
step is to NOT attempt to read any data into the sequences from within the read()
method of the parent array. The sequence's data will get read, and constraint expressions
applied when the serialze() method of the array calls the serialize method of the
sequence. Good Luck!

@param sink     a <code>DataOutputStream</code> to write to.
@param ce       a <code>CEEvaluator</code> containing constraint Clauses.
@param specialO a <code>Object</code> to be used by <code>ServerMethods.read()</code>
@throws IOException thrown on any <code>OutputStream</code>
exception.
@see BaseType
@see DDS
@see ServerDDS
<p / > Server - side serialization for OPeNDAP variables ( sub - classes of <code > BaseType< / code > ) . This does not send the entire class as the Java <code > Serializable< / code > interface does rather it sends only the binary data values . Other software is responsible for sending variable type information ( see <code > DDS< / code > ) . < / p > <p > Writes data to a <code > DataOutputStream< / code > . This method is used on the server side of the OPeNDAP client / server connection and possibly by GUI clients which need to download OPeNDAP data manipulate it and then re - save it as a binary file . < / p > <h2 > Caution : < / h2 > When serializing arrays of sequences ( children of DSequence ) it is crucial that it be handled with great care . Sequences have been implemented so that only one instance ( or row if you will ) is retained in memory at a given time . In order to correctly serialize an array of sequences the read () method for the array must create an instance of the sequence for each member of the array typically by repeatedly cloning the template variable in the PrimitiveVector . The important next step is to NOT attempt to read any data into the sequences from within the read () method of the parent array . The sequence s data will get read and constraint expressions applied when the serialze () method of the array calls the serialize method of the sequence . Good Luck!