ReadInput() private method

private ReadInput ( System sourceStream, sbyte &target, int start, int count ) : Int32
sourceStream System
target sbyte
start int
count int
return System.Int32
コード例 #1
0
        /// <summary>
        ///     Open a RIFF file.
        /// </summary>
        public virtual int Open(string filename, int newMode)
        {
            int retcode = DDC_SUCCESS;

            if (Fmode != RFM_UNKNOWN)
            {
                retcode = Close();
            }

            if (retcode == DDC_SUCCESS)
            {
                switch (newMode)
                {
                case RFM_WRITE:
                    try
                    {
                        m_File = RandomAccessFileStream.CreateRandomAccessFile(filename, "rw");

                        try
                        {
                            // Write the RIFF header...
                            // We will have to come back later and patch it!
                            sbyte[] br = new sbyte[8];
                            br[0] = (sbyte)((SupportClass.URShift(m_RiffHeader.CkId, 24)) & 0x000000FF);
                            br[1] = (sbyte)((SupportClass.URShift(m_RiffHeader.CkId, 16)) & 0x000000FF);
                            br[2] = (sbyte)((SupportClass.URShift(m_RiffHeader.CkId, 8)) & 0x000000FF);
                            br[3] = (sbyte)(m_RiffHeader.CkId & 0x000000FF);

                            sbyte br4 = (sbyte)((SupportClass.URShift(m_RiffHeader.CkSize, 24)) & 0x000000FF);
                            sbyte br5 = (sbyte)((SupportClass.URShift(m_RiffHeader.CkSize, 16)) & 0x000000FF);
                            sbyte br6 = (sbyte)((SupportClass.URShift(m_RiffHeader.CkSize, 8)) & 0x000000FF);
                            sbyte br7 = (sbyte)(m_RiffHeader.CkSize & 0x000000FF);

                            br[4] = br7;
                            br[5] = br6;
                            br[6] = br5;
                            br[7] = br4;

                            m_File.Write(SupportClass.ToByteArray(br), 0, 8);
                            Fmode = RFM_WRITE;
                        }
                        catch
                        {
                            m_File.Close();
                            Fmode = RFM_UNKNOWN;
                        }
                    }
                    catch
                    {
                        Fmode   = RFM_UNKNOWN;
                        retcode = DDC_FILE_ERROR;
                    }
                    break;

                case RFM_READ:
                    try
                    {
                        m_File = RandomAccessFileStream.CreateRandomAccessFile(filename, "r");
                        try
                        {
                            // Try to read the RIFF header...
                            sbyte[] br = new sbyte[8];
                            SupportClass.ReadInput(m_File, ref br, 0, 8);
                            Fmode             = RFM_READ;
                            m_RiffHeader.CkId = ((br[0] << 24) & (int)SupportClass.Identity(0xFF000000)) |
                                                ((br[1] << 16) & 0x00FF0000) | ((br[2] << 8) & 0x0000FF00) |
                                                (br[3] & 0x000000FF);
                            m_RiffHeader.CkSize = ((br[4] << 24) & (int)SupportClass.Identity(0xFF000000)) |
                                                  ((br[5] << 16) & 0x00FF0000) | ((br[6] << 8) & 0x0000FF00) |
                                                  (br[7] & 0x000000FF);
                        }
                        catch
                        {
                            m_File.Close();
                            Fmode = RFM_UNKNOWN;
                        }
                    }
                    catch
                    {
                        Fmode   = RFM_UNKNOWN;
                        retcode = DDC_FILE_ERROR;
                    }
                    break;

                default:
                    retcode = DDC_INVALID_CALL;
                    break;
                }
            }
            return(retcode);
        }
