com.intellij.psi.stubs.StubIndexKey#com.intellij.util.io.DataInputOutputUtil源码实例Demo

下面列出了com.intellij.psi.stubs.StubIndexKey#com.intellij.util.io.DataInputOutputUtil 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public void save(DataOutput dataOutput, List<Unity3dYMLAsset> list) throws IOException
{
	DataInputOutputUtil.writeSeq(dataOutput, list, asset ->
	{
		dataOutput.writeUTF(asset.getGuild());
		dataOutput.writeInt(asset.getStartOffset());
		String gameObjectName = asset.getGameObjectName();
		dataOutput.writeBoolean(gameObjectName != null);
		if(gameObjectName != null)
		{
			dataOutput.writeUTF(gameObjectName);
		}

		DataInputOutputUtil.writeSeq(dataOutput, asset.getValues(), it ->
		{
			dataOutput.writeUTF(it.getName());
			dataOutput.writeUTF(it.getValue());
			dataOutput.writeInt(it.getOffset());
		});
	});
}
 
@Override
public List<Unity3dYMLAsset> read(DataInput dataInput) throws IOException
{
	return DataInputOutputUtil.readSeq(dataInput, () ->
	{
		String guid = dataInput.readUTF();
		int startOffset = dataInput.readInt();
		boolean gameObjectCheck = dataInput.readBoolean();
		String gameObjectName = null;
		if(gameObjectCheck)
		{
			gameObjectName = dataInput.readUTF();
		}
		List<Unity3dYMLField> values = DataInputOutputUtil.readSeq(dataInput, () ->
		{
			String name = dataInput.readUTF();
			String value = dataInput.readUTF();
			int offset = dataInput.readInt();
			return new Unity3dYMLField(name, value, offset);
		});
		return new Unity3dYMLAsset(guid, gameObjectName, startOffset, values);
	});
}
 
源代码3 项目: consulo   文件: VfsDependentEnum.java
private void saveToFile(@Nonnull T instance) throws IOException {
  FileOutputStream fileOutputStream = new FileOutputStream(myFile, true);

  try (DataOutputStream output = new DataOutputStream(new BufferedOutputStream(fileOutputStream))) {
    if (myFile.length() == 0) {
      DataInputOutputUtil.writeTIME(output, FSRecords.getCreationTimestamp());
      DataInputOutputUtil.writeINT(output, myVersion);
    }
    myKeyDescriptor.save(output, instance);
  }
  finally {
    try {
      fileOutputStream.getFD().sync();
    }
    catch (IOException ignored) {
    }
  }
}
 
源代码4 项目: consulo   文件: CompressionUtil.java
public static int writeCompressed(@Nonnull DataOutput out, @Nonnull byte[] bytes, int start, int length) throws IOException {
  if (length > COMPRESSION_THRESHOLD) {
    LZ4Compressor compressor = compressor();

    byte[] compressedOutputBuffer = spareBufferLocal.getBuffer(compressor.maxCompressedLength(length));
    int compressedSize = compressor.compress(bytes, start, length, compressedOutputBuffer, 0);
    if (compressedSize < length) {
      DataInputOutputUtil.writeINT(out, -compressedSize);
      DataInputOutputUtil.writeINT(out, length - compressedSize);
      out.write(compressedOutputBuffer, 0, compressedSize);
      return compressedSize;
    }
  }
  DataInputOutputUtil.writeINT(out, length);
  out.write(bytes, start, length);
  return length;
}
 
源代码5 项目: consulo   文件: CompressionUtil.java
public static int writeCompressedWithoutOriginalBufferLength(@Nonnull DataOutput out, @Nonnull byte[] bytes, int length) throws IOException {
  long started = DUMP_COMPRESSION_STATS ? System.nanoTime() : 0;

  LZ4Compressor compressor = compressor();
  final byte[] compressedOutputBuffer = spareBufferLocal.getBuffer(compressor.maxCompressedLength(length));
  int compressedSize = compressor.compress(bytes, 0, length, compressedOutputBuffer, 0);

  final long time = (DUMP_COMPRESSION_STATS ? System.nanoTime() : 0) - started;
  mySizeAfterCompression.addAndGet(compressedSize);
  mySizeBeforeCompression.addAndGet(length);
  int requests = myCompressionRequests.incrementAndGet();
  long l = myCompressionTime.addAndGet(time);

  if (DUMP_COMPRESSION_STATS && (requests & 0x1fff) == 0) {
    System.out.println("Compressed " + requests + " times, size:" + mySizeBeforeCompression + "->" + mySizeAfterCompression + " for " + (l / 1000000) + "ms");
  }

  DataInputOutputUtil.writeINT(out, compressedSize);
  out.write(compressedOutputBuffer, 0, compressedSize);

  return compressedSize;
}
 
