public override void Unmarshal(DataInputStream dis)
        {
            base.Unmarshal(dis);

            if (dis != null)
            {
                try
                {
                    this._designatingEntityID.Unmarshal(dis);
                    this._codeName = dis.ReadUnsignedShort();
                    this._designatedEntityID.Unmarshal(dis);
                    this._designatorCode       = dis.ReadUnsignedShort();
                    this._designatorPower      = dis.ReadFloat();
                    this._designatorWavelength = dis.ReadFloat();
                    this._designatorSpotWrtDesignated.Unmarshal(dis);
                    this._designatorSpotLocation.Unmarshal(dis);
                    this._deadReckoningAlgorithm = dis.ReadByte();
                    this._padding1 = dis.ReadUnsignedShort();
                    this._padding2 = dis.ReadByte();
                    this._entityLinearAcceleration.Unmarshal(dis);
                }
                catch (Exception e)
                {
#if DEBUG
                    Trace.WriteLine(e);
                    Trace.Flush();
#endif
                    this.OnException(e);
                }
            }
        }
Exemple #2
0
        public override void Unmarshal(DataInputStream dis)
        {
            base.Unmarshal(dis);

            if (dis != null)
            {
                try
                {
                    this._emittingEntityID.Unmarshal(dis);
                    this._eventID.Unmarshal(dis);
                    this._stateChangeIndicator = dis.ReadByte();
                    this._pad = dis.ReadByte();
                    this._passiveParameterIndex        = dis.ReadUnsignedShort();
                    this._propulsionPlantConfiguration = dis.ReadUnsignedByte();
                    this._numberOfShafts           = dis.ReadUnsignedByte();
                    this._numberOfAPAs             = dis.ReadUnsignedByte();
                    this._numberOfUAEmitterSystems = dis.ReadUnsignedByte();

                    for (int idx = 0; idx < this.NumberOfShafts; idx++)
                    {
                        ShaftRPMs anX = new ShaftRPMs();
                        anX.Unmarshal(dis);
                        this._shaftRPMs.Add(anX);
                    }

                    for (int idx = 0; idx < this.NumberOfAPAs; idx++)
                    {
                        ApaData anX = new ApaData();
                        anX.Unmarshal(dis);
                        this._apaData.Add(anX);
                    }

                    for (int idx = 0; idx < this.NumberOfUAEmitterSystems; idx++)
                    {
                        AcousticEmitterSystemData anX = new AcousticEmitterSystemData();
                        anX.Unmarshal(dis);
                        this._emitterSystems.Add(anX);
                    }
                }
                catch (Exception e)
                {
                    if (PduBase.TraceExceptions)
                    {
                        Trace.WriteLine(e);
                        Trace.Flush();
                    }

                    this.RaiseExceptionOccured(e);

                    if (PduBase.ThrowExceptions)
                    {
                        throw e;
                    }
                }
            }
        }
        public void handle(byte[] data, model.RtpMidiServer appleMidiServer)
        {
            DataInputStream dataInputStream = new DataInputStream(new MemoryStream(data));

            try {
                byte header1 = (byte)dataInputStream.ReadByte();
                if (header1 != RtpMidiCommand.MIDI_COMMAND_HEADER1)
                {
                    Log.Info("RtpMidi", "Header did not contain first MIDI command header");
                    return;
                }
                byte header2 = (byte)dataInputStream.ReadByte();
                if (header2 != RtpMidiCommand.MIDI_COMMAND_HEADER2)
                {
                    Log.Info("RtpMidi", "Header did not contain second MIDI command header");
                    return;
                }
                byte[] commandBuffer    = new byte[COMMAND_BUFFER_LENGTH];
                int    commandBytesRead = dataInputStream.Read(commandBuffer);
                if (commandBytesRead != COMMAND_BUFFER_LENGTH)
                {
                    Log.Info("RtpMidi", "The number of command bytes: {} did not match: {}", commandBytesRead, COMMAND_BUFFER_LENGTH);
                    return;
                }
                string      command = Encoding.UTF8.GetString(commandBuffer);
                CommandWord commandWord;
                try
                {
                    commandWord = (CommandWord)System.Enum.Parse(typeof(CommandWord), command);
                }
                catch (IllegalArgumentException e) {
                    Log.Info("RtpMidi", "Could not parse command word from: {}", command);
                    return;
                }
                switch (commandWord)
                {
                case CommandWord.IN:
                    HandleInvitation(dataInputStream, appleMidiServer);
                    break;

                case CommandWord.CK:
                    HandleSynchronization(dataInputStream, appleMidiServer);
                    break;

                case CommandWord.BY:
                    HandleEndSession(dataInputStream, appleMidiServer);
                    break;
                }
            }
            catch (System.IO.IOException e)
            {
                Log.Error("RtpMidi", "IOException while parsing message", e);
            }
        }
