Ejemplo n.º 1
0
        public override void Marshal(DataOutputStream dos)
        {
            base.Marshal(dos);
            if (dos != null)
            {
                try
                {
                    dos.WriteUnsignedShort((ushort)this._encodingScheme);
                    dos.WriteUnsignedShort((ushort)this._tdlType);
                    dos.WriteUnsignedInt((uint)this._sampleRate);
                    dos.WriteShort((short)this._dataLength);
                    dos.WriteShort((short)this._samples);
                }
                catch (Exception e)
                {
                    if (PduBase.TraceExceptions)
                    {
                        Trace.WriteLine(e);
                        Trace.Flush();
                    }

                    this.RaiseExceptionOccured(e);

                    if (PduBase.ThrowExceptions)
                    {
                        throw e;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public override void Marshal(DataOutputStream dos)
        {
            base.Marshal(dos);
            if (dos != null)
            {
                try
                {
                    dos.WriteUnsignedShort((ushort)this._encodingScheme);
                    dos.WriteUnsignedShort((ushort)this._tdlType);
                    dos.WriteUnsignedInt((uint)this._sampleRate);
                    dos.WriteShort((short)((this._dataLength == 0 && this._data.Length > 0) ? this._data.Length * 8 : this._dataLength)); //09062009 Post processed.  If value is zero then default to every byte will use all 8 bits
                    dos.WriteShort((short)this._samples);

                    dos.WriteByte(this._data);
                }
                catch (Exception e)
                {
                    if (PduBase.TraceExceptions)
                    {
                        Trace.WriteLine(e);
                        Trace.Flush();
                    }

                    this.RaiseExceptionOccured(e);

                    if (PduBase.ThrowExceptions)
                    {
                        throw e;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public virtual void Marshal(DataOutputStream dos)
        {
            if (dos != null)
            {
                try
                {
                    dos.WriteShort((short)this._currentShaftRPMs);
                    dos.WriteShort((short)this._orderedShaftRPMs);
                    dos.WriteFloat((float)this._shaftRPMRateOfChange);
                }
                catch (Exception e)
                {
                    if (PduBase.TraceExceptions)
                    {
                        Trace.WriteLine(e);
                        Trace.Flush();
                    }

                    this.RaiseExceptionOccured(e);

                    if (PduBase.ThrowExceptions)
                    {
                        throw e;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public override void Marshal(DataOutputStream dos)
        {
            base.Marshal(dos);
            if (dos != null)
            {
                try
                {
                    this._originatingID.Marshal(dos);
                    this._receivingID.Marshal(dos);
                    this._realWorldTime.Marshal(dos);
                    dos.WriteUnsignedByte((byte)this._reason);
                    dos.WriteUnsignedByte((byte)this._frozenBehavior);
                    dos.WriteShort((short)this._padding1);
                    dos.WriteUnsignedInt((uint)this._requestID);
                }
                catch (Exception e)
                {
#if DEBUG
                    Trace.WriteLine(e);
                    Trace.Flush();
#endif
                    this.OnException(e);
                }
            }
        }
Ejemplo n.º 5
0
 public byte[] toByteArray() {
     short datalen = 0;
     byte[] data = null;
     byte[] bytes = null;
     byte[] byteNew = null;
     try {
         if (dos != null) {
             dos.Flush();
             data = ms.ToArray();
             datalen = (short)data.Length;
             dos.Close();
         }
         MemoryStream bos1 = new MemoryStream(datalen + 3);
         DataOutputStream dos1 = new DataOutputStream(new BinaryWriterIns(bos1));
         dos1.WriteByteNew(command);
         dos1.WriteShort(datalen);
         if (datalen > 0) {
             dos1.Write(data);
         }
         bytes = bos1.ToArray();
         byteNew = new byte[bytes.Length - 3];
         int n = byteNew.Length;
         Array.Copy(bytes, 3, byteNew, 0, n);
         byteNew[0] = (byte)command;
         dos1.Close();
     }
     catch (IOException e) {
         Debug.Log(e.ToString());
     }
     return byteNew;
 }
Ejemplo n.º 6
0
    public byte[] toByteArray()
    {
        short datalen = 0;

        byte[] data    = null;
        byte[] bytes   = null;
        byte[] byteNew = null;
        try {
            if (dos != null)
            {
                dos.Flush();
                data    = ms.ToArray();
                datalen = (short)data.Length;
                dos.Close();
            }
            MemoryStream     bos1 = new MemoryStream(datalen + 3);
            DataOutputStream dos1 = new DataOutputStream(new BinaryWriterIns(bos1));
            dos1.WriteByteNew(command);
            dos1.WriteShort(datalen);
            if (datalen > 0)
            {
                dos1.Write(data);
            }
            bytes   = bos1.ToArray();
            byteNew = new byte[bytes.Length - 3];
            int n = byteNew.Length;
            Array.Copy(bytes, 3, byteNew, 0, n);
            byteNew[0] = (byte)command;
            dos1.Close();
        }
        catch (IOException e) {
            Debug.Log(e.ToString());
        }
        return(byteNew);
    }
Ejemplo n.º 7
0
        public override void Marshal(DataOutputStream dos)
        {
            base.Marshal(dos);
            if (dos != null)
            {
                try
                {
                    this._munitionID.Marshal(dos);
                    this._eventID.Marshal(dos);
                    this._velocity.Marshal(dos);
                    this._locationInWorldCoordinates.Marshal(dos);
                    this._burstDescriptor.Marshal(dos);
                    this._locationInEntityCoordinates.Marshal(dos);
                    dos.WriteUnsignedByte((byte)this._detonationResult);
                    dos.WriteUnsignedByte((byte)this._articulationParameters.Count);
                    dos.WriteShort((short)this._pad);

                    for (int idx = 0; idx < this._articulationParameters.Count; idx++)
                    {
                        ArticulationParameter aArticulationParameter = (ArticulationParameter)this._articulationParameters[idx];
                        aArticulationParameter.Marshal(dos);
                    }
                }
                catch (Exception e)
                {
#if DEBUG
                    Trace.WriteLine(e);
                    Trace.Flush();
#endif
                    this.OnException(e);
                }
            }
        }
Ejemplo n.º 8
0
        public byte[] ToByteArray()
        {
            MemoryStream     byteArrayOutputStream = new MemoryStream(12);
            DataOutputStream outputStream          = new DataOutputStream(byteArrayOutputStream);

            byte header1 = 0;

            header1 |= (byte)(Version << 6);
            header1 |= (byte)((PaddingFlag ? 1 : 0) << 5);
            header1 |= (byte)((ExtensionFlag ? 1 : 0) << 4);
            header1 |= ContributingSourceIdentifiersCount;

            outputStream.WriteByte(header1);

            byte header2 = 0;

            header2 |= (byte)((MarkerFlag ? 1 : 0) << 7);
            header2 |= PayloadType;

            outputStream.WriteByte(header2);

            outputStream.WriteShort(SequenceNumber);
            outputStream.WriteInt(Timestamp);
            outputStream.WriteInt(Ssrc);
            outputStream.Flush();
            return(byteArrayOutputStream.ToArray());
        }
Ejemplo n.º 9
0
        /// <summary>Write the word vectors to an output stream.</summary>
        /// <remarks>
        /// Write the word vectors to an output stream. The stream is not closed on finishing
        /// the function.
        /// </remarks>
        /// <param name="out">The stream to write to.</param>
        /// <exception cref="System.IO.IOException">Thrown if the stream could not be written to.</exception>
        public virtual void Serialize(OutputStream @out)
        {
            DataOutputStream dataOut = new DataOutputStream(@out);
            // Write some length statistics
            int maxKeyLength = 0;
            int vectorLength = 0;

            foreach (KeyValuePair <string, float[]> entry in this)
            {
                maxKeyLength = Math.Max(Sharpen.Runtime.GetBytesForString(entry.Key).Length, maxKeyLength);
                vectorLength = entry.Value.Length;
            }
            VectorMap.Itype keyIntType = VectorMap.Itype.GetType(maxKeyLength);
            // Write the key length
            dataOut.WriteInt(maxKeyLength);
            // Write the vector dim
            dataOut.WriteInt(vectorLength);
            // Write the size of the dataset
            dataOut.WriteInt(this.Count);
            foreach (KeyValuePair <string, float[]> entry_1 in this)
            {
                // Write the length of the key
                byte[] key = Sharpen.Runtime.GetBytesForString(entry_1.Key);
                keyIntType.Write(dataOut, key.Length);
                dataOut.Write(key);
                // Write the vector
                foreach (float v in entry_1.Value)
                {
                    dataOut.WriteShort(FromFloat(v));
                }
            }
        }
Ejemplo n.º 10
0
        public virtual void Marshal(DataOutputStream dos)
        {
            if (dos != null)
            {
                try
                {
                    dos.WriteUnsignedShort((ushort)this._parameterIndex);
                    dos.WriteShort((short)this._parameterValue);
                }
                catch (Exception e)
                {
                    if (PduBase.TraceExceptions)
                    {
                        Trace.WriteLine(e);
                        Trace.Flush();
                    }

                    this.RaiseExceptionOccured(e);

                    if (PduBase.ThrowExceptions)
                    {
                        throw e;
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public override void Marshal(DataOutputStream dos)
        {
            base.Marshal(dos);
            if (dos != null)
            {
                try
                {
                    this._receivingEntityID.Marshal(dos);
                    this._supplyingEntityID.Marshal(dos);
                    dos.WriteUnsignedByte((byte)this._supplies.Count);
                    dos.WriteShort((short)this._padding1);
                    dos.WriteByte((byte)this._padding2);

                    for (int idx = 0; idx < this._supplies.Count; idx++)
                    {
                        SupplyQuantity aSupplyQuantity = (SupplyQuantity)this._supplies[idx];
                        aSupplyQuantity.Marshal(dos);
                    }
                }
                catch (Exception e)
                {
#if DEBUG
                    Trace.WriteLine(e);
                    Trace.Flush();
#endif
                    this.OnException(e);
                }
            }
        }
Ejemplo n.º 12
0
        public override void Marshal(DataOutputStream dos)
        {
            base.Marshal(dos);
            if (dos != null)
            {
                try
                {
                    this._realWorldTime.Marshal(dos);
                    dos.WriteUnsignedByte((byte)this._reason);
                    dos.WriteUnsignedByte((byte)this._frozenBehavior);
                    dos.WriteShort((short)this._padding1);
                    dos.WriteUnsignedInt((uint)this._requestID);
                }
                catch (Exception e)
                {
                    if (PduBase.TraceExceptions)
                    {
                        Trace.WriteLine(e);
                        Trace.Flush();
                    }

                    this.RaiseExceptionOccured(e);

                    if (PduBase.ThrowExceptions)
                    {
                        throw e;
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public virtual void Marshal(DataOutputStream dos)
        {
            if (dos != null)
            {
                try
                {
                    this._beamDirection.Marshal(dos);
                    dos.WriteFloat((float)this._azimuthBeamwidth);
                    dos.WriteFloat((float)this._referenceSystem);
                    dos.WriteShort((short)this._padding1);
                    dos.WriteByte((byte)this._padding2);
                    dos.WriteFloat((float)this._ez);
                    dos.WriteFloat((float)this._ex);
                    dos.WriteFloat((float)this._phase);
                }
                catch (Exception e)
                {
                    if (PduBase.TraceExceptions)
                    {
                        Trace.WriteLine(e);
                        Trace.Flush();
                    }

                    this.RaiseExceptionOccured(e);

                    if (PduBase.ThrowExceptions)
                    {
                        throw e;
                    }
                }
            }
        }
Ejemplo n.º 14
0
        public override void Marshal(DataOutputStream dos)
        {
            base.Marshal(dos);
            if (dos != null)
            {
                try
                {
                    this._issuingEntityID.Marshal(dos);
                    this._collidingEntityID.Marshal(dos);
                    this._collisionEventID.Marshal(dos);
                    dos.WriteShort((short)this._pad);
                    this._contactVelocity.Marshal(dos);
                    dos.WriteFloat((float)this._mass);
                    this._locationOfImpact.Marshal(dos);
                    dos.WriteFloat((float)this._collisionIntermediateResultXX);
                    dos.WriteFloat((float)this._collisionIntermediateResultXY);
                    dos.WriteFloat((float)this._collisionIntermediateResultXZ);
                    dos.WriteFloat((float)this._collisionIntermediateResultYY);
                    dos.WriteFloat((float)this._collisionIntermediateResultYZ);
                    dos.WriteFloat((float)this._collisionIntermediateResultZZ);
                    this._unitSurfaceNormal.Marshal(dos);
                    dos.WriteFloat((float)this._coefficientOfRestitution);
                }
                catch (Exception e)
                {
#if DEBUG
                    Trace.WriteLine(e);
                    Trace.Flush();
#endif
                    this.OnException(e);
                }
            }
        }
Ejemplo n.º 15
0
            /// <summary>Write an integer of this type to the given output stream</summary>
            /// <exception cref="System.IO.IOException"/>
            public void Write(DataOutputStream @out, int value)
            {
                switch (this)
                {
                case VectorMap.Itype.Int8:
                {
                    @out.WriteByte(value);
                    break;
                }

                case VectorMap.Itype.Int16:
                {
                    @out.WriteShort(value);
                    break;
                }

                case VectorMap.Itype.Int32:
                {
                    @out.WriteInt(value);
                    break;
                }

                default:
                {
                    throw new Exception("Unknown itype: " + this);
                }
                }
            }
Ejemplo n.º 16
0
        public override void Marshal(DataOutputStream dos)
        {
            base.Marshal(dos);
            if (dos != null)
            {
                try
                {
                    this._originatingSimulationAddress.Marshal(dos);
                    dos.WriteInt((int)this._padding1);
                    dos.WriteShort((short)this._padding2);
                    dos.WriteUnsignedByte((byte)this._attributeRecordPduType);
                    dos.WriteUnsignedByte((byte)this._attributeRecordProtocolVersion);
                    dos.WriteUnsignedInt((uint)this._masterAttributeRecordType);
                    dos.WriteUnsignedByte((byte)this._actionCode);
                    dos.WriteByte((byte)this._padding3);
                    dos.WriteUnsignedShort((ushort)this._numberAttributeRecordSet);
                }
                catch (Exception e)
                {
#if DEBUG
                    Trace.WriteLine(e);
                    Trace.Flush();
#endif
                    this.OnException(e);
                }
            }
        }
Ejemplo n.º 17
0
        public virtual void Marshal(DataOutputStream dos)
        {
            if (dos != null)
            {
                try
                {
                    dos.WriteUnsignedByte((byte)this._protocolVersion);
                    dos.WriteUnsignedByte((byte)this._exerciseID);
                    dos.WriteUnsignedByte((byte)this._pduType);
                    dos.WriteUnsignedByte((byte)this._protocolFamily);
                    dos.WriteUnsignedInt((uint)this._timestamp);
                    dos.WriteUnsignedShort((ushort)this._length);
                    dos.WriteShort((short)this._padding);
                }
                catch (Exception e)
                {
                    if (PduBase.TraceExceptions)
                    {
                        Trace.WriteLine(e);
                        Trace.Flush();
                    }

                    this.RaiseExceptionOccured(e);

                    if (PduBase.ThrowExceptions)
                    {
                        throw e;
                    }
                }
            }
        }
Ejemplo n.º 18
0
        public override void Marshal(DataOutputStream dos)
        {
            base.Marshal(dos);
            if (dos != null)
            {
                try
                {
                    this._receivingEntityID.Marshal(dos);
                    this._repairingEntityID.Marshal(dos);
                    dos.WriteUnsignedByte((byte)this._repairResult);
                    dos.WriteShort((short)this._padding1);
                    dos.WriteByte((byte)this._padding2);
                }
                catch (Exception e)
                {
                    if (PduBase.TraceExceptions)
                    {
                        Trace.WriteLine(e);
                        Trace.Flush();
                    }

                    this.RaiseExceptionOccured(e);

                    if (PduBase.ThrowExceptions)
                    {
                        throw e;
                    }
                }
            }
        }
Ejemplo n.º 19
0
        public virtual void Marshal(DataOutputStream dos)
        {
            if (dos != null)
            {
                try
                {
                    this._beamDirection.Marshal(dos);
                    dos.WriteFloat((float)this._azimuthBeamwidth);
                    dos.WriteFloat((float)this._referenceSystem);
                    dos.WriteShort((short)this._padding1);
                    dos.WriteByte((byte)this._padding2);
                    dos.WriteFloat((float)this._ez);
                    dos.WriteFloat((float)this._ex);
                    dos.WriteFloat((float)this._phase);
                }
                catch (Exception e)
                {
#if DEBUG
                    Trace.WriteLine(e);
                    Trace.Flush();
#endif
                    this.OnException(e);
                }
            }
        }
Ejemplo n.º 20
0
 /// <exception cref="System.IO.IOException"/>
 public virtual void Write(DataOutputStream @out)
 {
     System.Diagnostics.Debug.Assert(proto.GetSerializedSize() <= MaxProtoSize, "Expected "
                                     + (MaxProtoSize) + " got: " + proto.GetSerializedSize());
     @out.WriteInt(packetLen);
     @out.WriteShort(proto.GetSerializedSize());
     proto.WriteTo(@out);
 }
Ejemplo n.º 21
0
        public virtual void Marshal(DataOutputStream dos)
        {
            if (dos != null)
            {
                try
                {
                    dos.WriteShort((short)this._currentShaftRPMs);
                    dos.WriteShort((short)this._orderedShaftRPMs);
                    dos.WriteFloat((float)this._shaftRPMRateOfChange);
                }
                catch (Exception e)
                {
#if DEBUG
                    Trace.WriteLine(e);
                    Trace.Flush();
#endif
                    this.OnException(e);
                }
            }
        }
Ejemplo n.º 22
0
        // Helper function that writes an INodeUnderConstruction
        // into the output stream
        //
        /// <exception cref="System.IO.IOException"/>
        internal static void WriteINodeUnderConstruction(DataOutputStream @out, INodeFile
                                                         cons, string path)
        {
            WriteString(path, @out);
            @out.WriteLong(cons.GetId());
            @out.WriteShort(cons.GetFileReplication());
            @out.WriteLong(cons.GetModificationTime());
            @out.WriteLong(cons.GetPreferredBlockSize());
            WriteBlocks(cons.GetBlocks(), @out);
            cons.GetPermissionStatus().Write(@out);
            FileUnderConstructionFeature uc = cons.GetFileUnderConstructionFeature();

            WriteString(uc.GetClientName(), @out);
            WriteString(uc.GetClientMachine(), @out);
            @out.WriteInt(0);
        }
Ejemplo n.º 23
0
        public virtual void Marshal(DataOutputStream dos)
        {
            if (dos != null)
            {
                try
                {
                    dos.WriteUnsignedShort((ushort)this._parameterIndex);
                    dos.WriteShort((short)this._parameterValue);
                }
                catch (Exception e)
                {
#if DEBUG
                    Trace.WriteLine(e);
                    Trace.Flush();
#endif
                    this.OnException(e);
                }
            }
        }
Ejemplo n.º 24
0
        public override void Marshal(DataOutputStream dos)
        {
            base.Marshal(dos);
            if (dos != null)
            {
                try
                {
                    this._issuingEntityID.Marshal(dos);
                    this._collidingEntityID.Marshal(dos);
                    this._collisionEventID.Marshal(dos);
                    dos.WriteShort((short)this._pad);
                    this._contactVelocity.Marshal(dos);
                    dos.WriteFloat((float)this._mass);
                    this._location.Marshal(dos);
                    dos.WriteFloat((float)this._collisionResultXX);
                    dos.WriteFloat((float)this._collisionResultXY);
                    dos.WriteFloat((float)this._collisionResultXZ);
                    dos.WriteFloat((float)this._collisionResultYY);
                    dos.WriteFloat((float)this._collisionResultYZ);
                    dos.WriteFloat((float)this._collisionResultZZ);
                    this._unitSurfaceNormal.Marshal(dos);
                    dos.WriteFloat((float)this._coefficientOfRestitution);
                }
                catch (Exception e)
                {
                    if (PduBase.TraceExceptions)
                    {
                        Trace.WriteLine(e);
                        Trace.Flush();
                    }

                    this.RaiseExceptionOccured(e);

                    if (PduBase.ThrowExceptions)
                    {
                        throw e;
                    }
                }
            }
        }
Ejemplo n.º 25
0
        public override void Marshal(DataOutputStream dos)
        {
            base.Marshal(dos);
            if (dos != null)
            {
                try
                {
                    this._receivingEntityID.Marshal(dos);
                    this._repairingEntityID.Marshal(dos);
                    dos.WriteUnsignedShort((ushort)this._repair);
                    dos.WriteShort((short)this._padding2);
                }
                catch (Exception e)
                {
#if DEBUG
                    Trace.WriteLine(e);
                    Trace.Flush();
#endif
                    this.OnException(e);
                }
            }
        }
Ejemplo n.º 26
0
        public virtual void Marshal(DataOutputStream dos)
        {
            if (dos != null)
            {
                try
                {
                    dos.WriteUnsignedByte((byte)this._protocolVersion);
                    dos.WriteUnsignedByte((byte)this._exerciseID);
                    dos.WriteUnsignedByte((byte)this._pduType);
                    dos.WriteUnsignedByte((byte)this._protocolFamily);
                    dos.WriteUnsignedInt((uint)this._timestamp);
                    dos.WriteUnsignedShort((ushort)this._length);
                    dos.WriteShort((short)this._padding);
                }
                catch (Exception e)
                {
#if DEBUG
                    Trace.WriteLine(e);
                    Trace.Flush();
#endif
                    this.OnException(e);
                }
            }
        }
Ejemplo n.º 27
0
        public override void Marshal(DataOutputStream dos)
        {
            base.Marshal(dos);
            if (dos != null)
            {
                try
                {
                    this._receivingEntityID.Marshal(dos);
                    this._supplyingEntityID.Marshal(dos);
                    dos.WriteUnsignedByte((byte)this._supplies.Count);
                    dos.WriteShort((short)this._padding1);
                    dos.WriteByte((byte)this._padding2);

                    for (int idx = 0; idx < this._supplies.Count; idx++)
                    {
                        SupplyQuantity aSupplyQuantity = (SupplyQuantity)this._supplies[idx];
                        aSupplyQuantity.Marshal(dos);
                    }
                }
                catch (Exception e)
                {
                    if (PduBase.TraceExceptions)
                    {
                        Trace.WriteLine(e);
                        Trace.Flush();
                    }

                    this.RaiseExceptionOccured(e);

                    if (PduBase.ThrowExceptions)
                    {
                        throw e;
                    }
                }
            }
        }
Ejemplo n.º 28
0
        internal void FlattenData(Stream os)
        {
            DataOutputStream dos = new DataOutputStream(os);
            int i;

            // Remove comments and whitespace from the rules to make it smaller.
            String strippedRules = IBM.ICU.Text.RBBIRuleScanner.StripRules(fRules);

            // Calculate the size of each section in the data in bytes.
            // Sizes here are padded up to a multiple of 8 for better memory
            // alignment.
            // Sections sizes actually stored in the header are for the actual data
            // without the padding.
            //
            int headerSize       = 24 * 4; // align8(sizeof(RBBIDataHeader));
            int forwardTableSize = Align8(fForwardTables.GetTableSize());
            int reverseTableSize = Align8(fReverseTables.GetTableSize());
            int safeFwdTableSize = Align8(fSafeFwdTables.GetTableSize());
            int safeRevTableSize = Align8(fSafeRevTables.GetTableSize());
            int trieSize         = Align8(fSetBuilder.GetTrieSize());
            int statusTableSize  = Align8(fRuleStatusVals.Count * 4);
            int rulesSize        = Align8((strippedRules.Length) * 2);
            int totalSize        = headerSize + forwardTableSize + reverseTableSize
                                   + safeFwdTableSize + safeRevTableSize + statusTableSize
                                   + trieSize + rulesSize;
            int outputPos = 0;     // Track stream position, starting from

            // RBBIDataHeader.

            //
            // Write out an ICU Data Header
            // TODO: actually create a real header, rather than just a placeholder.
            // The empty placeholder is ok for compile-and-go from within ICU4J.
            // Replicating the ICU4C genbrk tool for building .brk resources would
            // need a real header.
            //
            byte[] ICUDataHeader = new byte[0x80];
            dos.Write(ICUDataHeader, 0, ICUDataHeader.Length);

            //
            // Write out the RBBIDataHeader
            //
            int[] header = new int[IBM.ICU.Text.RBBIDataWrapper.DH_SIZE];     // sizeof struct
            // RBBIDataHeader
            header[IBM.ICU.Text.RBBIDataWrapper.DH_MAGIC]         = 0xb1a0;
            header[IBM.ICU.Text.RBBIDataWrapper.DH_FORMATVERSION] = 0x03010000; // uint8_t
            // fFormatVersion[4];
            header[IBM.ICU.Text.RBBIDataWrapper.DH_LENGTH] = totalSize;         // fLength, the total
            // size of all rule
            // sections.
            header[IBM.ICU.Text.RBBIDataWrapper.DH_CATCOUNT] = fSetBuilder
                                                               .GetNumCharCategories();      // fCatCount.
            header[IBM.ICU.Text.RBBIDataWrapper.DH_FTABLE]    = headerSize;                  // fFTable
            header[IBM.ICU.Text.RBBIDataWrapper.DH_FTABLELEN] = forwardTableSize;            // fTableLen
            header[IBM.ICU.Text.RBBIDataWrapper.DH_RTABLE]    = header[IBM.ICU.Text.RBBIDataWrapper.DH_FTABLE]
                                                                + forwardTableSize;          // fRTable
            header[IBM.ICU.Text.RBBIDataWrapper.DH_RTABLELEN] = reverseTableSize;            // fRTableLen
            header[IBM.ICU.Text.RBBIDataWrapper.DH_SFTABLE]   = header[IBM.ICU.Text.RBBIDataWrapper.DH_RTABLE]
                                                                + reverseTableSize;          // fSTable
            header[IBM.ICU.Text.RBBIDataWrapper.DH_SFTABLELEN] = safeFwdTableSize;           // fSTableLen
            header[IBM.ICU.Text.RBBIDataWrapper.DH_SRTABLE]    = header[IBM.ICU.Text.RBBIDataWrapper.DH_SFTABLE]
                                                                 + safeFwdTableSize;         // fSRTable
            header[IBM.ICU.Text.RBBIDataWrapper.DH_SRTABLELEN] = safeRevTableSize;           // fSRTableLen
            header[IBM.ICU.Text.RBBIDataWrapper.DH_TRIE]       = header[IBM.ICU.Text.RBBIDataWrapper.DH_SRTABLE]
                                                                 + safeRevTableSize;         // fTrie
            header[IBM.ICU.Text.RBBIDataWrapper.DH_TRIELEN]     = fSetBuilder.GetTrieSize(); // fTrieLen
            header[IBM.ICU.Text.RBBIDataWrapper.DH_STATUSTABLE] = header[IBM.ICU.Text.RBBIDataWrapper.DH_TRIE]
                                                                  + header[IBM.ICU.Text.RBBIDataWrapper.DH_TRIELEN];
            header[IBM.ICU.Text.RBBIDataWrapper.DH_STATUSTABLELEN] = statusTableSize;     // fStatusTableLen
            header[IBM.ICU.Text.RBBIDataWrapper.DH_RULESOURCE]     = header[IBM.ICU.Text.RBBIDataWrapper.DH_STATUSTABLE]
                                                                     + statusTableSize;
            header[IBM.ICU.Text.RBBIDataWrapper.DH_RULESOURCELEN] = strippedRules.Length * 2;
            for (i = 0; i < header.Length; i++)
            {
                dos.WriteInt(header[i]);
                outputPos += 4;
            }

            // Write out the actual state tables.
            short[] tableData;
            tableData = fForwardTables.ExportTable();
            IBM.ICU.Impl.Assert.Assrt(outputPos == header[4]);
            for (i = 0; i < tableData.Length; i++)
            {
                dos.WriteShort(tableData[i]);
                outputPos += 2;
            }

            tableData = fReverseTables.ExportTable();
            IBM.ICU.Impl.Assert.Assrt(outputPos == header[6]);
            for (i = 0; i < tableData.Length; i++)
            {
                dos.WriteShort(tableData[i]);
                outputPos += 2;
            }

            IBM.ICU.Impl.Assert.Assrt(outputPos == header[8]);
            tableData = fSafeFwdTables.ExportTable();
            for (i = 0; i < tableData.Length; i++)
            {
                dos.WriteShort(tableData[i]);
                outputPos += 2;
            }

            IBM.ICU.Impl.Assert.Assrt(outputPos == header[10]);
            tableData = fSafeRevTables.ExportTable();
            for (i = 0; i < tableData.Length; i++)
            {
                dos.WriteShort(tableData[i]);
                outputPos += 2;
            }

            // write out the Trie table
            IBM.ICU.Impl.Assert.Assrt(outputPos == header[12]);
            fSetBuilder.SerializeTrie(os);
            outputPos += header[13];
            while (outputPos % 8 != 0)       // pad to an 8 byte boundary
            {
                dos.WriteByte((byte)0);
                outputPos += 1;
            }

            // Write out the status {tag} table.
            IBM.ICU.Impl.Assert.Assrt(outputPos == header[16]);
            for (i = 0; i < fRuleStatusVals.Count; i++)
            {
                Int32 val = (Int32)fRuleStatusVals[i];
                dos.WriteInt(val);
                outputPos += 4;
            }

            while (outputPos % 8 != 0)       // pad to an 8 byte boundary
            {
                dos.WriteByte((byte)0);
                outputPos += 1;
            }

            // Write out the stripped rules (rules with extra spaces removed
            // These go last in the data area, even though they are not last in the
            // header.
            IBM.ICU.Impl.Assert.Assrt(outputPos == header[14]);
            dos.WriteChars(strippedRules);
            outputPos += strippedRules.Length * 2;
            while (outputPos % 8 != 0)       // pad to an 8 byte boundary
            {
                dos.WriteByte((byte)0);
                outputPos += 1;
            }
        }
Ejemplo n.º 29
0
        public virtual void TestDataTransferProtocol()
        {
            Random        random       = new Random();
            int           oneMil       = 1024 * 1024;
            Path          file         = new Path("dataprotocol.dat");
            int           numDataNodes = 1;
            Configuration conf         = new HdfsConfiguration();

            conf.SetInt(DFSConfigKeys.DfsReplicationKey, numDataNodes);
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(numDataNodes
                                                                                   ).Build();

            try
            {
                cluster.WaitActive();
                datanode = cluster.GetFileSystem().GetDataNodeStats(HdfsConstants.DatanodeReportType
                                                                    .Live)[0];
                dnAddr = NetUtils.CreateSocketAddr(datanode.GetXferAddr());
                FileSystem fileSys = cluster.GetFileSystem();
                int        fileLen = Math.Min(conf.GetInt(DFSConfigKeys.DfsBlockSizeKey, 4096), 4096);
                CreateFile(fileSys, file, fileLen);
                // get the first blockid for the file
                ExtendedBlock firstBlock = DFSTestUtil.GetFirstBlock(fileSys, file);
                string        poolId     = firstBlock.GetBlockPoolId();
                long          newBlockId = firstBlock.GetBlockId() + 1;
                recvBuf.Reset();
                sendBuf.Reset();
                // bad version
                recvOut.WriteShort((short)(DataTransferProtocol.DataTransferVersion - 1));
                sendOut.WriteShort((short)(DataTransferProtocol.DataTransferVersion - 1));
                SendRecvData("Wrong Version", true);
                // bad ops
                sendBuf.Reset();
                sendOut.WriteShort((short)DataTransferProtocol.DataTransferVersion);
                sendOut.WriteByte(OP.WriteBlock.code - 1);
                SendRecvData("Wrong Op Code", true);
                /* Test OP_WRITE_BLOCK */
                sendBuf.Reset();
                DataChecksum badChecksum = Org.Mockito.Mockito.Spy(DefaultChecksum);
                Org.Mockito.Mockito.DoReturn(-1).When(badChecksum).GetBytesPerChecksum();
                WriteBlock(poolId, newBlockId, badChecksum);
                recvBuf.Reset();
                SendResponse(DataTransferProtos.Status.Error, null, null, recvOut);
                SendRecvData("wrong bytesPerChecksum while writing", true);
                sendBuf.Reset();
                recvBuf.Reset();
                WriteBlock(poolId, ++newBlockId, DefaultChecksum);
                PacketHeader hdr = new PacketHeader(4, 0, 100, false, -1 - random.Next(oneMil), false
                                                    );
                // size of packet
                // offset in block,
                // seqno
                // last packet
                // bad datalen
                hdr.Write(sendOut);
                SendResponse(DataTransferProtos.Status.Success, string.Empty, null, recvOut);
                new PipelineAck(100, new int[] { PipelineAck.CombineHeader(PipelineAck.ECN.Disabled
                                                                           , DataTransferProtos.Status.Error) }).Write(recvOut);
                SendRecvData("negative DATA_CHUNK len while writing block " + newBlockId, true);
                // test for writing a valid zero size block
                sendBuf.Reset();
                recvBuf.Reset();
                WriteBlock(poolId, ++newBlockId, DefaultChecksum);
                hdr = new PacketHeader(8, 0, 100, true, 0, false);
                // size of packet
                // OffsetInBlock
                // sequencenumber
                // lastPacketInBlock
                // chunk length
                hdr.Write(sendOut);
                sendOut.WriteInt(0);
                // zero checksum
                sendOut.Flush();
                //ok finally write a block with 0 len
                SendResponse(DataTransferProtos.Status.Success, string.Empty, null, recvOut);
                new PipelineAck(100, new int[] { PipelineAck.CombineHeader(PipelineAck.ECN.Disabled
                                                                           , DataTransferProtos.Status.Success) }).Write(recvOut);
                SendRecvData("Writing a zero len block blockid " + newBlockId, false);
                /* Test OP_READ_BLOCK */
                string        bpid  = cluster.GetNamesystem().GetBlockPoolId();
                ExtendedBlock blk   = new ExtendedBlock(bpid, firstBlock.GetLocalBlock());
                long          blkid = blk.GetBlockId();
                // bad block id
                sendBuf.Reset();
                recvBuf.Reset();
                blk.SetBlockId(blkid - 1);
                sender.ReadBlock(blk, BlockTokenSecretManager.DummyToken, "cl", 0L, fileLen, true
                                 , CachingStrategy.NewDefaultStrategy());
                SendRecvData("Wrong block ID " + newBlockId + " for read", false);
                // negative block start offset -1L
                sendBuf.Reset();
                blk.SetBlockId(blkid);
                sender.ReadBlock(blk, BlockTokenSecretManager.DummyToken, "cl", -1L, fileLen, true
                                 , CachingStrategy.NewDefaultStrategy());
                SendRecvData("Negative start-offset for read for block " + firstBlock.GetBlockId(
                                 ), false);
                // bad block start offset
                sendBuf.Reset();
                sender.ReadBlock(blk, BlockTokenSecretManager.DummyToken, "cl", fileLen, fileLen,
                                 true, CachingStrategy.NewDefaultStrategy());
                SendRecvData("Wrong start-offset for reading block " + firstBlock.GetBlockId(), false
                             );
                // negative length is ok. Datanode assumes we want to read the whole block.
                recvBuf.Reset();
                ((DataTransferProtos.BlockOpResponseProto)DataTransferProtos.BlockOpResponseProto
                 .NewBuilder().SetStatus(DataTransferProtos.Status.Success).SetReadOpChecksumInfo
                     (DataTransferProtos.ReadOpChecksumInfoProto.NewBuilder().SetChecksum(DataTransferProtoUtil
                                                                                          .ToProto(DefaultChecksum)).SetChunkOffset(0L)).Build()).WriteDelimitedTo(recvOut
                                                                                                                                                                   );
                sendBuf.Reset();
                sender.ReadBlock(blk, BlockTokenSecretManager.DummyToken, "cl", 0L, -1L - random.
                                 Next(oneMil), true, CachingStrategy.NewDefaultStrategy());
                SendRecvData("Negative length for reading block " + firstBlock.GetBlockId(), false
                             );
                // length is more than size of block.
                recvBuf.Reset();
                SendResponse(DataTransferProtos.Status.Error, null, "opReadBlock " + firstBlock +
                             " received exception java.io.IOException:  " + "Offset 0 and length 4097 don't match block "
                             + firstBlock + " ( blockLen 4096 )", recvOut);
                sendBuf.Reset();
                sender.ReadBlock(blk, BlockTokenSecretManager.DummyToken, "cl", 0L, fileLen + 1,
                                 true, CachingStrategy.NewDefaultStrategy());
                SendRecvData("Wrong length for reading block " + firstBlock.GetBlockId(), false);
                //At the end of all this, read the file to make sure that succeeds finally.
                sendBuf.Reset();
                sender.ReadBlock(blk, BlockTokenSecretManager.DummyToken, "cl", 0L, fileLen, true
                                 , CachingStrategy.NewDefaultStrategy());
                ReadFile(fileSys, file, fileLen);
            }
            finally
            {
                cluster.Shutdown();
            }
        }
Ejemplo n.º 30
0
 public static void WriteHeader(DataOutputStream @out, Org.Apache.Hadoop.Hdfs.Server.Datanode.BlockMetadataHeader
                                header)
 {
     @out.WriteShort(header.GetVersion());
     header.GetChecksum().WriteHeader(@out);
 }