源代码6 项目: consulo   文件: CompressionUtil.java
@Nonnull
public static byte[] readCompressedWithoutOriginalBufferLength(@Nonnull DataInput in, int originalBufferLength) throws IOException {
  int size = DataInputOutputUtil.readINT(in);

  byte[] bytes = spareBufferLocal.getBuffer(size);
  in.readFully(bytes, 0, size);

  int decompressedRequests = myDecompressionRequests.incrementAndGet();
  long started = DUMP_COMPRESSION_STATS ? System.nanoTime() : 0;

  final byte[] decompressedResult = decompressor().decompress(bytes, 0, originalBufferLength);

  long doneTime = (DUMP_COMPRESSION_STATS ? System.nanoTime() : 0) - started;
  long decompressedSize = myDecompressedSize.addAndGet(size);
  long decompressedTime = myDecompressionTime.addAndGet(doneTime);
  if (DUMP_COMPRESSION_STATS && (decompressedRequests & 0x1fff) == 0) {
    System.out.println("Decompressed " + decompressedRequests + " times, size: " + decompressedSize + " for " + (decompressedTime / 1000000) + "ms");
  }

  return decompressedResult;
}
 
源代码7 项目: consulo   文件: CompressionUtil.java
@Nonnull
public static CharSequence uncompressStringRawBytes(@Nonnull Object compressed) {
  if (compressed instanceof CharSequence) return (CharSequence)compressed;

  ByteBuffer buffer = ByteBuffer.wrap((byte[])compressed);
  int len = DataInputOutputUtil.readINT(buffer);
  int uncompressedLength = DataInputOutputUtil.readINT(buffer) + len;

  ByteBuffer dest = ByteBuffer.wrap(spareBufferLocal.getBuffer(uncompressedLength), 0, uncompressedLength);
  decompressor().decompress(buffer, dest);
  dest.rewind();

  char[] chars = new char[len];

  for (int i = 0; i < len; i++) {
    int c = DataInputOutputUtil.readINT(dest);
    chars[i] = (char)c;
  }
  return StringFactory.createShared(chars);
}
 
源代码8 项目: consulo   文件: ChangeTrackingValueContainer.java
@Override
public void saveTo(DataOutput out, DataExternalizer<? super Value> externalizer) throws IOException {
  if (needsCompacting()) {
    getMergedData().saveTo(out, externalizer);
  }
  else {
    final TIntHashSet set = myInvalidated;
    if (set != null && set.size() > 0) {
      for (int inputId : set.toArray()) {
        DataInputOutputUtil.writeINT(out, -inputId); // mark inputId as invalid, to be processed on load in ValueContainerImpl.readFrom
      }
    }

    final UpdatableValueContainer<Value> toAppend = myAdded;
    if (toAppend != null && toAppend.size() > 0) {
      toAppend.saveTo(out, externalizer);
    }
  }
}
 
源代码9 项目: consulo   文件: StubUpdatingIndex.java
private static void rememberIndexingStamp(@Nonnull VirtualFile file, boolean isBinary, long contentByteLength, int contentCharLength) {
  try (DataOutputStream stream = INDEXED_STAMP.writeAttribute(file)) {
    DataInputOutputUtil.writeTIME(stream, file.getTimeStamp());
    DataInputOutputUtil.writeLONG(stream, contentByteLength);

    boolean lengthsAreTheSame = contentByteLength == contentCharLength;
    byte flags = 0;
    flags = BitUtil.set(flags, IS_BINARY_MASK, isBinary);
    flags = BitUtil.set(flags, BYTE_AND_CHAR_LENGTHS_ARE_THE_SAME_MASK, lengthsAreTheSame);
    stream.writeByte(flags);

    if (!lengthsAreTheSame && !isBinary) {
      DataInputOutputUtil.writeINT(stream, contentCharLength);
    }
  }
  catch (IOException e) {
    LOG.error(e);
  }
}
 