コード例 #2
0
ファイル: StreamsUtil.cs プロジェクト: amasasi/DotNetRosa
        /// <summary>
        /// Read bytes from an input stream into a byte array then close the input
        /// stream
        ///
        /// </summary>
        /// <param name="in">
        /// </param>
        /// <param name="len">
        /// </param>
        /// <returns>
        /// </returns>
        /// <throws>  IOException </throws>
        public static sbyte[] readFromStream(System.IO.Stream in_Renamed, int len)
        {
            sbyte[] data;
            int     read;

            if (len >= 0)
            {
                data = new sbyte[len];
                read = 0;
                while (read < len)
                {
                    int k = in_Renamed is org.javarosa.core.io.BufferedInputStream?((org.javarosa.core.io.BufferedInputStream)in_Renamed).read(data, read, len - read):SupportClass.ReadInput(in_Renamed, data, read, len - read);
                    if (k == -1)
                    {
                        break;
                    }
                    read += k;
                }
            }
            else
            {
                System.IO.MemoryStream buffer = new System.IO.MemoryStream();
                while (true)
                {
                    int b = in_Renamed.ReadByte();
                    if (b == -1)
                    {
                        break;
                    }
                    buffer.WriteByte((System.Byte)b);
                }
                data = SupportClass.ToSByteArray(buffer.ToArray());
                read = data.Length;
            }

            if (len > 0 && read < len)
            {
                // System.out.println("WARNING: expected " + len + "!!");
                throw new System.SystemException("expected: " + len + " bytes but read " + read);
            }
            // replyS
            // System.out.println(new String(data, "UTF-8"));

            return(data);
        }
コード例 #3
0
ファイル: RiffFile.cs プロジェクト: jwofles/ForkSO
        /// <summary> Open a RIFF file.
        /// </summary>
        public virtual int Open(System.String Filename, int NewMode)
        {
            int retcode = DDC_SUCCESS;

            if (fmode != RFM_UNKNOWN)
            {
                retcode = Close();
            }

            if (retcode == DDC_SUCCESS)
            {
                switch (NewMode)
                {
                case RFM_WRITE:
                    try
                    {
                        file = SupportClass.RandomAccessFileSupport.CreateRandomAccessFile(Filename, "rw");

                        try
                        {
                            // Write the RIFF header...
                            // We will have to come back later and patch it!
                            sbyte[] br = new sbyte[8];
                            br[0] = (sbyte)((SupportClass.URShift(riff_header.ckID, 24)) & 0x000000FF);
                            br[1] = (sbyte)((SupportClass.URShift(riff_header.ckID, 16)) & 0x000000FF);
                            br[2] = (sbyte)((SupportClass.URShift(riff_header.ckID, 8)) & 0x000000FF);
                            br[3] = (sbyte)(riff_header.ckID & 0x000000FF);

                            sbyte br4 = (sbyte)((SupportClass.URShift(riff_header.ckSize, 24)) & 0x000000FF);
                            sbyte br5 = (sbyte)((SupportClass.URShift(riff_header.ckSize, 16)) & 0x000000FF);
                            sbyte br6 = (sbyte)((SupportClass.URShift(riff_header.ckSize, 8)) & 0x000000FF);
                            sbyte br7 = (sbyte)(riff_header.ckSize & 0x000000FF);

                            br[4] = br7;
                            br[5] = br6;
                            br[6] = br5;
                            br[7] = br4;

                            file.Write(SupportClass.ToByteArray(br), 0, 8);
                            fmode = RFM_WRITE;
                        }
                        catch (System.IO.IOException ioe)
                        {
                            file.Close();
                            fmode = RFM_UNKNOWN;
                        }
                    }
                    catch (System.IO.IOException ioe)
                    {
                        fmode   = RFM_UNKNOWN;
                        retcode = DDC_FILE_ERROR;
                    }
                    break;


                case RFM_READ:
                    try
                    {
                        file = SupportClass.RandomAccessFileSupport.CreateRandomAccessFile(Filename, "r");
                        try
                        {
                            // Try to read the RIFF header...
                            sbyte[] br = new sbyte[8];
                            SupportClass.ReadInput(file, ref br, 0, 8);
                            fmode              = RFM_READ;
                            riff_header.ckID   = ((br[0] << 24) & (int)SupportClass.Identity(0xFF000000)) | ((br[1] << 16) & 0x00FF0000) | ((br[2] << 8) & 0x0000FF00) | (br[3] & 0x000000FF);
                            riff_header.ckSize = ((br[4] << 24) & (int)SupportClass.Identity(0xFF000000)) | ((br[5] << 16) & 0x00FF0000) | ((br[6] << 8) & 0x0000FF00) | (br[7] & 0x000000FF);
                        }
                        catch (System.IO.IOException ioe)
                        {
                            file.Close();
                            fmode = RFM_UNKNOWN;
                        }
                    }
                    catch (System.IO.IOException ioe)
                    {
                        fmode   = RFM_UNKNOWN;
                        retcode = DDC_FILE_ERROR;
                    }
                    break;

                default:
                    retcode = DDC_INVALID_CALL;
                    break;
                }
            }
            return(retcode);
        }
