/*
(non-Javadoc)
@see javax.jms.StreamMessage#readByte()
777679
@Override
	public byte readByte() throws JMSException
    {
    	backupState();
    	try
    	{
    		return MessageConvertTools.asByte(internalReadObject());
    	}
    	catch (JMSException e)
    	{
    		restoreState();
    		throw e;	
    	}
    	catch (RuntimeException e)
    	{
    		restoreState();
    		throw e;
    	}
    }
506555
protected void readBytes(final InputStream in, final ProgressByteProcessor processor) throws IOException {
        final byte[] buf = new byte[BUF_SIZE];
        try {
            int amt;
            do {
                amt = in.read(buf);
                if (amt == -1) {
                    break;
                }
            } while (processor.processBytes(buf, 0, amt));
        } finally {
            IOUtils.closeQuietly(in);
        }
    }
535328
@Override
    public int read(byte[] output, int offset, int length) throws IOException {
        synchronized(this){
            int value = 0;
            if(closed) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isErrorEnabled())
                    Tr.error(tc, "stream.is.closed.no.read.write");
                throw new IOException(Tr.formatMessage(tc, "stream.is.closed.no.read.write"));
            }
            if(output == null){
                if (TraceComponent.isAnyTracingEnabled() && tc.isErrorEnabled())
                    Tr.error(tc, "read.write.bytearray.null");
                throw new NullPointerException(Tr.formatMessage(tc, "read.write.bytearray.null"));
            }
            if((offset < 0) || (length < 0) || (length > (output.length - offset))){
                if (TraceComponent.isAnyTracingEnabled() && tc.isErrorEnabled())
                    Tr.error(tc, "read.write.offset.length.bytearraylength", new Object[] {offset, length, output.length});
                throw new IndexOutOfBoundsException(Tr.formatMessage(tc, "read.write.offset.length.bytearraylength", new Object[] {offset, length, output.length}));
            }

            if (this._inBuffer != null) {
                value = _inBuffer.read(output, offset, length);
            }
            else {
                value = this.in.read(output, offset, length);
            }

            return value;
        }
    }
762387
@Override
	public int read(byte[] b) throws IOException {
		int result = stream.read(b);
		update(result);
		return result;
	}
1126041
public byte[] readBytes()
        throws IOException
    {
        int tag = read();

        switch (tag) {
            case 'N':
                return null;

            case 'B':
            case 'b':
                _isLastChunk = tag == 'B';
                _chunkLength = (read() << 8) + read();

                ByteArrayOutputStream bos = new ByteArrayOutputStream();

                int data;
                while ((data = parseByte()) >= 0)
                    bos.write(data);

                return bos.toByteArray();

            default:
                throw expect("bytes", tag);
        }
    }
452124
public int read(byte[] b, int off, int len) throws IOException
	{
		if (b == null)
			throw new NullPointerException();
		if (off < 0 || len < 0 || len > b.length - off)
			throw new IndexOutOfBoundsException();
		return p.readBytes(b, off, len);
	}
659247
public static int readSingleByte(InputStream in) throws IOException {
        byte[] buffer = new byte[1];
        int result = in.read(buffer, 0, 1);
        return (result != -1) ? buffer[0] & 0xff : -1;
    }
805088
@Override
    public ByteArray readByteArray() {
        int type = readInteger();
        if ((type & 1) == 0) {
            return (ByteArray) getReference(type >> 1);
        }
        type >>= 1;
        ByteArray result = new ByteArray(buf, type);
        storeReference(result);
        return result;
    }
521616
@Override
  public synchronized int read(byte[] buf, int off, int len)
      throws IOException {
    checkNotClosed();

    validatePositionedReadArgs(nextReadPos, buf, off, len);
    if (len == 0) {
      return 0;
    }

    if (contentLength == 0 || (nextReadPos >= contentLength)) {
      return -1;
    }

    try {
      lazySeek(nextReadPos, len);
    } catch (EOFException e) {
      // the end of the file has moved
      return -1;
    }

    int bytesRead;
    try {
      bytesRead = wrappedStream.read(buf, off, len);
    } catch (EOFException e) {
      onReadFailure(e, len);
      // the base implementation swallows EOFs.
      return -1;
    } catch (IOException e) {
      onReadFailure(e, len);
      bytesRead = wrappedStream.read(buf, off, len);
    }

    if (bytesRead > 0) {
      pos += bytesRead;
      nextReadPos += bytesRead;
    }
    incrementBytesRead(bytesRead);
    return bytesRead;
  }
147869
@Override
    public void writeBytes(byte[] value) throws JMSException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(this, tc, "writeBytes", value);

        try {
            // Check that we are in write mode
            checkBodyWriteable("writeBytes");

            // This method has different behaviours for storing the byte array, based on the whether the producer
            // has promised not to mess with data after it's been written...
            if (producerWontModifyPayloadAfterSet) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    SibTr.debug(this, tc, "Producer has promised not to modify the payload after setting it in the message - check if they've violated that promise");

                // The producer has promised not to modify the payload after it's been set, so check
                // the flag to see whether this is the first, or a subsequent call to writeBytes.
                if (!writeByteArrayCalled) {
                    if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                        SibTr.debug(this, tc, "This is the first call to writeBytes(byte[] value) - storing the byte array reference directly in the underlying MFP object");

                    writeByteArrayCalled = true;

                    // Set the data buffer & MFP data references to the value param & reset
                    // the dataStart attribute
                    jsBytesMsg.setBytes(value);
                    dataBuffer = value;
                    dataStart = 0;
                }

                else {
                    // The producer has promised not to modify the payload after it's been set, but the producer has
                    // been naughty by calling this method more than once! Throw exception to admonish the producer.
                    throw (JMSException) JmsErrorUtils.newThrowable(
                                                                    IllegalStateException.class, // JMS illegal state exception
                                                                    "PROMISE_BROKEN_EXCEPTION_CWSIA0511", // promise broken
                                                                    null, // No inserts
                                                                    null, // no cause - original exception
                                                                    "JmsBytesMessageImpl.writeBytes#3", // Probe ID
                                                                    this, // Caller (?)
                                                                    tc); // Trace component
                }
            }

            else {
                // Producer makes no promises relating to the accessing the message payload, so
                // make a copy of the byte array at this point to ensure the message is transmitted safely.
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    SibTr.debug(this, tc, "Producer 'payload modification' promise is not in place - make a copy of the byte array");

                // Write the byte array to the output stream
                // We don't check for value==null as JDK1.1.6 DataOutputStream doesn't
                writeStream.write(value, 0, value.length);

                // Ensure that the new data gets exported when the time comes.
                bodySetInJsMsg = false;
            }

            // Invalidate the cached toString object, because the message payload has changed.
            cachedBytesToString = null;
        }

        catch (IOException ex) {
            // No FFDC code needed
            //(exception repro'ed from 3-param writeBytes method)
            throw (JMSException) JmsErrorUtils.newThrowable(
                                                            ResourceAllocationException.class,
                                                            "WRITE_PROBLEM_CWSIA0186",
                                                            null,
                                                            ex,
                                                            "JmsBytesMessageImpl.writeBytes#4",
                                                            this,
                                                            tc);
        }

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(this, tc, "writeBytes");
    }
1257935
@Override
    public byte readByte() throws IndexOutOfBoundsException, IOException {
        final int read = internalReadBytes(1);
        if (read == -1) {
            // not sure this is really the right thing to do
            throw new IndexOutOfBoundsException();
        }
        return getByte(this.readerIndex++);
    }
201662
static private int readBytes(int c[], int len, InputStream is)
                throws IOException {

        byte buf[] = new byte[len];
        if (is.read(buf, 0, len) < len) {
            return -1;
        }

        // fill the passed in int array
        for (int i = 0; i < len; i++) {
             c[i] = buf[i] & 0xff;
        }
        return 0;
    }
1342133
@Override
    protected int readBytesWireFormat ( byte[] buffer, int bufferIndex ) throws SMBProtocolDecodingException {
        int start = bufferIndex;
        for ( int i = 0; i < this.unlocks.length; i++ ) {
            this.unlocks[ i ] = createLockRange();
            bufferIndex += this.unlocks[ i ].decode(buffer, bufferIndex, buffer.length);
        }

        for ( int i = 0; i < this.locks.length; i++ ) {
            this.locks[ i ] = createLockRange();
            bufferIndex += this.locks[ i ].decode(buffer, bufferIndex, buffer.length);
        }

        return start - bufferIndex;
    }
169575
public ByteArray readBytes(int size) throws IOException
   {
      byte[] data = new byte[size];
      m_stream.read(data);
      return new ByteArray(data);
   }
162482
protected int readByte() throws IOException {
        if (commPort != null && commPort.isOpen()) {
            byte[] buffer = new byte[1];
            int cnt = commPort.readBytes(buffer, 1);
            if (cnt != 1) {
                throw new IOException("Cannot read from serial port");
            }
            else {
                return buffer[0] & 0xff;
            }
        }
        else {
            throw new IOException("Comm port is not valid or not open");
        }
    }
593718
@Override
    public int read(byte[] bts) throws IOException {
        try {
            beforeRead(bts != null ? bts.length : 0);
            int n = in.read(bts);
            afterRead(n);
            return n;
        } catch (IOException e) {
            handleIOException(e);
            return -1;
        }
    }
450981
public byte[] readBytesNullEnd() {
    int initialPosition = position;
    int cnt = 0;
    while (remaining() > 0 && (buf[position++] != 0)) {
      cnt++;
    }
    final byte[] tmpArr = new byte[cnt];
    System.arraycopy(buf, initialPosition, tmpArr, 0, cnt);
    return tmpArr;
  }