源代码10 项目: consulo   文件: StubSerializationHelper.java
private Stub deserializeRoot(StubInputStream inputStream, FileLocalStringEnumerator storage, IntEnumerator serializerLocalEnumerator) throws IOException, SerializerNotFoundException {
  ObjectStubSerializer<?, Stub> serializer = getClassById(DataInputOutputUtil.readINT(inputStream), null, serializerLocalEnumerator);
  ourRootStubSerializer.set(serializer);
  try {
    Stub stub = serializer.deserialize(inputStream, null);
    if (stub instanceof StubBase) {
      deserializeStubList((StubBase)stub, serializer, inputStream, storage, serializerLocalEnumerator);
    }
    else {
      deserializeChildren(inputStream, stub, serializerLocalEnumerator);
    }
    return stub;
  }
  finally {
    ourRootStubSerializer.set(null);
  }
}
 
源代码11 项目: consulo   文件: StubSerializationHelper.java
private void serializeStubList(StubList stubList, DataOutput out, AbstractStringEnumerator storage, IntEnumerator serializerLocalEnumerator) throws IOException {
  if (!stubList.isChildrenLayoutOptimal()) {
    throw new IllegalArgumentException("Manually assembled stubs should be normalized before serialization, consider wrapping them into StubTree");
  }

  DataInputOutputUtil.writeINT(out, stubList.size());
  DataInputOutputUtil.writeINT(out, stubList.getChildrenCount(0));

  BufferExposingByteArrayOutputStream tempBuffer = new BufferExposingByteArrayOutputStream();
  ByteArrayInterner interner = new ByteArrayInterner();

  for (int i = 1; i < stubList.size(); i++) {
    StubBase<?> stub = stubList.get(i);
    ObjectStubSerializer<Stub, Stub> serializer = writeSerializerId(stub, out, serializerLocalEnumerator);
    DataInputOutputUtil.writeINT(out, interner.internBytes(serializeStub(serializer, storage, stub, tempBuffer)));
    DataInputOutputUtil.writeINT(out, stubList.getChildrenCount(stub.id));
  }

  writeByteArray(out, interner.joinedBuffer.getInternalBuffer(), interner.joinedBuffer.size());
}
 
源代码12 项目: consulo   文件: StubSerializationHelper.java
private void deserializeChildren(StubInputStream stream, Stub parent, IntEnumerator serializerLocalEnumerator) throws IOException, SerializerNotFoundException {
  int childCount = DataInputOutputUtil.readINT(stream);
  for (int i = 0; i < childCount; i++) {
    boolean dangling = false;
    int id = DataInputOutputUtil.readINT(stream);
    if (id == 0) {
      dangling = true;
      id = DataInputOutputUtil.readINT(stream);
    }

    Stub child = getClassById(id, parent, serializerLocalEnumerator).deserialize(stream, parent);
    if (dangling) {
      ((ObjectStubBase)child).markDangling();
    }
    deserializeChildren(stream, child, serializerLocalEnumerator);
  }
}
 
源代码13 项目: consulo   文件: IntEnumerator.java
void dump(DataOutputStream stream, IntUnaryOperator idRemapping) throws IOException {
  DataInputOutputUtil.writeINT(stream, myIds.size());
  IOException[] exception = new IOException[1];
  myIds.forEach(id -> {
    try {
      int remapped = idRemapping.applyAsInt(id);
      if (remapped == 0) {
        exception[0] = new IOException("remapping is not found for " + id);
        return false;
      }
      DataInputOutputUtil.writeINT(stream, remapped);
    }
    catch (IOException e) {
      exception[0] = e;
      return false;
    }
    return true;
  });
  if (exception[0] != null) {
    throw exception[0];
  }
}
 
