Package lombok

Examples of lombok.val


   */
  @Validate
  public static byte[] readUntil(@NotNull final InputStream stream, final byte terminator)
      throws IOException
  {
    val result = new ByteArrayOutputStream(128);

    while (true)
    {
      // read next byte
      val read = stream.read();

      // check status
      if (read >= 0)
      {
        val bt = (byte) read;

        if (bt == terminator)
          break;

        result.write(bt);
View Full Code Here


   */
  @Validate
  public static byte[] readUntil(@NotNull final InputStream stream, @NotNull final byte[] terminator)
      throws IOException
  {
    val result = new ByteArrayOutputStream(128);

    // buffer holding the latest bytes
    val tempBuffer = new byte[terminator.length];

    // read the first batch
    for (int i = 0; i < tempBuffer.length; i++)
    {
      int read = stream.read();

      // check status
      if (read >= 0)
        tempBuffer[i] = (byte) read;
      else
        throw new IOException(String.format(EOF_EXCEPTION_MESSAGE_BYTES, tempBuffer.length - i));
    }
    result.write(tempBuffer, 0, tempBuffer.length);

    // compare and read next until arrays hold equal values
    while (!(ByteArrayUtils.sequenceEqual(tempBuffer, terminator)))
    {
      // read next byte
      val read = stream.read();

      // check status
      if (read >= 0)
      {
        val bt = (byte) read;

        // shift elements in array to the left, throw away the first read
        for (int i = 0; i < tempBuffer.length - 1; i++)
          tempBuffer[i] = tempBuffer[i + 1];

View Full Code Here

   */
  @Validate
  public static String readUntil(InputStream stream, byte[] terminator, @NotNull final Charset streamEncoding)
      throws IOException
  {
    val ba = readUntil(stream, terminator);
    val result = streamEncoding.decode(ByteBuffer.wrap(ba));
    return result.toString();
  }
View Full Code Here

   */
  @Validate
  public static char readCharacter(@NotNull final InputStream stream, @NotNull final Charset streamEncoding)
      throws IOException
  {
    val byteBuffer = ByteBuffer.allocate(8);

    CharBuffer chars;
    do
    {
      int b = stream.read();

      if (b < 0)
        throw new IOException(String.format(EOF_EXCEPTION_MESSAGE_CHARACTERS, 1));

      byteBuffer.put((byte) b);

      // attempt to decode byte -> char, returns 0 if failed
      chars = streamEncoding.decode(byteBuffer);
    }
    while (chars.length() == 0);
View Full Code Here

      throws IOException
  {
    if (count < 0)
      throw new IllegalArgumentException("count=" + count);

    val sb = new StringBuilder(256);

    for (int i = 0; i < count; i++)
      sb.append(readCharacter(textStream));

    return sb.toString();
  }
View Full Code Here

   */
  public static String readUntil(final Reader textStream, final char terminator)
      throws IOException
  {
    char ch;
    val sb = new StringBuilder(256);

    while ((ch = readCharacter(textStream)) != terminator)
      sb.append(ch);

    return sb.toString();
  }
View Full Code Here

   */
  @Validate
  public static String readUntil(final Reader textStream, @NotNull final String terminator)
      throws IOException
  {
    val result = new StringBuilder(256);

    // this is the terminator string
    val terminatorChars = terminator.toCharArray();

    // buffer holding the latest characters
    val tempBuffer = new char[terminatorChars.length];

    // read the first batch
    for (int i = 0; i < tempBuffer.length; i++)
    {
      tempBuffer[i] = readCharacter(textStream);
      result.append(tempBuffer[i]);
    }

    // compare and read next until arrays hold equal values
    while (!(StringUtils.sequenceEqual(terminatorChars, tempBuffer)))
    {
      // read next char
      val ch = readCharacter(textStream);

      // left shift elements in array, throw away the first read
      for (int i = 0; i < tempBuffer.length - 1; i++)
        tempBuffer[i] = tempBuffer[i + 1];

View Full Code Here

   * @throws IOException An I/O exception occurred.
   */
  public static String readUntilPeeking(final Reader textStream, final char terminator)
      throws IOException
  {
    val result = new StringBuilder(256);
    while (peekCharacter(textStream) != terminator)
      result.append(readCharacter(textStream));

    return result.toString();
  }
View Full Code Here

   */
  @Validate
  public static char readCharacter(@NotNull final Reader textStream)
      throws IOException
  {
    val ch = textStream.read();

    if (ch < 0)
      throw new IOException(String.format(EOF_EXCEPTION_MESSAGE_CHARACTERS, 1));

    return (char) ch;
View Full Code Here

      throws IOException
  {
    if (count < 0)
      throw new IllegalArgumentException("count=" + count);

    val result = new char[count];
    int i = 0;

    try
    {
      for (i = 0; i < count; i++)
View Full Code Here

TOP

Related Classes of lombok.val

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.