Exemple #4
0
        /// <summary>
        /// Reads four bytes from the input and returns a VersionInfo object. Use it
        /// to read different collator versions.
        /// </summary>
        ///
        /// <param name="input">already instantiated DataInputStream, positioned at the startof four version bytes</param>
        /// <returns>a ready VersionInfo object</returns>
        /// <exception cref="IOException">thrown when error occurs while reading version bytes</exception>

        protected static internal VersionInfo ReadVersion(DataInputStream input)
        {
            sbyte[] version = new sbyte[4];
            version[0] = input.ReadByte();
            version[1] = input.ReadByte();
            version[2] = input.ReadByte();
            version[3] = input.ReadByte();

            VersionInfo result = IBM.ICU.Util.VersionInfo.GetInstance((int)version[0],
                                                                      (int)version[1], (int)version[2], (int)version[3]);

            return(result);
        }
Exemple #5
0
        public override void Unmarshal(DataInputStream dis)
        {
            base.Unmarshal(dis);

            if (dis != null)
            {
                try
                {
                    this._emittingEntityID.Unmarshal(dis);
                    this._eventID.Unmarshal(dis);
                    this._stateChangeIndicator = dis.ReadByte();
                    this._pad = dis.ReadByte();
                    this._passiveParameterIndex        = dis.ReadUnsignedShort();
                    this._propulsionPlantConfiguration = dis.ReadUnsignedByte();
                    this._numberOfShafts           = dis.ReadUnsignedByte();
                    this._numberOfAPAs             = dis.ReadUnsignedByte();
                    this._numberOfUAEmitterSystems = dis.ReadUnsignedByte();
                    for (int idx = 0; idx < this.NumberOfShafts; idx++)
                    {
                        Vector3Float anX = new Vector3Float();
                        anX.Unmarshal(dis);
                        this._shaftRPMs.Add(anX);
                    }
                    ;

                    for (int idx = 0; idx < this.NumberOfAPAs; idx++)
                    {
                        Vector3Float anX = new Vector3Float();
                        anX.Unmarshal(dis);
                        this._apaData.Add(anX);
                    }
                    ;

                    for (int idx = 0; idx < this.NumberOfUAEmitterSystems; idx++)
                    {
                        Vector3Float anX = new Vector3Float();
                        anX.Unmarshal(dis);
                        this._emitterSystems.Add(anX);
                    }
                    ;
                }
                catch (Exception e)
                {
#if DEBUG
                    Trace.WriteLine(e);
                    Trace.Flush();
#endif
                    this.OnException(e);
                }
            }
        }
