CSJ2K.j2k.io.BufferedRandomAccessFile.write C# (CSharp) Метод

write() публичный Метод

Writes a byte to the stream. Prior to writing, the stream is realigned at the byte level.
If an I/O error ocurred. /// ///
public write ( byte b ) : void
b byte The byte to write. /// ///
Результат void
        public void write(byte b)
        {
            // As long as pos is less than the length of the buffer we can write
            // to the buffer. If the position is after the buffer a new buffer is
            // needed
            if (position < byteBuffer.Length)
            {
                if (isReadOnly)
                    throw new System.IO.IOException("File is read only");
                byteBuffer[position] = b;
                if (position >= maxByte)
                {
                    maxByte = position + 1;
                }
                position++;
                byteBufferChanged = true;
            }
            else
            {
                readNewBuffer(offset + position);
                write(b);
            }
        }

Same methods

BufferedRandomAccessFile::write ( byte b, int offset, int length ) : void
BufferedRandomAccessFile::write ( int b ) : void

Usage Example

Пример #1
0
        /// <summary> This method writes the new codestream to the file. 
        /// 
        /// </summary>
        /// <param name="fi">The file to write the new codestream to
        /// 
        /// </param>
        /// <exception cref="IOException">If an I/O error ocurred.
        /// 
        /// </exception>
        private void writeNewCodestream(BufferedRandomAccessFile fi)
        {
            int t, p, tp; // i removed
            int numTiles = tileParts.Length;
            int[][] packetHeaderLengths = new int[numTiles][];
            for (int i2 = 0; i2 < numTiles; i2++)
            {
                packetHeaderLengths[i2] = new int[maxtp];
            }
            byte[] temp;
            int length;

            // Write main header up to SOT marker
            fi.write(mainHeader, 0, mainHeader.Length);

            // If PPM used write all packet headers in PPM markers
            if (ppmUsed)
            {
                System.IO.MemoryStream ppmMarkerSegment = new System.IO.MemoryStream();
                int numPackets;
                int totNumPackets;
                int ppmIndex = 0;
                int ppmLength;
                int pStart, pStop;
                int[] prem = new int[numTiles];

                // Set number of remaining packets
                for (t = 0; t < numTiles; t++)
                {
                    prem[t] = packetHeaders[t].Length;
                }

                // Calculate Nppm values
                for (tp = 0; tp < maxtp; tp++)
                {
                    for (t = 0; t < numTiles; t++)
                    {
                        if (tileParts[t].Length > tp)
                        {
                            totNumPackets = packetHeaders[t].Length;
                            // Calculate number of packets in this tilepart
                            numPackets = (tp == tileParts[t].Length - 1)?prem[t]:pptp;

                            pStart = totNumPackets - prem[t];
                            pStop = pStart + numPackets;

                            // Calculate number of packet header bytes for this
                            // tile part
                            for (p = pStart; p < pStop; p++)
                                packetHeaderLengths[t][tp] += packetHeaders[t][p].Length;

                            prem[t] -= numPackets;
                        }
                    }
                }

                // Write first PPM marker
                ppmMarkerSegment.WriteByte((System.Byte) SupportClass.URShift(CSJ2K.j2k.codestream.Markers.PPM, 8));
                ppmMarkerSegment.WriteByte((System.Byte) (CSJ2K.j2k.codestream.Markers.PPM & 0x00FF));
                ppmMarkerSegment.WriteByte((System.Byte) 0); // Temporary Lppm value
                ppmMarkerSegment.WriteByte((System.Byte) 0); // Temporary Lppm value
                ppmMarkerSegment.WriteByte((System.Byte) 0); // zppm
                ppmLength = 3;
                ppmIndex++;

                // Set number of remaining packets
                for (t = 0; t < numTiles; t++)
                    prem[t] = packetHeaders[t].Length;

                // Write all PPM markers and information
                for (tp = 0; tp < maxtp; tp++)
                {
                    for (t = 0; t < numTiles; t++)
                    {

                        if (tileParts[t].Length > tp)
                        {
                            totNumPackets = packetHeaders[t].Length;

                            // Calculate number of packets in this tilepart
                            numPackets = (tp == tileParts[t].Length - 1)?prem[t]:pptp;

                            pStart = totNumPackets - prem[t];
                            pStop = pStart + numPackets;

                            // If Nppm value wont fit in current PPM marker segment
                            // write current PPM marker segment and start new
                            if (ppmLength + 4 > CSJ2K.j2k.codestream.Markers.MAX_LPPM)
                            {
                                // Write current PPM marker
                                temp = ppmMarkerSegment.ToArray();
                                length = temp.Length - 2;
                                temp[2] = (byte) (SupportClass.URShift(length, 8));
                                temp[3] = (byte) length;
                                fi.write(temp, 0, length + 2);

                                // Start new PPM marker segment
                                //UPGRADE_ISSUE: Method 'java.io.ByteArrayOutputStream.reset' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaioByteArrayOutputStreamreset'"
                                //ppmMarkerSegment.reset();
                                ppmMarkerSegment.SetLength(0);
                                ppmMarkerSegment.WriteByte((System.Byte) SupportClass.URShift(CSJ2K.j2k.codestream.Markers.PPM, 8));
                                ppmMarkerSegment.WriteByte((System.Byte) (CSJ2K.j2k.codestream.Markers.PPM & 0x00FF));
                                ppmMarkerSegment.WriteByte((System.Byte) 0); // Temporary Lppm value
                                ppmMarkerSegment.WriteByte((System.Byte) 0); // Temporary Lppm value
                                ppmMarkerSegment.WriteByte((System.Byte) ppmIndex++); // zppm
                                ppmLength = 3;
                            }

                            // Write Nppm value
                            length = packetHeaderLengths[t][tp];
                            ppmMarkerSegment.WriteByte((System.Byte) SupportClass.URShift(length, 24));
                            ppmMarkerSegment.WriteByte((System.Byte) SupportClass.URShift(length, 16));
                            ppmMarkerSegment.WriteByte((System.Byte) SupportClass.URShift(length, 8));
                            ppmMarkerSegment.WriteByte((System.Byte) length);
                            ppmLength += 4;

                            // Write packet headers
                            for (p = pStart; p < pStop; p++)
                            {
                                length = packetHeaders[t][p].Length;

                                // If next packet header value wont fit in
                                // current PPM marker segment write current PPM
                                // marker segment and start new
                                if (ppmLength + length > CSJ2K.j2k.codestream.Markers.MAX_LPPM)
                                {
                                    // Write current PPM marker
                                    temp = ppmMarkerSegment.ToArray();
                                    length = temp.Length - 2;
                                    temp[2] = (byte) (SupportClass.URShift(length, 8));
                                    temp[3] = (byte) length;
                                    fi.write(temp, 0, length + 2);

                                    // Start new PPM marker segment
                                    //UPGRADE_ISSUE: Method 'java.io.ByteArrayOutputStream.reset' was not converted. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1000_javaioByteArrayOutputStreamreset'"
                                    //ppmMarkerSegment.reset();
                                    ppmMarkerSegment.SetLength(0);
                                    ppmMarkerSegment.WriteByte((System.Byte) SupportClass.URShift(CSJ2K.j2k.codestream.Markers.PPM, 8));
                                    ppmMarkerSegment.WriteByte((System.Byte) (CSJ2K.j2k.codestream.Markers.PPM & 0x00FF));
                                    ppmMarkerSegment.WriteByte((System.Byte) 0); // Temp Lppm value
                                    ppmMarkerSegment.WriteByte((System.Byte) 0); // Temp Lppm value
                                    ppmMarkerSegment.WriteByte((System.Byte) ppmIndex++); // zppm
                                    ppmLength = 3;
                                }

                                // write packet header
                                ppmMarkerSegment.Write(packetHeaders[t][p], 0, packetHeaders[t][p].Length);
                                ppmLength += packetHeaders[t][p].Length;
                            }
                            prem[t] -= numPackets;
                        }
                    }
                }
                // Write last PPM marker segment
                temp = ppmMarkerSegment.ToArray();
                length = temp.Length - 2;
                temp[2] = (byte) (SupportClass.URShift(length, 8));
                temp[3] = (byte) length;
                fi.write(temp, 0, length + 2);
            }

            // Write tile parts interleaved
            for (tp = 0; tp < maxtp; tp++)
            {
                for (t = 0; t < nt; t++)
                {
                    if (tileParts[t].Length > tp)
                    {
                        temp = tileParts[t][tp];
                        length = temp.Length;
                        fi.write(temp, 0, length);
                    }
                }
            }
            fi.writeShort(CSJ2K.j2k.codestream.Markers.EOC);
        }
All Usage Examples Of CSJ2K.j2k.io.BufferedRandomAccessFile::write