Java Code Examples for com.intellij.util.io.DataInputOutputUtil#readINT()

The following examples show how to use com.intellij.util.io.DataInputOutputUtil#readINT() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VirtualFileGistImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 2
Source File: CompressionUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example 3
Source File: CompressionUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 4
Source File: StubSerializationHelper.java    From consulo with Apache License 2.0 6 votes vote down vote up
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);
  }
}
 
Example 5
Source File: StubSerializationHelper.java    From consulo with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 6
Source File: InputMapExternalizer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public Map<Key, Value> read(@Nonnull DataInput in) throws IOException {
  int pairs = DataInputOutputUtil.readINT(in);
  if (pairs == 0) return Collections.emptyMap();
  Map<Key, Value> result = new THashMap<>(pairs);
  while (((InputStream)in).available() > 0) {
    Value value = myValueExternalizer.read(in);
    Collection<Key> keys = mySnapshotIndexExternalizer.read(in);
    for (Key k : keys) result.put(k, value);
  }
  return result;
}
 
Example 7
Source File: PersistentIndicesConfiguration.java    From consulo with Apache License 2.0 5 votes vote down vote up
static void loadConfiguration() {
  try (DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(indicesConfigurationFile())))) {
    if (DataInputOutputUtil.readINT(in) == INDICES_CONFIGURATION_VERSION) {
      IndexingStamp.initPersistentIndexStamp(in);
    }
  }
  catch (IOException ignored) {
  }
}
 
Example 8
Source File: IndexingStamp.java    From consulo with Apache License 2.0 5 votes vote down vote up
IndexVersion(DataInput in) throws IOException {
  myIndexVersion = DataInputOutputUtil.readINT(in);
  myCommonIndicesVersion = DataInputOutputUtil.readINT(in);
  myVfsCreationStamp = DataInputOutputUtil.readTIME(in);
  myModificationCount = DataInputOutputUtil.readTIME(in);
  advanceIndexStamp(myModificationCount);
}
 
Example 9
Source File: StubVersionMap.java    From consulo with Apache License 2.0 5 votes vote down vote up
public boolean isIndexed(int fileId, @Nonnull VirtualFile file) throws IOException {
  DataInputStream stream = FSRecords.readAttributeWithLock(fileId, VERSION_STAMP);
  int diff = stream != null ? DataInputOutputUtil.readINT(stream) : 0;
  if (diff == 0) return false;
  FileType fileType = getFileTypeByIndexingTimestampDiff(diff);
  return fileType != null && getStamp(file.getFileType()) == getStamp(fileType);
}
 
Example 10
Source File: StubForwardIndexExternalizer.java    From consulo with Apache License 2.0 5 votes vote down vote up
<K> Map<StubIndexKey, Map<Object, StubIdList>> doRead(@Nonnull DataInput in, @Nullable StubIndexKey<K, ?> requestedIndex, @Nullable K requestedKey) throws IOException {
  if (!myEnsuredStubElementTypesLoaded) {
    ProgressManager.getInstance().executeNonCancelableSection(() -> {
      SerializationManager.getInstance().initSerializers();
      StubIndexImpl.initExtensions();
    });
    myEnsuredStubElementTypesLoaded = true;
  }
  int stubIndicesValueMapSize = DataInputOutputUtil.readINT(in);
  if (stubIndicesValueMapSize > 0) {
    THashMap<StubIndexKey, Map<Object, StubIdList>> stubIndicesValueMap = requestedIndex != null ? null : new THashMap<>(stubIndicesValueMapSize);
    StubIndexImpl stubIndex = (StubIndexImpl)StubIndex.getInstance();
    StubKeySerializationState stubKeySerializationState = createStubIndexKeySerializationState(in, stubIndicesValueMapSize);
    for (int i = 0; i < stubIndicesValueMapSize; ++i) {
      ID<Object, ?> indexKey = (ID<Object, ?>)readStubIndexKey(in, stubKeySerializationState);
      if (indexKey instanceof StubIndexKey) { // indexKey can be ID in case of removed index
        StubIndexKey<Object, ?> stubIndexKey = (StubIndexKey<Object, ?>)indexKey;
        boolean deserialize = requestedIndex == null || requestedIndex.equals(stubIndexKey);
        if (deserialize) {
          Map<Object, StubIdList> value = stubIndex.deserializeIndexValue(in, stubIndexKey, requestedKey);
          if (requestedIndex != null) {
            return Collections.singletonMap(requestedIndex, value);
          }
          stubIndicesValueMap.put(stubIndexKey, value);
        }
        else {
          stubIndex.skipIndexValue(in);
        }
      }
    }
    return stubIndicesValueMap;
  }
  return Collections.emptyMap();
}
 