Exemple #6
0
        private int ReadDeltaTime(DataInputStream midiInputStream)
        {
            byte deltaTimeOctet = (byte)midiInputStream.ReadByte();
            int  deltaTime      = deltaTimeOctet & 0x7F;
            int  numberOfOctets = 1;

            while (((deltaTimeOctet >> 7) & 0x01) == 1 || numberOfOctets < 4)
            {
                numberOfOctets++;
                deltaTimeOctet = (byte)midiInputStream.ReadByte();
                deltaTime      = ((deltaTimeOctet << 8) & 0x7F) | deltaTimeOctet;
            }
            return(deltaTime);
        }
        public override void Unmarshal(DataInputStream dis)
        {
            base.Unmarshal(dis);

            if (dis != null)
            {
                try
                {
                    this._entityID.Unmarshal(dis);
                    this._forceId = dis.ReadUnsignedByte();
                    this._articulationParameterCount = dis.ReadByte();
                    this._entityType.Unmarshal(dis);
                    this._alternativeEntityType.Unmarshal(dis);
                    this._entityLinearVelocity.Unmarshal(dis);
                    this._entityLocation.Unmarshal(dis);
                    this._entityOrientation.Unmarshal(dis);
                    this._entityAppearance = dis.ReadInt();
                    this._deadReckoningParameters.Unmarshal(dis);

                    for (int idx = 0; idx < this._marking.Length; idx++)
                    {
                        this._marking[idx] = dis.ReadByte();
                    }

                    this._capabilities = dis.ReadInt();

                    for (int idx = 0; idx < this.ArticulationParameterCount; idx++)
                    {
                        ArticulationParameter anX = new ArticulationParameter();
                        anX.Unmarshal(dis);
                        this._articulationParameters.Add(anX);
                    }
                }
                catch (Exception e)
                {
                    if (PduBase.TraceExceptions)
                    {
                        Trace.WriteLine(e);
                        Trace.Flush();
                    }

                    this.RaiseExceptionOccured(e);

                    if (PduBase.ThrowExceptions)
                    {
                        throw e;
                    }
                }
            }
        }
Exemple #8
0
        // private methods ---------------------------------------------------

        /// <summary>
        /// Reads an individual record of AlgorithmNames
        /// </summary>
        ///
        /// <returns>an instance of AlgorithNames if read is successful otherwise null</returns>
        /// <exception cref="IOException">thrown when file read error occurs or data is corrupted</exception>
        private UCharacterName.AlgorithmName ReadAlg()
        {
            UCharacterName.AlgorithmName result = new UCharacterName.AlgorithmName();
            int   rangestart = m_dataInputStream_.ReadInt();
            int   rangeend   = m_dataInputStream_.ReadInt();
            sbyte type       = m_dataInputStream_.ReadByte();
            sbyte variant    = m_dataInputStream_.ReadByte();

            if (!result.SetInfo(rangestart, rangeend, type, variant))
            {
                return(null);
            }

            int size = m_dataInputStream_.ReadChar();

            if (type == IBM.ICU.Impl.UCharacterName.AlgorithmName.TYPE_1_)
            {
                char[] factor = new char[variant];
                for (int j = 0; j < variant; j++)
                {
                    factor[j] = m_dataInputStream_.ReadChar();
                }

                result.SetFactor(factor);
                size -= (variant << 1);
            }

            StringBuilder prefix = new StringBuilder();
            char          c      = (char)(m_dataInputStream_.ReadByte() & 0x00FF);

            while (c != 0)
            {
                prefix.Append(c);
                c = (char)(m_dataInputStream_.ReadByte() & 0x00FF);
            }

            result.SetPrefix(prefix.ToString());

            size -= (ALG_INFO_SIZE_ + prefix.Length + 1);

            if (size > 0)
            {
                byte[] str0 = new byte[size];
                m_dataInputStream_.ReadFully(str0);
                result.SetFactorString(str0);
            }
            return(result);
        }
        public override void Unmarshal(DataInputStream dis)
        {
            base.Unmarshal(dis);

            if (dis != null)
            {
                try
                {
                    this._receivingEntityID.Unmarshal(dis);
                    this._supplyingEntityID.Unmarshal(dis);
                    this._numberOfSupplyTypes = dis.ReadUnsignedByte();
                    this._padding1            = dis.ReadShort();
                    this._padding2            = dis.ReadByte();
                    for (int idx = 0; idx < this.NumberOfSupplyTypes; idx++)
                    {
                        SupplyQuantity anX = new SupplyQuantity();
                        anX.Unmarshal(dis);
                        this._supplies.Add(anX);
                    }
                    ;
                }
                catch (Exception e)
                {
#if DEBUG
                    Trace.WriteLine(e);
                    Trace.Flush();
#endif
                    this.OnException(e);
                }
            }
        }
        public virtual void Unmarshal(DataInputStream dis)
        {
            if (dis != null)
            {
                try
                {
                    this._deadReckoningAlgorithm = dis.ReadUnsignedByte();

                    for (int idx = 0; idx < this._otherParameters.Length; idx++)
                    {
                        this._otherParameters[idx] = dis.ReadByte();
                    }

                    this._entityLinearAcceleration.Unmarshal(dis);
                    this._entityAngularVelocity.Unmarshal(dis);
                }
                catch (Exception e)
                {
                    if (PduBase.TraceExceptions)
                    {
                        Trace.WriteLine(e);
                        Trace.Flush();
                    }

                    this.RaiseExceptionOccured(e);

                    if (PduBase.ThrowExceptions)
                    {
                        throw e;
                    }
                }
            }
        }
        public virtual void Unmarshal(DataInputStream dis)
        {
            if (dis != null)
            {
                try
                {
                    this._beamDirection.Unmarshal(dis);
                    this._azimuthBeamwidth = dis.ReadFloat();
                    this._referenceSystem  = dis.ReadFloat();
                    this._padding1         = dis.ReadShort();
                    this._padding2         = dis.ReadByte();
                    this._ez    = dis.ReadFloat();
                    this._ex    = dis.ReadFloat();
                    this._phase = dis.ReadFloat();
                }
                catch (Exception e)
                {
                    if (PduBase.TraceExceptions)
                    {
                        Trace.WriteLine(e);
                        Trace.Flush();
                    }

                    this.RaiseExceptionOccured(e);

                    if (PduBase.ThrowExceptions)
                    {
                        throw e;
                    }
                }
            }
        }