コード例 #4
0
        public static sbyte[] toByteArray(Stream input, int length)
        {
            BufferedStream inputStream = new BufferedStream(input);

            sbyte[] buffer = new sbyte[length];

            try
            {
                int bytesRead = 0;
                int index     = 0;

                while ((bytesRead >= 0) && (index < buffer.Length))
                {
                    bytesRead = inputStream is Flash.Swf.SwfDecoder?((Flash.Swf.SwfDecoder)inputStream).read(buffer, index, buffer.Length - index):SupportClass.ReadInput(inputStream, buffer, index, buffer.Length - index);
                    index    += bytesRead;
                }
            }
            finally
            {
                inputStream.Close();
            }
            return(buffer);
        }
コード例 #5
0
 private bool fillBuffer()
 {
     if (count == -1)
     {
         //do nothing
         return(false);
     }
     position = 0;
     count    = in_Renamed is org.javarosa.core.io.BufferedInputStream?((org.javarosa.core.io.BufferedInputStream)in_Renamed).read(buffer):SupportClass.ReadInput(in_Renamed, buffer, 0, buffer.Length);
     return(count == buffer.Length);
 }
コード例 #6
0
        public virtual int read(sbyte[] b, int offs, int len)
        {
            int read = SupportClass.ReadInput(in_Renamed, ref b, offs, len);

            return(read);
        }
コード例 #7
0
        /// <summary> Creates an ensemble object for the product PDS.</summary>
        /// <param name="raf">RandomAccessFile.
        /// </param>
        /// <param name="parameterNumber">
        /// </param>
        /// <throws>  IOException </throws>
        //UPGRADE_TODO: Class 'java.io.RandomAccessFile' was converted to 'System.IO.FileStream' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073_javaioRandomAccessFile'"
        public Grib1Ensemble(System.IO.FileStream raf, int parameterNumber)
        {
            // skip 12 bytes to start of ensemble
            SupportClass.Skip(raf, 12);

            // octet 41 id's ensemble
            int app = raf.ReadByte();

            if (app != 1)
            {
                System.Console.Out.WriteLine("not ensemble product");
                return;
            }

            // octet 42 Type
            eType = raf.ReadByte();

            // octet 43 Identification number
            eId = raf.ReadByte();

            // octet 44 Product Identifier
            eProd = raf.ReadByte();

            // octet 45 Spatial Identifier
            eSpatial = raf.ReadByte();

            if (parameterNumber == 191 || parameterNumber == 192)
            {
                // octet 46 Probability product definition
                epd = raf.ReadByte();

                // octet 47 Probability type
                ept = raf.ReadByte();

                // octet 48-51 Probability lower limit
                epll = GribNumbers.int4(raf);

                // octet 52-55 Probability upper limit
                epul = GribNumbers.int4(raf);

                // octet 56-60 reserved
                int reserved = GribNumbers.int4(raf);

                if (eType == 4 || eType == 5)
                {
                    // octet 61 Ensemble size
                    eSize = raf.ReadByte();

                    // octet 62 Cluster size
                    eCSize = raf.ReadByte();

                    // octet 63 Number of clusters
                    eCNumber = raf.ReadByte();

                    // octet 64 Clustering Method
                    eCMethod = raf.ReadByte();

                    // octet 65-67 Northern latitude of clustering domain
                    nLat = GribNumbers.int3(raf);

                    // octet 68-70 Southern latitude of clustering domain
                    sLat = GribNumbers.int3(raf);

                    // octet 71-73 Eastern latitude of clustering domain
                    eLat = GribNumbers.int3(raf);

                    // octet 74-76 Western latitude of clustering domain
                    wLat = GribNumbers.int3(raf);

                    if (eType == 4)
                    {
                        // octets 77-86 Cluster Membership
                        cm = new sbyte[10];
                        SupportClass.ReadInput(raf, cm, 0, cm.Length);
                    }
                }
            }
        }