javazoom.jl.decoder.BackStream.Read C# (CSharp) Method

Read() public method

public Read ( sbyte toRead, int offset, int length ) : int
toRead sbyte
offset int
length int
return int
        public int Read(sbyte[]toRead, int offset, int length)
        {
            // Read
            int currentByte = 0;
            bool canReadStream = true;
            while (currentByte < length && canReadStream)
            {
                if (NumForwardBytesInBuffer > 0)
                { // from mem
                    NumForwardBytesInBuffer--;
                    toRead[offset+currentByte] = (sbyte)COB[NumForwardBytesInBuffer];
                    currentByte++;
                }
                else
                { // from stream
                    int newBytes = length - currentByte;
                    int numRead = S.Read(Temp, 0, newBytes);
                    canReadStream = numRead >= newBytes;
                    for (int i = 0; i < numRead; i++)
                    {
                        COB.Push(Temp[i]);
                        toRead[offset+currentByte+i] = (sbyte)Temp[i];
                    }
                    currentByte += numRead;
                }
            }
            return currentByte;
        }

Usage Example

示例#1
0
        /// <summary> Reads the exact number of bytes from the source
        /// input stream into a byte array.
        /// *
        /// </summary>
        /// <param name="b		The">byte array to read the specified number
        /// of bytes into.
        /// </param>
        /// <param name="offs	The">index in the array where the first byte
        /// read should be stored.
        /// </param>
        /// <param name="len	the">number of bytes to read.
        /// *
        /// </param>
        /// <exception cref=""> BitstreamException is thrown if the specified
        /// number of bytes could not be read from the stream.
        ///
        /// </exception>
        private void  readFully(sbyte[] b, int offs, int len)
        {
            try
            {
                while (len > 0)
                {
                    int bytesread = source.Read(b, offs, len);
                    if (bytesread == -1 ||
                        bytesread == 0)                        // t/DD -- .NET returns 0 at end-of-stream!
                    {
                        // t/DD: this really SHOULD throw an exception here...
                        Trace.WriteLine("readFully -- returning success at EOF? (" + bytesread + ")",
                                        "Bitstream");
                        while (len-- > 0)
                        {
                            b[offs++] = 0;
                        }
                        break;
                        //throw newBitstreamException(UNEXPECTED_EOF, new EOFException());
                    }

                    offs += bytesread;
                    len  -= bytesread;
                }
            }
            catch (System.IO.IOException ex)
            {
                throw newBitstreamException(javazoom.jl.decoder.BitstreamErrors_Fields.STREAM_ERROR, ex);
            }
        }
All Usage Examples Of javazoom.jl.decoder.BackStream::Read