Exemple #12
0
 /*
  * Reads the information from the index and data files.
  *
  * @param index holds the sprite indices
  * @param data  holds the sprite data per index
  * @throws IOException
  */
 public void readValues(DataInputStream index, DataInputStream data)
 {
     do
     {
         int opCode = data.ReadByte();
         if (opCode == 0)
         {
             break;
         }
         if (opCode == 1)
         {
             id = data.ReadShort();
         }
         else if (opCode == 2)
         {
             name = data.ReadUTF();
         }
         else if (opCode == 3)
         {
             drawOffsetX = data.ReadShort();
         }
         else if (opCode == 4)
         {
             drawOffsetY = data.ReadShort();
         }
         else if (opCode == 5)
         {
             int    indexLength = index.ReadInt();
             byte[] dataread    = new byte[indexLength];
             data.Read(dataread, 0, indexLength);
             spriteData = dataread;
         }
     } while (true);
 }
Exemple #13
0
        public override void Unmarshal(DataInputStream dis)
        {
            base.Unmarshal(dis);

            if (dis != null)
            {
                try
                {
                    this._issuingEntityID.Unmarshal(dis);
                    this._collidingEntityID.Unmarshal(dis);
                    this._eventID.Unmarshal(dis);
                    this._collisionType = dis.ReadUnsignedByte();
                    this._pad           = dis.ReadByte();
                    this._velocity.Unmarshal(dis);
                    this._mass = dis.ReadFloat();
                    this._location.Unmarshal(dis);
                }
                catch (Exception e)
                {
#if DEBUG
                    Trace.WriteLine(e);
                    Trace.Flush();
#endif
                    this.OnException(e);
                }
            }
        }
Exemple #14
0
        public override void Unmarshal(DataInputStream dis)
        {
            base.Unmarshal(dis);

            if (dis != null)
            {
                try
                {
                    this._receivingEntityID.Unmarshal(dis);
                    this._repairingEntityID.Unmarshal(dis);
                    this._repairResult = dis.ReadUnsignedByte();
                    this._padding1     = dis.ReadShort();
                    this._padding2     = dis.ReadByte();
                }
                catch (Exception e)
                {
                    if (PduBase.TraceExceptions)
                    {
                        Trace.WriteLine(e);
                        Trace.Flush();
                    }

                    this.RaiseExceptionOccured(e);

                    if (PduBase.ThrowExceptions)
                    {
                        throw e;
                    }
                }
            }
        }