源代码14 项目: consulo   文件: VirtualFileGistImpl.java
@Override
public Data getFileData(@Nullable Project project, @Nonnull VirtualFile file) {
  ApplicationManager.getApplication().assertReadAccessAllowed();
  ProgressManager.checkCanceled();

  if (!(file instanceof VirtualFileWithId)) return myCalculator.calcData(project, file);

  int stamp = PersistentFS.getInstance().getModificationCount(file) + ((GistManagerImpl)GistManager.getInstance()).getReindexCount();

  try (DataInputStream stream = getFileAttribute(project).readAttribute(file)) {
    if (stream != null && DataInputOutputUtil.readINT(stream) == stamp) {
      return stream.readBoolean() ? myExternalizer.read(stream) : null;
    }
  }
  catch (IOException e) {
    LOG.error(e);
  }

  Data result = myCalculator.calcData(project, file);
  cacheResult(stamp, result, project, file);
  return result;
}
 
源代码15 项目: consulo   文件: DuplicatesIndex.java
@Override
public void save(@Nonnull DataOutput out, TIntArrayList list) throws IOException {
  if (list.size() == 2) {
    DataInputOutputUtil.writeINT(out, list.getQuick(0));
    DataInputOutputUtil.writeINT(out, list.getQuick(1));
  }
  else {
    DataInputOutputUtil.writeINT(out, -list.size());
    int prev = 0;
    for (int i = 0, len = list.size(); i < len; i+=2) {
      int value = list.getQuick(i);
      DataInputOutputUtil.writeINT(out, value - prev);
      prev = value;
      DataInputOutputUtil.writeINT(out, list.getQuick(i + 1));
    }
  }
}
 
源代码16 项目: consulo   文件: DirectoryEntry.java
public DirectoryEntry(DataInput in, @SuppressWarnings("unused") boolean dummy /* to distinguish from general constructor*/) throws IOException {
  super(in);
  int count = DataInputOutputUtil.readINT(in);
  myChildren = new ArrayList<>(count);
  while (count-- > 0) {
    unsafeAddChild(StreamUtil.readEntry(in));
  }
}
 
源代码17 项目: consulo   文件: DirectoryEntry.java
@Override
public void write(DataOutput out) throws IOException {
  super.write(out);
  DataInputOutputUtil.writeINT(out, myChildren.size());
  for (Entry child : myChildren) {
    StreamUtil.writeEntry(out, child);
  }
}
 
源代码18 项目: consulo   文件: TranslationSourceFileInfo.java
TranslationSourceFileInfo(@Nonnull DataInput in) throws IOException {
  final int projCount = DataInputOutputUtil.readINT(in);
  for (int idx = 0; idx < projCount; idx++) {
    final int projectId = DataInputOutputUtil.readINT(in);
    final long stamp = DataInputOutputUtil.readTIME(in);
    updateTimestamp(projectId, stamp);

    final int pathsCount = DataInputOutputUtil.readINT(in);
    for (int i = 0; i < pathsCount; i++) {
      final int path = in.readInt();
      addOutputPath(projectId, path);
    }
  }
}
 
源代码19 项目: consulo   文件: HashImpl.java
@Nonnull
public static Hash read(@Nonnull DataInput in) throws IOException {
  int length = DataInputOutputUtil.readINT(in);
  if (length == 0) throw new IOException("Can not read hash: data length is zero");
  byte[] buf = new byte[length];
  in.readFully(buf);
  return new HashImpl(buf);
}
 
源代码20 项目: consulo   文件: CompressionUtil.java
@Nonnull
public static Object compressStringRawBytes(@Nonnull CharSequence string) {
  int length = string.length();
  if (length < STRING_COMPRESSION_THRESHOLD) {
    if (string instanceof CharBuffer && ((CharBuffer)string).capacity() > STRING_COMPRESSION_THRESHOLD) {
      string = string.toString();   // shrink to size
    }
    return string;
  }
  try {
    BufferExposingByteArrayOutputStream bytes = new BufferExposingByteArrayOutputStream(length);
    @Nonnull DataOutput out = new DataOutputStream(bytes);

    for (int i = 0; i < length; i++) {
      char c = string.charAt(i);
      DataInputOutputUtil.writeINT(out, c);
    }

    LZ4Compressor compressor = compressor();
    int bytesWritten = bytes.size();
    ByteBuffer dest = ByteBuffer.wrap(spareBufferLocal.getBuffer(compressor.maxCompressedLength(bytesWritten) + 10));
    DataInputOutputUtil.writeINT(dest, length);
    DataInputOutputUtil.writeINT(dest, bytesWritten - length);
    compressor.compress(ByteBuffer.wrap(bytes.getInternalBuffer(), 0, bytesWritten), dest);

    return dest.position() < length * 2 ? Arrays.copyOf(dest.array(), dest.position()) : string;
  }
  catch (IOException e) {
    e.printStackTrace();
    return string;
  }
}
 
