Skip to the next matching short value.

@param buffer input data array
@param offset start offset into the input array
@param value value to match
@return offset of matching pattern
423501
public static int skipToNextMatchingShort(byte[] buffer, int offset, int value)
   {
      int nextOffset = offset;
      while (getShort(buffer, nextOffset) != value)
      {
         ++nextOffset;
      }
      nextOffset += 2;

      return nextOffset;
   }
546511
private static void writeLong(byte[] buffer, int offset, long value) {
    buffer[offset    ] = (byte) (value >> 56);
    buffer[offset + 1] = (byte) (value >> 48);
    buffer[offset + 2] = (byte) (value >> 40);
    buffer[offset + 3] = (byte) (value >> 32);
    buffer[offset + 4] = (byte) (value >> 24);
    buffer[offset + 5] = (byte) (value >> 16);
    buffer[offset + 6] = (byte) (value >> 8);
    buffer[offset + 7] = (byte) value;
  }
730535
public void setText(String value) {
        string = value;
        start = offset = 0;
        end = value.length();
    }
1253282
protected String findOffsetMatch(TestInfo info, int startOffset, MutableOffset mutableOffset, final byte[] bytes,
			final char[] chars, final int maxPos) {

		// verify the starting offset
		if (startOffset < 0) {
			return null;
		}

		int targetPos = startOffset;
		boolean lastMagicCompactWhitespace = false;
		for (int magicPos = 0; magicPos < info.pattern.length(); magicPos++) {
			char magicCh = info.pattern.charAt(magicPos);
			boolean lastChar = (magicPos == info.pattern.length() - 1);
			// did we reach the end?
			if (targetPos >= maxPos) {
				return null;
			}
			char targetCh;
			if (bytes == null) {
				targetCh = chars[targetPos];
			} else {
				targetCh = charFromByte(bytes, targetPos);
			}
			targetPos++;

			// if it matches, we can continue
			if (info.operator.doTest(targetCh, magicCh, lastChar)) {
				if (info.compactWhiteSpace) {
					lastMagicCompactWhitespace = Character.isWhitespace(magicCh);
				}
				continue;
			}

			// if it doesn't match, maybe the target is a whitespace
			if ((lastMagicCompactWhitespace || info.optionalWhiteSpace) && Character.isWhitespace(targetCh)) {
				do {
					if (targetPos >= maxPos) {
						break;
					}
					if (bytes == null) {
						targetCh = chars[targetPos];
					} else {
						targetCh = charFromByte(bytes, targetPos);
					}
					targetPos++;
				} while (Character.isWhitespace(targetCh));
				// now that we get to the first non-whitespace, it must match
				if (info.operator.doTest(targetCh, magicCh, lastChar)) {
					if (info.compactWhiteSpace) {
						lastMagicCompactWhitespace = Character.isWhitespace(magicCh);
					}
					continue;
				}
				// if it doesn't match, check the case insensitive
			}

			// maybe it doesn't match because of case insensitive handling and magic-char is lowercase
			if (info.caseInsensitive && Character.isLowerCase(magicCh)) {
				if (info.operator.doTest(Character.toLowerCase(targetCh), magicCh, lastChar)) {
					// matches
					continue;
				}
				// upper-case characters must match
			}

			return null;
		}

		char[] resultChars;
		if (bytes == null) {
			resultChars = Arrays.copyOfRange(chars, startOffset, targetPos);
		} else {
			resultChars = new char[targetPos - startOffset];
			for (int i = 0; i < resultChars.length; i++) {
				resultChars[i] = charFromByte(bytes, startOffset + i);
			}
		}
		mutableOffset.offset = targetPos;
		return new String(resultChars);
	}
433673
@Override
    public int peek(int offset) throws IOException
    {
        long target = cursor + offset - 1;
        if (target - end > size || target < end - size || target < 0)
        {
            throw new IllegalArgumentException("offset "+offset+" out of buffer");
        }
        if (target >= end)
        {
            int la = 0;
            while (target >= end)
            {
                int cc = read();
                if (cc == -1)
                {
                    if (target+la == end)
                    {
                        return -1;
                    }
                    else
                    {
                        throw new IOException("eof");
                    }
                }
                la++;
            }
            rewind(la);
        }
        return get(target);
    }