Exemple #15
0
        public virtual void TestLocalFileCorruption()
        {
            Configuration    conf = new HdfsConfiguration();
            Path             file = new Path(PathUtils.GetTestDirName(GetType()), "corruptFile");
            FileSystem       fs   = FileSystem.GetLocal(conf);
            DataOutputStream dos  = fs.Create(file);

            dos.WriteBytes("original bytes");
            dos.Close();
            // Now deliberately corrupt the file
            dos = new DataOutputStream(new FileOutputStream(file.ToString()));
            dos.WriteBytes("corruption");
            dos.Close();
            // Now attempt to read the file
            DataInputStream dis = fs.Open(file, 512);

            try
            {
                System.Console.Out.WriteLine("A ChecksumException is expected to be logged.");
                dis.ReadByte();
            }
            catch (ChecksumException)
            {
            }
            //expect this exception but let any NPE get thrown
            fs.Delete(file, true);
        }
Exemple #16
0
            /// <summary>Read an integer of this type from the given input stream</summary>
            /// <exception cref="System.IO.IOException"/>
            public int Read(DataInputStream @in)
            {
                switch (this)
                {
                case VectorMap.Itype.Int8:
                {
                    return(@in.ReadByte());
                }

                case VectorMap.Itype.Int16:
                {
                    return(@in.ReadShort());
                }

                case VectorMap.Itype.Int32:
                {
                    return(@in.ReadInt());
                }

                default:
                {
                    throw new Exception("Unknown itype: " + this);
                }
                }
            }
Exemple #17
0
        public override void Unmarshal(DataInputStream dis)
        {
            base.Unmarshal(dis);

            if (dis != null)
            {
                try
                {
                    this._entityID.Unmarshal(dis);
                    this._padding1 = dis.ReadByte();
                    this._numberOfVariableParameters = dis.ReadUnsignedByte();
                    this._entityLinearVelocity.Unmarshal(dis);
                    this._entityLocation.Unmarshal(dis);
                    this._entityOrientation.Unmarshal(dis);
                    this._entityAppearance = dis.ReadUnsignedInt();
                    for (int idx = 0; idx < this.NumberOfVariableParameters; idx++)
                    {
                        VariableParameter anX = new VariableParameter();
                        anX.Unmarshal(dis);
                        this._variableParameters.Add(anX);
                    }
                    ;
                }
                catch (Exception e)
                {
#if DEBUG
                    Trace.WriteLine(e);
                    Trace.Flush();
#endif
                    this.OnException(e);
                }
            }
        }
Exemple #18
0
        /// <summary>
        /// Reads an automaton from a byte stream.
        /// </summary>
        /// <param name="stream">The stream to read.</param>
        internal CFSA2(Stream stream)
        {
            using (DataInputStream input = new DataInputStream(stream, true))
            {
                // Read flags.
                ushort flagBits = (ushort)input.ReadInt16();
                flags = 0;
                flags = (FSAFlags)flagBits;

                if (flagBits != (ushort)flags)
                {
                    throw new IOException($"Unrecognized flags: 0x{((int)flagBits).ToHexString()}");
                }

                this.hasNumbers = (flags & FSAFlags.Numbers) != 0;

                /*
                 * Read mapping dictionary.
                 */
                int labelMappingSize = input.ReadByte() & 0xff;

                LabelMapping = new byte[labelMappingSize];

                input.ReadFully(LabelMapping);

                /*
                 * Read arcs' data.
                 */
                Arcs = ReadRemaining(input);
            }
        }
        public virtual void Unmarshal(DataInputStream dis)
        {
            if (dis != null)
            {
                try
                {
                    this._beamDirection.Unmarshal(dis);
                    this._azimuthBeamwidth = dis.ReadFloat();
                    this._referenceSystem  = dis.ReadFloat();
                    this._padding1         = dis.ReadShort();
                    this._padding2         = dis.ReadByte();
                    this._ez    = dis.ReadFloat();
                    this._ex    = dis.ReadFloat();
                    this._phase = dis.ReadFloat();
                }
                catch (Exception e)
                {
#if DEBUG
                    Trace.WriteLine(e);
                    Trace.Flush();
#endif
                    this.OnException(e);
                }
            }
        }
        public virtual void Unmarshal(DataInputStream dis)
        {
            if (dis != null)
            {
                try
                {
                    this._order = dis.ReadByte();
                }
                catch (Exception e)
                {
                    if (PduBase.TraceExceptions)
                    {
                        Trace.WriteLine(e);
                        Trace.Flush();
                    }

                    this.RaiseExceptionOccured(e);

                    if (PduBase.ThrowExceptions)
                    {
                        throw e;
                    }
                }
            }
        }