源代码21 项目: consulo   文件: ValueContainerImpl.java
@Override
public void saveTo(DataOutput out, DataExternalizer<? super Value> externalizer) throws IOException {
  DataInputOutputUtil.writeINT(out, size());

  for (final InvertedIndexValueIterator<Value> valueIterator = getValueIterator(); valueIterator.hasNext(); ) {
    final Value value = valueIterator.next();
    externalizer.save(out, value);
    Object fileSetObject = valueIterator.getFileSetObject();

    if (fileSetObject instanceof Integer) {
      DataInputOutputUtil.writeINT(out, (Integer)fileSetObject); // most common 90% case during index building
    }
    else {
      // serialize positive file ids with delta encoding
      ChangeBufferingList originalInput = (ChangeBufferingList)fileSetObject;
      IntIdsIterator intIterator = originalInput.sortedIntIterator();
      if (DebugAssertions.DEBUG) DebugAssertions.assertTrue(intIterator.hasAscendingOrder());

      if (intIterator.size() == 1) {
        DataInputOutputUtil.writeINT(out, intIterator.next());
      }
      else {
        DataInputOutputUtil.writeINT(out, -intIterator.size());
        int prev = 0;

        while (intIterator.hasNext()) {
          int fileId = intIterator.next();
          DataInputOutputUtil.writeINT(out, fileId - prev);
          prev = fileId;
        }
      }
    }
  }
}
 
源代码22 项目: consulo   文件: InputIndexDataExternalizer.java
@Override
public void save(@Nonnull DataOutput out, @Nonnull Collection<K> value) throws IOException {
  try {
    DataInputOutputUtil.writeINT(out, value.size());
    for (K key : value) {
      myKeyDescriptor.save(out, key);
    }
  }
  catch (IllegalArgumentException e) {
    throw new IOException("Error saving data for index " + myIndexId, e);
  }
}
 
源代码23 项目: consulo   文件: InputIndexDataExternalizer.java
@Nonnull
@Override
public Collection<K> read(@Nonnull DataInput in) throws IOException {
  try {
    final int size = DataInputOutputUtil.readINT(in);
    final List<K> list = new ArrayList<>(size);
    for (int idx = 0; idx < size; idx++) {
      list.add(myKeyDescriptor.read(in));
    }
    return list;
  }
  catch (IllegalArgumentException e) {
    throw new IOException("Error reading data for index " + myIndexId, e);
  }
}
 
源代码24 项目: consulo   文件: StubUpdatingIndex.java
@Nullable
static IndexingStampInfo getIndexingStampInfo(@Nonnull VirtualFile file) {
  try (DataInputStream stream = INDEXED_STAMP.readAttribute(file)) {
    if (stream == null) {
      return null;
    }
    long stamp = DataInputOutputUtil.readTIME(stream);
    long byteLength = DataInputOutputUtil.readLONG(stream);

    byte flags = stream.readByte();
    boolean isBinary = BitUtil.isSet(flags, IS_BINARY_MASK);
    boolean readOnlyOneLength = BitUtil.isSet(flags, BYTE_AND_CHAR_LENGTHS_ARE_THE_SAME_MASK);

    int charLength;
    if (isBinary) {
      charLength = -1;
    }
    else if (readOnlyOneLength) {
      charLength = (int)byteLength;
    }
    else {
      charLength = DataInputOutputUtil.readINT(stream);
    }
    return new IndexingStampInfo(stamp, byteLength, charLength);
  }
  catch (IOException e) {
    LOG.error(e);
    return null;
  }
}
 
