Пример #1
0
  public static CharBuf read(Reader input, CharBuf charBuf, final int bufSize) {

    if (charBuf == null) {
      charBuf = CharBuf.create(bufSize);
    } else {
      charBuf.readForRecycle();
    }

    try {

      char[] buffer = charBuf.toCharArray();
      int size = input.read(buffer);
      if (size != -1) {
        charBuf._len(size);
      }
      if (size < buffer.length) {
        return charBuf;
      }

      copy(input, charBuf);

    } catch (IOException e) {
      Exceptions.handle(e);
    } finally {
      try {
        input.close();
      } catch (IOException e) {
        Exceptions.handle(e);
      }
    }

    return charBuf;
  }
Пример #2
0
  public static char[] readCharBuffer(Reader input) {

    try {
      CharBuf sw = CharBuf.create(DEFAULT_BUFFER_SIZE);
      copy(input, sw);
      return sw.toCharArray();

    } finally {
      try {
        input.close();
      } catch (IOException e) {
        Exceptions.handle(e);
      }
    }
  }
Пример #3
0
  public static String prettyPrintMessageWithLinesTabs(String message) {

    String[] groups;
    String[] records;
    CharBuf charBuf = CharBuf.create(255);

    groups = split(message, DELIMITER);

    int groupNumber = 0;

    int recordNumber = 0;

    for (String group : groups) {
      records = split(group, SUB_DELIM);

      if (records.length > 1) {
        recordNumber = 0;

        charBuf
            .add("\tgrp ")
            .add(Str.lpad("" + groupNumber, 3, ' '))
            .add('\t')
            .add('\t')
            .add("start")
            .add('\n');
        for (String record : records) {
          charBuf
              .add("\t\trec ")
              .add(Str.lpad("" + recordNumber, 3, ' '))
              .add('\t')
              .add('\t')
              .add(record)
              .add('\n');
          recordNumber++;
        }
        charBuf
            .add("\tgrp ")
            .add(Str.lpad("" + groupNumber, 3, ' '))
            .add('\t')
            .add('\t')
            .add("stop")
            .add('\n');
      } else {

        charBuf
            .add("\tgrp ")
            .add(Str.lpad("" + groupNumber, 3, ' '))
            .add('\t')
            .add('\t')
            .add(group)
            .add('\n');
      }
      groupNumber++;
    }

    return charBuf.toString();
  }
Пример #4
0
  @Override
  public List<ITEM> findStartsWith(KEY keyFrag) {
    keyFrag = getKey(keyFrag);

    List<ITEM> results;

    if (keyFrag instanceof String) {
      String start = (String) keyFrag;
      if (start.length() == 0 || start == null) {
        return Collections.EMPTY_LIST;
      }

      char endLetter = start.charAt(start.length() - 1);
      String sub = start.substring(0, start.length() - 1);

      CharBuf after = CharBuf.create(start.length());

      after.add(String.valueOf(sub));
      after.add((char) (endLetter + 1));

      NavigableMap<String, MultiValue<ITEM>> sortMap =
          (NavigableMap<String, MultiValue<ITEM>>) this.navigableMap;

      SortedMap<String, MultiValue<ITEM>> sortedSubMap = sortMap.subMap(start, after.toString());

      if (sortedSubMap.size() > 0) {
        results = new ArrayList<>();
        for (MultiValue<ITEM> values : sortedSubMap.values()) {
          values.addTo(results);
        }
        return results;
      }
      return Collections.EMPTY_LIST;
    }
    return Collections.EMPTY_LIST;
  }
Пример #5
0
 public String doToString() {
   CharBuf builder = CharBuf.create(80);
   builder.add("c{");
   builder.add("\"name\":'");
   builder.add(String.valueOf(name));
   builder.add(", \"operator\":");
   builder.add(String.valueOf(operator));
   builder.add(", \"set\":");
   builder.add(String.valueOf(value));
   builder.add(", \"update\":");
   builder.add(Arrays.toString(values));
   builder.add("}");
   return builder.toString();
 }