Exemple #21
0
        public override void Unmarshal(DataInputStream dis)
        {
            base.Unmarshal(dis);

            if (dis != null)
            {
                try
                {
                    this._originatingSimulationAddress.Unmarshal(dis);
                    this._padding1 = dis.ReadInt();
                    this._padding2 = dis.ReadShort();
                    this._attributeRecordPduType         = dis.ReadUnsignedByte();
                    this._attributeRecordProtocolVersion = dis.ReadUnsignedByte();
                    this._masterAttributeRecordType      = dis.ReadUnsignedInt();
                    this._actionCode = dis.ReadUnsignedByte();
                    this._padding3   = dis.ReadByte();
                    this._numberAttributeRecordSet = dis.ReadUnsignedShort();
                }
                catch (Exception e)
                {
#if DEBUG
                    Trace.WriteLine(e);
                    Trace.Flush();
#endif
                    this.OnException(e);
                }
            }
        }
Exemple #22
0
        public override void Unmarshal(DataInputStream dis)
        {
            base.Unmarshal(dis);

            if (dis != null)
            {
                try
                {
                    this._issuingEntityID.Unmarshal(dis);
                    this._collidingEntityID.Unmarshal(dis);
                    this._eventID.Unmarshal(dis);
                    this._collisionType = dis.ReadUnsignedByte();
                    this._pad           = dis.ReadByte();
                    this._velocity.Unmarshal(dis);
                    this._mass = dis.ReadFloat();
                    this._location.Unmarshal(dis);
                }
                catch (Exception e)
                {
                    if (PduBase.TraceExceptions)
                    {
                        Trace.WriteLine(e);
                        Trace.Flush();
                    }

                    this.RaiseExceptionOccured(e);

                    if (PduBase.ThrowExceptions)
                    {
                        throw e;
                    }
                }
            }
        }
Exemple #23
0
        public virtual void Unmarshal(DataInputStream dis)
        {
            if (dis != null)
            {
                try
                {
                    for (int idx = 0; idx < this._otherParameters.Length; idx++)
                    {
                        this._otherParameters[idx] = dis.ReadByte();
                    }
                }
                catch (Exception e)
                {
                    if (PduBase.TraceExceptions)
                    {
                        Trace.WriteLine(e);
                        Trace.Flush();
                    }

                    this.RaiseExceptionOccured(e);

                    if (PduBase.ThrowExceptions)
                    {
                        throw e;
                    }
                }
            }
        }
Exemple #24
0
 /// <summary>
 /// 读取Byte[]
 /// </summary>
 ///
 /// <param name="dis"></param>
 /// <param name="readLength"></param>
 /// <returns></returns>
 /// <exception cref="System.Exception"></exception>
 public static byte[] ReadByteArray(DataInputStream dis, int readLength)
 {
     byte[] readBytes = new byte[readLength];
     for (int i = 0; i < readLength; i++)
     {
         readBytes[i] = (byte)dis.ReadByte();
     }
     return(readBytes);
 }