771945
public void addUnsignedByte( short value ) {
        if ( 1 + length < capacity ) {
            DynamicByteBufferHelper.unsignedByteTo( buffer, length, value );
        } else {
            buffer = DynamicByteBufferHelper.grow( buffer, buffer.length * 2 + 1 );
            capacity = buffer.length;

            DynamicByteBufferHelper.unsignedByteTo( buffer, length, value );
        }

        length += 1;

    }
438828
@SuppressWarnings("deprecation")
    private static short shortBE(ByteBuf buffer, int offset) {
        return buffer.order() == ByteOrder.BIG_ENDIAN ?
                buffer.getShort(offset) : buffer.getShortLE(offset);
    }
756100
public static void writeInt32(final int value, final byte[] buffer, int offset)
    {
        buffer[offset++] = (byte) ((value >>> 24) & 0xFF);
        buffer[offset++] = (byte) ((value >>> 16) & 0xFF);
        buffer[offset++] = (byte) ((value >>> 8) & 0xFF);
        buffer[offset] = (byte) ((value >>> 0) & 0xFF);
    }
524908
public static ByteBuf copyShort(short... values) {
        if (values == null || values.length == 0) {
            return EMPTY_BUFFER;
        }
        ByteBuf buffer = buffer(values.length * 2);
        for (int v: values) {
            buffer.writeShort(v);
        }
        return buffer;
    }
670086
public static final void writeShort(short value, byte[] array, int offset)
    {
        if (array.length < offset + 2)
        {
            throw new IllegalArgumentException("no room in array");
        }
        array[offset] = (byte) (value >> 8);
        array[offset + 1] = (byte) (value & 0xff);
    }
964222
public void append(final StringBuffer buffer, final String fieldName, final long value) {
        appendFieldStart(buffer, fieldName);
        appendDetail(buffer, fieldName, value);
        appendFieldEnd(buffer, fieldName);
    }
37199
@Override
    public short[] read(ScanBuffer buffer) {
        int length = getLength(buffer);
        if (length<0) return null;
        return buffer.getShorts(length);
    }
1303769
private static short shortBE(ByteBuffer buffer, int offset) {
        return buffer.order() == ByteOrder.BIG_ENDIAN ?
                buffer.getShort(offset) : ByteBufUtil.swapShort(buffer.getShort(offset));
    }
244377
public static int search(short[] shortArray, short value) { 
        int start = 0;
        int end = shortArray.length - 1;
        int middle = 0;
        
        while(start <= end) {
            middle = (start + end) >> 1;
        
            if(value == shortArray[middle]) {
                return middle;
            }
            
            if(value < shortArray[middle]) {
                end = middle - 1 ;
            }
            else {
                start = middle + 1;
            }
        }
                

        return -1;
    }
1074606
public JBBPOut Short(final short[] value) throws IOException {
    assertNotEnded();
    assertArrayNotNull(value);
    if (this.processCommands) {
      for (final short v : value) {
        this._writeShort(v);
      }
    }
    return this;
  }
520933
public static void readFully(Reader reader, char[] buffer, int offset) throws IOException {
    int originalOffset = offset;
    int expected = buffer.length - offset;
    while (offset < buffer.length) {
      int numRead = reader.read(buffer, offset, buffer.length - offset);
      if (numRead < 0) {
        throw new IOException(
                String.format("Reached end of stream earlier than expected. Expected to read %d bytes. Actual: %d",
                expected, offset - originalOffset));
      }
      offset += numRead;
    }
  }
690909
private static final <T extends Appendable> void encodeRun(T buffer, int value, int length) {
        if (length < 4) {
            for (int j=0; j<length; ++j) {
                if (value == ESCAPE) {
                    appendInt(buffer, value);
                }
                appendInt(buffer, value);
            }
        }
        else {
            if (length == ESCAPE) {
                if (value == ESCAPE) {
                    appendInt(buffer, ESCAPE);
                }
                appendInt(buffer, value);
                --length;
            }
            appendInt(buffer, ESCAPE);
            appendInt(buffer, length);
            appendInt(buffer, value); // Don't need to escape this value
        }
    }