@Override
public final void save(@Nonnull final DataOutput out, @Nonnull final SerializedStubTree tree) throws IOException {
  if (PersistentHashMapValueStorage.COMPRESSION_ENABLED) {
    DataInputOutputUtil.writeINT(out, tree.myTreeByteLength);
    out.write(tree.myTreeBytes, 0, tree.myTreeByteLength);
    if (myIncludeInputs) {
      DataInputOutputUtil.writeINT(out, tree.myIndexedStubByteLength);
      out.write(tree.myIndexedStubBytes, 0, tree.myIndexedStubByteLength);
    }
  }
  else {
    CompressionUtil.writeCompressed(out, tree.myTreeBytes, 0, tree.myTreeByteLength);
    if (myIncludeInputs) CompressionUtil.writeCompressed(out, tree.myIndexedStubBytes, 0, tree.myIndexedStubByteLength);
  }
}
 
源代码26 项目: consulo   文件: StubSerializationHelper.java
private void serializeChildren(@Nonnull Stub parent, @Nonnull StubOutputStream stream, IntEnumerator serializerLocalEnumerator) throws IOException {
  final List<? extends Stub> children = parent.getChildrenStubs();
  DataInputOutputUtil.writeINT(stream, children.size());
  for (Stub child : children) {
    serializeSelf(child, stream, serializerLocalEnumerator);
    serializeChildren(child, stream, serializerLocalEnumerator);
  }
}
 
源代码27 项目: consulo   文件: StubSerializationHelper.java
void serialize(@Nonnull Stub rootStub, @Nonnull OutputStream stream) throws IOException {
  BufferExposingByteArrayOutputStream out = new BufferExposingByteArrayOutputStream();
  FileLocalStringEnumerator storage = new FileLocalStringEnumerator(true);
  IntEnumerator selializerIdLocalEnumerator = new IntEnumerator();
  StubOutputStream stubOutputStream = new StubOutputStream(out, storage);
  boolean doDefaultSerialization = true;

  if (rootStub instanceof PsiFileStubImpl) {
    final PsiFileStub[] roots = ((PsiFileStubImpl<?>)rootStub).getStubRoots();
    if (roots.length == 0) {
      Logger.getInstance(getClass()).error("Incorrect stub files count during serialization:" + rootStub + "," + rootStub.getStubType());
    }
    else {
      doDefaultSerialization = false;
      DataInputOutputUtil.writeINT(stubOutputStream, roots.length);
      for (PsiFileStub root : roots) {
        serializeRoot(stubOutputStream, root, storage, selializerIdLocalEnumerator);
      }
    }
  }

  if (doDefaultSerialization) {
    DataInputOutputUtil.writeINT(stubOutputStream, 1);
    serializeRoot(stubOutputStream, rootStub, storage, selializerIdLocalEnumerator);
  }
  DataOutputStream resultStream = new DataOutputStream(stream);
  selializerIdLocalEnumerator.dump(resultStream);
  storage.write(resultStream);
  resultStream.write(out.getInternalBuffer(), 0, out.size());
}
 
源代码28 项目: consulo   文件: StubSerializationHelper.java
private byte[] readByteArray(StubInputStream inputStream) throws IOException {
  int length = DataInputOutputUtil.readINT(inputStream);
  if (length == 0) return ArrayUtilRt.EMPTY_BYTE_ARRAY;

  byte[] array = new byte[length];
  int read = inputStream.read(array);
  if (read != array.length) {
    Logger.getInstance(getClass()).error("Serialized array length mismatch");
  }
  return array;
}
 
源代码29 项目: consulo   文件: FileLocalStringEnumerator.java
static void readEnumeratedStrings(@Nonnull FileLocalStringEnumerator enumerator, @Nonnull DataInput stream, @Nonnull UnaryOperator<String> interner) throws IOException {
  final int numberOfStrings = DataInputOutputUtil.readINT(stream);
  byte[] buffer = IOUtil.allocReadWriteUTFBuffer();
  enumerator.myStrings.ensureCapacity(numberOfStrings);

  int i = 0;
  while (i < numberOfStrings) {
    String s = interner.apply(IOUtil.readUTFFast(buffer, stream));
    enumerator.myStrings.add(s);
    ++i;
  }
}
 
源代码30 项目: consulo   文件: IntEnumerator.java
static IntEnumerator read(DataInputStream stream) throws IOException {
  int size = DataInputOutputUtil.readINT(stream);
  IntEnumerator enumerator = new IntEnumerator(false);
  for (int i = 1; i < size + 1; i++) {
    enumerator.myIds.add(DataInputOutputUtil.readINT(stream));
  }
  return enumerator;
}