Exemple #25
0
        // public methods --------------------------------------------------------

        /// <summary>
        /// <p>
        /// ICU data header reader method. Takes a ICU generated big-endian input
        /// stream, parse the ICU standard file header and authenticates them.
        /// </p>
        /// <p>
        /// Header format:
        /// <ul>
        /// <li>Header size (char)
        /// <li>Magic number 1 (byte)
        /// <li>Magic number 2 (byte)
        /// <li>Rest of the header size (char)
        /// <li>Reserved word (char)
        /// <li>Big endian indicator (byte)
        /// <li>Character set family indicator (byte)
        /// <li>Size of a char (byte) for c++ and c use
        /// <li>Reserved byte (byte)
        /// <li>Data format identifier (4 bytes), each ICU data has its own
        /// identifier to distinguish them. [0] major [1] minor [2] milli [3] micro
        /// <li>Data version (4 bytes), the change version of the ICU data [0] major
        /// [1] minor [2] milli [3] micro
        /// <li>Unicode version (4 bytes) this ICU is based on.
        /// </ul>
        /// </p>
        /// <p>
        /// Example of use:<br>
        /// <pre>
        /// try {
        /// FileInputStream input = new FileInputStream(filename);
        /// If (Utility.readICUDataHeader(input, dataformat, dataversion,
        /// unicode) {
        /// System.out.println("Verified file header, this is a ICU data file");
        /// }
        /// } catch (IOException e) {
        /// System.out.println("This is not a ICU data file");
        /// }
        /// </pre>
        /// </p>
        /// </summary>
        ///
        /// <param name="inputStream">input stream that contains the ICU data header</param>
        /// <param name="dataFormatIDExpected">Data format expected. An array of 4 bytes information aboutthe data format. E.g. data format ID 1.2.3.4. will became anarray of {1, 2, 3, 4}</param>
        /// <param name="authenticate">user defined extra data authentication. This value can benull, if no extra authentication is needed.</param>
        /// <exception cref="IOException">thrown if there is a read error or when headerauthentication fails.</exception>
        /// @draft 2.1
        public static byte[] ReadHeader(Stream inputStream,
                                        byte[] dataFormatIDExpected, ICUBinary.Authenticate authenticate)
        {
            DataInputStream input      = new DataInputStream(inputStream);
            char            headersize = input.ReadChar();
            int             readcount  = 2;
            // reading the header format
            byte magic1 = (byte)input.ReadByte();

            readcount++;
            byte magic2 = (byte)input.ReadByte();

            readcount++;
            if (magic1 != MAGIC1 || magic2 != MAGIC2)
            {
                throw new IOException(MAGIC_NUMBER_AUTHENTICATION_FAILED_);
            }

            input.ReadChar();     // reading size
            readcount += 2;
            input.ReadChar();     // reading reserved word
            readcount += 2;
            sbyte bigendian = input.ReadByte();

            readcount++;
            sbyte charset = input.ReadByte();

            readcount++;
            sbyte charsize = input.ReadByte();

            readcount++;
            input.ReadByte();     // reading reserved byte
            readcount++;

            byte[] dataFormatID = new byte[4];
            input.ReadFully(dataFormatID);
            readcount += 4;
            byte[] dataVersion = new byte[4];
            input.ReadFully(dataVersion);
            readcount += 4;
            byte[] unicodeVersion = new byte[4];
            input.ReadFully(unicodeVersion);
            readcount += 4;
            if (headersize < readcount)
            {
                throw new IOException("Internal Error: Header size error");
            }
            input.SkipBytes(headersize - readcount);

            if (bigendian != BIG_ENDIAN_ ||
                charset != CHAR_SET_ ||
                charsize != CHAR_SIZE_ ||
                !ILOG.J2CsMapping.Collections.Arrays.Equals(dataFormatIDExpected, dataFormatID) ||
                (authenticate != null && !authenticate
                 .IsDataVersionAcceptable(dataVersion)))
            {
                throw new IOException(HEADER_AUTHENTICATION_FAILED_);
            }
            return(unicodeVersion);
        }
Exemple #26
0
        /// <summary>
        /// Loads the rules from a DateInputStream, often in a jar file.
        /// </summary>
        /// <param name="dis">  the DateInputStream to load, not null </param>
        /// <exception cref="Exception"> if an error occurs </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void load(java.io.DataInputStream dis) throws Exception
        private void Load(DataInputStream dis)
        {
            if (dis.ReadByte() != 1)
            {
                throw new StreamCorruptedException("File format not recognised");
            }
            // group
            String groupId = dis.ReadUTF();

            if ("TZDB".Equals(groupId) == false)
            {
                throw new StreamCorruptedException("File format not recognised");
            }
            // versions
            int versionCount = dis.ReadShort();

            for (int i = 0; i < versionCount; i++)
            {
                VersionId = dis.ReadUTF();
            }
            // regions
            int regionCount = dis.ReadShort();

            String[] regionArray = new String[regionCount];
            for (int i = 0; i < regionCount; i++)
            {
                regionArray[i] = dis.ReadUTF();
            }
            RegionIds = Arrays.AsList(regionArray);
            // rules
            int ruleCount = dis.ReadShort();

            Object[] ruleArray = new Object[ruleCount];
            for (int i = 0; i < ruleCount; i++)
            {
                sbyte[] bytes = new sbyte[dis.ReadShort()];
                dis.ReadFully(bytes);
                ruleArray[i] = bytes;
            }
            // link version-region-rules
            for (int i = 0; i < versionCount; i++)
            {
                int versionRegionCount = dis.ReadShort();
                RegionToRules.Clear();
                for (int j = 0; j < versionRegionCount; j++)
                {
                    String region = regionArray[dis.ReadShort()];
                    Object rule   = ruleArray[dis.ReadShort() & 0xffff];
                    RegionToRules[region] = rule;
                }
            }
        }
