Mercurial > 510Connectbot
diff src/org/tn5250j/framework/tn5250/Stream5250.java @ 112:77ac18bc1b2f
cleanup java formatting
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Wed, 18 Jun 2014 13:03:01 -0700 |
parents | e8d2a24e85c6 |
children |
line wrap: on
line diff
--- a/src/org/tn5250j/framework/tn5250/Stream5250.java Wed Jun 18 13:00:19 2014 -0700 +++ b/src/org/tn5250j/framework/tn5250/Stream5250.java Wed Jun 18 13:03:01 2014 -0700 @@ -43,131 +43,122 @@ } public Stream5250() { - buffer = null; - streamSize = 0; - opCode = 0; - dataStart = 0; - pos = dataStart; - } + buffer = null; + streamSize = 0; + opCode = 0; + dataStart = 0; + pos = dataStart; + } /** * This method takes a byte array and initializes the object information * to be used. - * + * * @param abyte0 */ public void initialize(byte abyte0[]) { - - buffer = abyte0; - // size without end of record 0xFF 0xEF - streamSize = (abyte0[0] & 0xff) << 8 | abyte0[1] & 0xff; - opCode = abyte0[9]; - dataStart = 6 + abyte0[6]; - pos = dataStart; - + buffer = abyte0; + // size without end of record 0xFF 0xEF + streamSize = (abyte0[0] & 0xff) << 8 | abyte0[1] & 0xff; + opCode = abyte0[9]; + dataStart = 6 + abyte0[6]; + pos = dataStart; } - + public final int getOpCode() { return opCode; } public final byte getNextByte() - throws Exception { - if(buffer == null || pos > buffer.length) + throws Exception { + if (buffer == null || pos > buffer.length) throw new Exception("Buffer length exceeded: " + pos); else return buffer[pos++]; } public final void setPrevByte() - throws Exception { - if(pos == 0) { + throws Exception { + if (pos == 0) { throw new Exception("Index equals zero."); } else { pos--; return; - } - } + } + } - /** - * Returns where we are in the buffer - * @return position in the buffer - */ - public final int getCurrentPos() { - return pos; - } + /** + * Returns where we are in the buffer + * @return position in the buffer + */ + public final int getCurrentPos() { + return pos; + } - public final byte getByteOffset(int off) - throws Exception { - - if(buffer == null || (pos + off ) > buffer.length) + public final byte getByteOffset(int off) + throws Exception { + if (buffer == null || (pos + off) > buffer.length) throw new Exception("Buffer length exceeded: " + pos); else return buffer[pos + off]; - - } + } - public final boolean size() { - return pos >= streamSize; - } + public final boolean size() { + return pos >= streamSize; + } - /** - * Determines if any more bytes are available in the buffer to be processed. - * @return yes or no - */ - public final boolean hasNext() { - + /** + * Determines if any more bytes are available in the buffer to be processed. + * @return yes or no + */ + public final boolean hasNext() { // return pos >= buffer.length; - return pos < streamSize; - } + return pos < streamSize; + } - /** - * This routine will retrieve a segment based on the first two bytes being - * the length of the segment. - * - * @return a new byte array containing the bytes of the segment. - * @throws Exception - */ - public final byte[] getSegment() throws Exception { - - // The first two bytes contain the length of the segment. - int length = ((buffer[pos] & 0xff )<< 8 | (buffer[pos+1] & 0xff)); - // allocate space for it. - byte[] segment = new byte[length]; - - getSegment(segment,length,true); - - return segment; - } + /** + * This routine will retrieve a segment based on the first two bytes being + * the length of the segment. + * + * @return a new byte array containing the bytes of the segment. + * @throws Exception + */ + public final byte[] getSegment() throws Exception { + // The first two bytes contain the length of the segment. + int length = ((buffer[pos] & 0xff) << 8 | (buffer[pos + 1] & 0xff)); + // allocate space for it. + byte[] segment = new byte[length]; + getSegment(segment, length, true); + return segment; + } - /** - * This routine will retrieve a byte array based on the first two bytes being - * the length of the segment. - * - * @param segment - byte array - * @param length - length of segment to return - * @param adjustPos - adjust the position of the buffer to the end of the seg - * ment - * @throws Exception - */ - public final void getSegment(byte[] segment, int length, boolean adjustPos) - throws Exception { + /** + * This routine will retrieve a byte array based on the first two bytes being + * the length of the segment. + * + * @param segment - byte array + * @param length - length of segment to return + * @param adjustPos - adjust the position of the buffer to the end of the seg + * ment + * @throws Exception + */ + public final void getSegment(byte[] segment, int length, boolean adjustPos) + throws Exception { + // If the length is larger than what is available throw an exception + if ((pos + length) > buffer.length) + throw new Exception("Buffer length exceeded: start " + pos + + " length " + length); - // If the length is larger than what is available throw an exception - if((pos + length ) > buffer.length) - throw new Exception("Buffer length exceeded: start " + pos - + " length " + length); - // use the system array copy to move the bytes from the buffer - // to the allocated byte array - System.arraycopy(buffer,pos,segment,0,length); + // use the system array copy to move the bytes from the buffer + // to the allocated byte array + System.arraycopy(buffer, pos, segment, 0, length); - // update the offset to be after the segment so the next byte can be read - if (adjustPos) - pos +=length; - - } + // update the offset to be after the segment so the next byte can be read + if (adjustPos) + pos += length; + } }