Example 11
Source File: IntEnumerator.java    From consulo with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 12
Source File: FileLocalStringEnumerator.java    From consulo with Apache License 2.0 5 votes vote down vote up
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;
  }
}
 
Example 13
Source File: StubUpdatingIndex.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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;
  }
}
 
Example 14
Source File: InputIndexDataExternalizer.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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);
  }
}
 
Example 15
Source File: HashImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 16
Source File: TranslationSourceFileInfo.java    From consulo with Apache License 2.0 5 votes vote down vote up
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);
    }
  }
}
 
Example 17
Source File: DirectoryEntry.java    From consulo with Apache License 2.0 5 votes vote down vote up
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));
  }
}
 
Example 18
Source File: CSharpFileAttribute.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
protected static CSharpFileAttribute read(DataInputStream inputStream) throws IOException
{
	int ver = DataInputOutputUtil.readINT(inputStream);
	int varsHashCode = DataInputOutputUtil.readINT(inputStream);
	return new CSharpFileAttribute((byte) ver, varsHashCode);
}
 
Example 19
Source File: ValueContainerImpl.java    From consulo with Apache License 2.0 4 votes vote down vote up
public void readFrom(@Nonnull DataInputStream stream, @Nonnull DataExternalizer<? extends Value> externalizer, @Nonnull IntIntFunction inputRemapping) throws IOException {
  FileId2ValueMapping<Value> mapping = null;

  while (stream.available() > 0) {
    final int valueCount = DataInputOutputUtil.readINT(stream);
    if (valueCount < 0) {
      // ChangeTrackingValueContainer marked inputId as invalidated, see ChangeTrackingValueContainer.saveTo
      final int inputId = inputRemapping.fun(-valueCount);

      if (mapping == null && size() > NUMBER_OF_VALUES_THRESHOLD) { // avoid O(NumberOfValues)
        mapping = new FileId2ValueMapping<>(this);
      }

      boolean doCompact;
      if (mapping != null) {
        doCompact = mapping.removeFileId(inputId);
      }
      else {
        removeAssociatedValue(inputId);
        doCompact = true;
      }

      if (doCompact) setNeedsCompacting(true);
    }
    else {
      for (int valueIdx = 0; valueIdx < valueCount; valueIdx++) {
        final Value value = externalizer.read(stream);
        int idCountOrSingleValue = DataInputOutputUtil.readINT(stream);

        if (idCountOrSingleValue > 0) {
          addValue(idCountOrSingleValue, value);
          if (mapping != null) mapping.associateFileIdToValue(inputRemapping.fun(idCountOrSingleValue), value);
        }
        else {
          idCountOrSingleValue = -idCountOrSingleValue;
          ChangeBufferingList changeBufferingList = ensureFileSetCapacityForValue(value, idCountOrSingleValue);
          int prev = 0;

          for (int i = 0; i < idCountOrSingleValue; i++) {
            final int id = DataInputOutputUtil.readINT(stream);
            int remappedInputId = inputRemapping.fun(prev + id);
            if (changeBufferingList != null) changeBufferingList.add(remappedInputId);
            else addValue(remappedInputId, value);
            if (mapping != null) mapping.associateFileIdToValue(remappedInputId, value);
            prev += id;
          }
        }
      }
    }
  }
}