Exemple #27
0
        /// <summary>
        /// This constructs a DataChecksum by reading HEADER_LEN bytes from input
        /// stream <i>in</i>
        /// </summary>
        /// <exception cref="System.IO.IOException"/>
        public static DataChecksum NewDataChecksum(DataInputStream @in)
        {
            int          type   = @in.ReadByte();
            int          bpc    = @in.ReadInt();
            DataChecksum summer = NewDataChecksum(DataChecksum.Type.ValueOf(type), bpc);

            if (summer == null)
            {
                throw new IOException("Could not create DataChecksum of type " + type + " with bytesPerChecksum "
                                      + bpc);
            }
            return(summer);
        }
Exemple #28
0
        /// <summary>
        /// Creates a new automaton, reading it from a file in FSA format, version 5.
        /// </summary>
        internal CFSA(Stream stream)
        {
            using (DataInputStream input = new DataInputStream(stream, true))
            {
                // Skip legacy header fields.
                input.ReadByte();  // filler
                input.ReadByte();  // annotation
                byte hgtl = (byte)input.ReadByte();

                /*
                 * Determine if the automaton was compiled with NUMBERS. If so, modify
                 * ctl and goto fields accordingly.
                 */
                flags = FSAFlags.Flexible | FSAFlags.StopBit | FSAFlags.NextBit;
                if ((hgtl & 0xf0) != 0)
                {
                    this.NodeDataLength = (hgtl.TripleShift(4)) & 0x0f;
                    this.GoToLength     = hgtl & 0x0f;
                    flags |= FSAFlags.Numbers;
                }
                else
                {
                    this.NodeDataLength = 0;
                    this.GoToLength     = hgtl & 0x0f;
                }

                /*
                 * Read mapping dictionary.
                 */
                LabelMapping = new byte[1 << 5];
                input.ReadFully(LabelMapping);

                /*
                 * Read arcs' data.
                 */
                Arcs = ReadRemaining(input);
            }
        }
        /// <summary>
        /// Read and wrap a binary automaton in FSA version 5.
        /// </summary>
        internal FSA5(Stream stream)
        {
            DataInputStream input = new DataInputStream(stream);

            this.Filler     = (byte)input.ReadByte();
            this.Annotation = (byte)input.ReadByte();
            byte hgtl = (byte)input.ReadByte();

            /*
             * Determine if the automaton was compiled with NUMBERS. If so, modify
             * ctl and goto fields accordingly.
             */
            flags = FSAFlags.Flexible | FSAFlags.StopBit | FSAFlags.NextBit;
            if ((hgtl & 0xf0) != 0)
            {
                flags |= FSAFlags.Numbers;
            }

            this.NodeDataLength = (hgtl.TripleShift(4)) & 0x0f;
            this.GoToLength     = hgtl & 0x0f;

            Arcs = ReadRemaining(input);
        }
Exemple #30
0
        /// <summary>
        /// Checks for updates at the remote host.
        /// </summary>
        public virtual SessionToken CheckForUpdate(string currentVersion)
        {
            string[] parameters = null;
            if (currentVersion != null)
                parameters = new[] { ReplicationService.REPLICATE_VERSION_PARAM, currentVersion };

            HttpResponseMessage response = base.ExecuteGet(ReplicationService.ReplicationAction.UPDATE.ToString(), parameters);
            return DoAction(response, () =>
            {
                using (DataInputStream inputStream = new DataInputStream(ResponseInputStream(response)))
                {
                    return inputStream.ReadByte() == 0 ? null : new SessionToken(inputStream);
                }
            });
        }