Java 类com.intellij.util.SpinAllocator 实例源码

项目:tools-idea    文件:CompilerParsingThread.java   
private String readLine(final Reader reader) {
  StringBuilder buffer;
  boolean releaseBuffer = true;
  try {
    buffer = StringBuilderSpinAllocator.alloc();
  }
  catch (SpinAllocator.AllocatorExhaustedException e) {
    if (CompileDriver.ourDebugMode) {
      e.printStackTrace();
    }
    LOG.info(e);
    buffer = new StringBuilder();
    releaseBuffer = false;
  }

  try {
    boolean first = true;
    while (true) {
      int c = readNextByte(reader);
      if (c == -1) break;
      first = false;
      if (c == '\n') {
        if (mySkipLF) {
          mySkipLF = false;
          continue;
        }
        break;
      }
      else if (c == '\r') {
        mySkipLF = true;
        break;
      }
      else {
        mySkipLF = false;
        buffer.append((char)c);
      }
    }
    if (first) {
      return null;
    }
    return buffer.toString();
  }
  finally {
    if (releaseBuffer) {
      StringBuilderSpinAllocator.dispose(buffer);
    }
  }
}