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

项目:intellij-ce-playground    文件:SerializedStubTree.java   
public SerializedStubTree(DataInput in) throws IOException {
  if (PersistentHashMapValueStorage.COMPRESSION_ENABLED) {
    int serializedStubsLength = DataInputOutputUtil.readINT(in);
    byte[] bytes = new byte[serializedStubsLength];
    in.readFully(bytes);
    myBytes = bytes;
    myLength = myBytes.length;
    myByteContentLength = DataInputOutputUtil.readLONG(in);
    myCharContentLength = DataInputOutputUtil.readINT(in);
  } else {
    myBytes = CompressionUtil.readCompressed(in);
    myLength = myBytes.length;
    myByteContentLength = in.readLong();
    myCharContentLength = in.readInt();
  }
}
项目:consulo    文件:SerializedStubTree.java   
public SerializedStubTree(DataInput in) throws IOException {
  if (PersistentHashMapValueStorage.COMPRESSION_ENABLED) {
    int serializedStubsLength = DataInputOutputUtil.readINT(in);
    byte[] bytes = new byte[serializedStubsLength];
    in.readFully(bytes);
    myBytes = bytes;
    myLength = myBytes.length;
    myByteContentLength = DataInputOutputUtil.readLONG(in);
    myCharContentLength = DataInputOutputUtil.readINT(in);
  } else {
    myBytes = CompressionUtil.readCompressed(in);
    myLength = myBytes.length;
    myByteContentLength = in.readLong();
    myCharContentLength = in.readInt();
  }
}
项目:consulo    文件:SnapshotInputMappings.java   
private PersistentHashMap<Integer, String> createIndexingTrace() throws IOException {
  final File mapFile = new File(IndexInfrastructure.getIndexRootDir(myIndexId), "indextrace");
  try {
    return new PersistentHashMap<>(mapFile, EnumeratorIntegerDescriptor.INSTANCE,
                                   new DataExternalizer<String>() {
                                     @Override
                                     public void save(@Nonnull DataOutput out, String value) throws IOException {
                                       out.write((byte[])CompressionUtil.compressCharSequence(value, Charset.defaultCharset()));
                                     }

                                     @Override
                                     public String read(@Nonnull DataInput in) throws IOException {
                                       byte[] b = new byte[((InputStream)in).available()];
                                       in.readFully(b);
                                       return (String)CompressionUtil.uncompressCharSequence(b, Charset.defaultCharset());
                                     }
                                   }, 4096);
  }
  catch (IOException ex) {
    IOUtil.deleteAllFilesStartingWith(mapFile);
    throw ex;
  }
}
项目:intellij-ce-playground    文件:FSRecords.java   
private static DataInputStream doReadContentById(int contentId) throws IOException {
  DataInputStream stream = getContentStorage().readStream(contentId);
  if (useSnappyForCompression) {
    byte[] bytes = CompressionUtil.readCompressed(stream);
    stream = new DataInputStream(new ByteArrayInputStream(bytes));
  }

  return stream;
}
项目:intellij-ce-playground    文件:EditorChangeAction.java   
public EditorChangeAction(@NotNull DocumentEx document,
                          int offset,
                          @NotNull CharSequence oldString,
                          @NotNull CharSequence newString,
                          long oldTimeStamp) {
  super(document);
  myOffset = offset;
  myOldString = CompressionUtil.compressStringRawBytes(oldString);
  myNewString = CompressionUtil.compressStringRawBytes(newString);
  myOldTimeStamp = oldTimeStamp;
  myNewTimeStamp = document.getModificationStamp();
}
项目:intellij-ce-playground    文件:EditorChangeAction.java   
@Override
public void redo() {
  DocumentUndoProvider.startDocumentUndo(getDocument());
  try {
    CharSequence oldString = CompressionUtil.uncompressStringRawBytes(myOldString);
    CharSequence newString = CompressionUtil.uncompressStringRawBytes(myNewString);
    exchangeStrings(oldString, newString);
  }
  finally {
    DocumentUndoProvider.finishDocumentUndo(getDocument());
  }
  getDocument().setModificationStamp(myNewTimeStamp);
  refreshFileStatus();
}
项目:intellij-ce-playground    文件:SerializedStubTree.java   
public void write(DataOutput out) throws IOException {
  if (PersistentHashMapValueStorage.COMPRESSION_ENABLED) {
    DataInputOutputUtil.writeINT(out, myLength);
    out.write(myBytes, 0, myLength);
    DataInputOutputUtil.writeLONG(out, myByteContentLength);
    DataInputOutputUtil.writeINT(out, myCharContentLength);
  } else {
    CompressionUtil.writeCompressed(out, myBytes, myLength);
    out.writeLong(myByteContentLength);
    out.writeInt(myCharContentLength);
  }
}
项目:consulo    文件:FSRecords.java   
private static DataInputStream doReadContentById(int contentId) throws IOException {
  DataInputStream stream = getContentStorage().readStream(contentId);
  if (useSnappyForCompression) {
    byte[] bytes = CompressionUtil.readCompressed(stream);
    stream = new DataInputStream(new ByteArrayInputStream(bytes));
  }

  return stream;
}
项目:consulo    文件:EditorChangeAction.java   
public EditorChangeAction(@Nonnull DocumentEx document,
                          int offset,
                          @Nonnull CharSequence oldString,
                          @Nonnull CharSequence newString,
                          long oldTimeStamp) {
  super(document);
  myOffset = offset;
  myOldString = CompressionUtil.compressStringRawBytes(oldString);
  myNewString = CompressionUtil.compressStringRawBytes(newString);
  myOldTimeStamp = oldTimeStamp;
  myNewTimeStamp = document.getModificationStamp();
  myNewLength = document.getTextLength();
  myOldLength = myNewLength - newString.length() + oldString.length();
}
项目:consulo    文件:EditorChangeAction.java   
@Override
public void redo() throws UnexpectedUndoException {
  validateDocumentLength(myOldLength);
  DocumentUndoProvider.startDocumentUndo(getDocument());
  try {
    CharSequence oldString = CompressionUtil.uncompressStringRawBytes(myOldString);
    CharSequence newString = CompressionUtil.uncompressStringRawBytes(myNewString);
    exchangeStrings(oldString, newString);
  }
  finally {
    DocumentUndoProvider.finishDocumentUndo(getDocument());
  }
  getDocument().setModificationStamp(myNewTimeStamp);
  refreshFileStatus();
}
项目:consulo    文件:SerializedStubTree.java   
public void write(DataOutput out) throws IOException {
  if (PersistentHashMapValueStorage.COMPRESSION_ENABLED) {
    DataInputOutputUtil.writeINT(out, myLength);
    out.write(myBytes, 0, myLength);
    DataInputOutputUtil.writeLONG(out, myByteContentLength);
    DataInputOutputUtil.writeINT(out, myCharContentLength);
  } else {
    CompressionUtil.writeCompressed(out, myBytes, myLength);
    out.writeLong(myByteContentLength);
    out.writeInt(myCharContentLength);
  }
}
项目:intellij-ce-playground    文件:EditorChangeAction.java   
public void performUndo() {
  CharSequence oldString = CompressionUtil.uncompressStringRawBytes(myOldString);
  CharSequence newString = CompressionUtil.uncompressStringRawBytes(myNewString);
  exchangeStrings(newString, oldString);
}
项目:intellij-ce-playground    文件:CompressedAppendableFile.java   
private synchronized void initChunkLengthTable() throws IOException {
  if (myChunkLengthTable != null) return;
  File chunkLengthFile = getChunkLengthFile();

  if (chunkLengthFile.exists()) {
    final DataInputStream chunkLengthStream = new DataInputStream(new BufferedInputStream(
      new LimitedInputStream(new FileInputStream(chunkLengthFile), (int)chunkLengthFile.length()) {
        @Override
        public int available() throws IOException {
          return remainingLimit();
        }
      }, 32768));
    try{
      short[] chunkLengthTable = new short[(int)(chunkLengthFile.length() / 2)];
      int chunkLengthTableLength = 0;

      long o = 0;
      while (chunkLengthStream.available() != 0) {
        int chunkLength = DataInputOutputUtil.readINT(chunkLengthStream);
        o += chunkLength;
        if (chunkLengthTableLength == chunkLengthTable.length) {
          chunkLengthTable = reallocShortTable(chunkLengthTable);
        }
        chunkLengthTable[chunkLengthTableLength++] = (short)chunkLength;
        if (doDebug) myCompressedChunksFileOffsets.add(o);
      }
      myChunkLengthTable = chunkLengthTable;
      myChunkTableLength = chunkLengthTableLength;

      if (myChunkTableLength >= FACTOR) {
        long[] chunkOffsetTable = new long[myChunkTableLength / FACTOR];
        long offset = 0;
        for(int i = 0; i < chunkOffsetTable.length; ++i) {
          int start = i * FACTOR;
          for(int j = 0; j < FACTOR; ++j) {
            offset += (chunkLengthTable[start + j] & MAX_PAGE_LENGTH);
          }
          chunkOffsetTable[i] = offset;
        }
        myChunkOffsetTable = chunkOffsetTable;
        if (doDebug) { // check all offsets
          for(int i = 0; i < chunkLengthTableLength; ++i) {
            calcOffsetOfPage(i);
          }
        }
      } else {
        myChunkOffsetTable = ArrayUtil.EMPTY_LONG_ARRAY;
      }

      myFileLength = calcOffsetOfPage(myChunkTableLength - 1);
    } finally {
      try {
        chunkLengthStream.close();
      } catch (IOException ignore) {}
    }
  }
  else {
    myChunkLengthTable = ArrayUtil.EMPTY_SHORT_ARRAY;
    myChunkTableLength = 0;
    myChunkOffsetTable = ArrayUtil.EMPTY_LONG_ARRAY;
    myFileLength = 0;
  }

  if (myUncompressedFileLength == -1) {
    long tempFileLength = getIncompleteChunkFile().length();
    myUncompressedFileLength = ((long)myChunkTableLength * myAppendBufferLength) + tempFileLength;
    if (myUncompressedFileLength != myFileLength + tempFileLength) {
      if (CompressionUtil.DUMP_COMPRESSION_STATS) {
        System.out.println(myUncompressedFileLength + "->" + (myFileLength + tempFileLength) + " for " + myBaseFile);
      }
    }
  }
}
项目:intellij-ce-playground    文件:CompressedAppendableFile.java   
protected int compress(DataOutputStream compressedDataOut, byte[] buffer) throws IOException {
  return CompressionUtil.writeCompressedWithoutOriginalBufferLength(compressedDataOut, buffer, myAppendBufferLength);
}
项目:intellij-ce-playground    文件:CompressedAppendableFile.java   
protected byte[] decompress(DataInputStream keysStream) throws IOException {
  return CompressionUtil.readCompressedWithoutOriginalBufferLength(keysStream);
}
项目:tools-idea    文件:SerializedStubTree.java   
public SerializedStubTree(DataInput in) throws IOException {
  myBytes = CompressionUtil.readCompressed(in);
  myLength = myBytes.length;
  myByteContentLength = in.readLong();
  myCharContentLength = in.readInt();
}
项目:tools-idea    文件:SerializedStubTree.java   
public void write(DataOutput out) throws IOException {
  CompressionUtil.writeCompressed(out, myBytes, myLength);
  out.writeLong(myByteContentLength);
  out.writeInt(myCharContentLength);
}
项目:consulo    文件:EditorChangeAction.java   
public void performUndo() {
  CharSequence oldString = CompressionUtil.uncompressStringRawBytes(myOldString);
  CharSequence newString = CompressionUtil.uncompressStringRawBytes(myNewString);
  exchangeStrings(newString, oldString);
}
项目:consulo    文件:CompressedAppendableFile.java   
private synchronized void initChunkLengthTable() throws IOException {
  if (myChunkLengthTable != null) return;
  File chunkLengthFile = getChunkLengthFile();

  if (chunkLengthFile.exists()) {
    final DataInputStream chunkLengthStream = new DataInputStream(new BufferedInputStream(
            new LimitedInputStream(new FileInputStream(chunkLengthFile), (int)chunkLengthFile.length()) {
              @Override
              public int available() throws IOException {
                return remainingLimit();
              }
            }, 32768));
    try{
      short[] chunkLengthTable = new short[(int)(chunkLengthFile.length() / 2)];
      int chunkLengthTableLength = 0;

      long o = 0;
      while (chunkLengthStream.available() != 0) {
        int chunkLength = DataInputOutputUtil.readINT(chunkLengthStream);
        o += chunkLength;
        if (chunkLengthTableLength == chunkLengthTable.length) {
          chunkLengthTable = reallocShortTable(chunkLengthTable);
        }
        chunkLengthTable[chunkLengthTableLength++] = (short)chunkLength;
        if (doDebug) myCompressedChunksFileOffsets.add(o);
      }
      myChunkLengthTable = chunkLengthTable;
      myChunkTableLength = chunkLengthTableLength;

      if (myChunkTableLength >= FACTOR) {
        long[] chunkOffsetTable = new long[myChunkTableLength / FACTOR];
        long offset = 0;
        for(int i = 0; i < chunkOffsetTable.length; ++i) {
          int start = i * FACTOR;
          for(int j = 0; j < FACTOR; ++j) {
            offset += (chunkLengthTable[start + j] & MAX_PAGE_LENGTH);
          }
          chunkOffsetTable[i] = offset;
        }
        myChunkOffsetTable = chunkOffsetTable;
        if (doDebug) { // check all offsets
          for(int i = 0; i < chunkLengthTableLength; ++i) {
            calcOffsetOfPage(i);
          }
        }
      } else {
        myChunkOffsetTable = ArrayUtil.EMPTY_LONG_ARRAY;
      }

      myFileLength = calcOffsetOfPage(myChunkTableLength - 1);
    } finally {
      try {
        chunkLengthStream.close();
      } catch (IOException ignore) {}
    }
  }
  else {
    myChunkLengthTable = ArrayUtil.EMPTY_SHORT_ARRAY;
    myChunkTableLength = 0;
    myChunkOffsetTable = ArrayUtil.EMPTY_LONG_ARRAY;
    myFileLength = 0;
  }

  if (myUncompressedFileLength == -1) {
    long tempFileLength = getIncompleteChunkFile().length();
    myUncompressedFileLength = ((long)myChunkTableLength * myAppendBufferLength) + tempFileLength;
    if (myUncompressedFileLength != myFileLength + tempFileLength) {
      if (CompressionUtil.DUMP_COMPRESSION_STATS) {
        System.out.println(myUncompressedFileLength + "->" + (myFileLength + tempFileLength) + " for " + myBaseFile);
      }
    }
  }
}
项目:consulo    文件:CompressedAppendableFile.java   
protected int compress(DataOutputStream compressedDataOut, byte[] buffer) throws IOException {
  return CompressionUtil.writeCompressedWithoutOriginalBufferLength(compressedDataOut, buffer, myAppendBufferLength);
}
项目:consulo    文件:CompressedAppendableFile.java   
protected byte[] decompress(DataInputStream keysStream) throws IOException {
  return CompressionUtil.readCompressedWithoutOriginalBufferLength(keysStream);
}