com.intellij.util.io.DataExternalizer Java Examples

The following examples show how to use com.intellij.util.io.DataExternalizer. 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: ChangeTrackingValueContainer.java    From consulo with Apache License 2.0 6 votes vote down vote up
@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);
    }
  }
}
 
Example #2
Source File: VcsLogFullDetailsIndex.java    From consulo with Apache License 2.0 6 votes vote down vote up
public VcsLogFullDetailsIndex(@Nonnull String logId,
                              @Nonnull String name,
                              final int version,
                              @Nonnull DataIndexer<Integer, T, VcsFullCommitDetails> indexer,
                              @Nonnull DataExternalizer<T> externalizer,
                              @Nonnull FatalErrorHandler fatalErrorHandler,
                              @Nonnull Disposable disposableParent) throws IOException {
  myID = ID.create(name);
  myName = name;
  myLogId = logId;
  myIndexer = indexer;
  myFatalErrorHandler = fatalErrorHandler;

  myMapReduceIndex = createMapReduceIndex(externalizer, version);

  Disposer.register(disposableParent, this);
}
 
Example #3
Source File: MapReduceIndex.java    From consulo with Apache License 2.0 6 votes vote down vote up
public static <Key, Value> void checkValuesHaveProperEqualsAndHashCode(@Nonnull Map<Key, Value> data, @Nonnull IndexId<Key, Value> indexId, @Nonnull DataExternalizer<Value> valueExternalizer) {
  if (DebugAssertions.DEBUG) {
    for (Map.Entry<Key, Value> e : data.entrySet()) {
      final Value value = e.getValue();
      if (!(Comparing.equal(value, value) && (value == null || value.hashCode() == value.hashCode()))) {
        LOG.error("Index " + indexId + " violates equals / hashCode contract for Value parameter");
      }

      try {
        final BufferExposingByteArrayOutputStream out = new BufferExposingByteArrayOutputStream();
        DataOutputStream outputStream = new DataOutputStream(out);
        valueExternalizer.save(outputStream, value);
        outputStream.close();
        final Value deserializedValue = valueExternalizer.read(new DataInputStream(out.toInputStream()));

        if (!(Comparing.equal(value, deserializedValue) && (value == null || value.hashCode() == deserializedValue.hashCode()))) {
          LOG.error("Index " + indexId + " deserialization violates equals / hashCode contract for Value parameter");
        }
      }
      catch (IOException ex) {
        LOG.error(ex);
      }
    }
  }
}
 
Example #4
Source File: TestStateStorage.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static ThrowableComputable<PersistentHashMap<String, Record>, IOException> getComputable(final File file) {
  return () -> new PersistentHashMap<>(file, EnumeratorStringDescriptor.INSTANCE, new DataExternalizer<Record>() {
    @Override
    public void save(@Nonnull DataOutput out, Record value) throws IOException {
      out.writeInt(value.magnitude);
      out.writeLong(value.date.getTime());
      out.writeLong(value.configurationHash);
    }

    @Override
    public Record read(@Nonnull DataInput in) throws IOException {
      return new Record(in.readInt(), new Date(in.readLong()), in.readLong());
    }
  }, 4096, CURRENT_VERSION);
}
 
Example #5
Source File: VcsLogFullDetailsIndex.java    From consulo with Apache License 2.0 5 votes vote down vote up
protected MyMapIndexStorage(@Nonnull File storageFile,
                            @Nonnull KeyDescriptor<Integer> keyDescriptor,
                            @Nonnull DataExternalizer<T> valueExternalizer,
                            int cacheSize,
                            boolean keyIsUniqueForIndexedFile) throws IOException {
  super(storageFile, keyDescriptor, valueExternalizer, cacheSize, keyIsUniqueForIndexedFile);
}
 
Example #6
Source File: ValueContainerMap.java    From consulo with Apache License 2.0 5 votes vote down vote up
ValueContainerMap(@Nonnull final File file,
                  @Nonnull KeyDescriptor<Key> keyKeyDescriptor,
                  @Nonnull DataExternalizer<Value> valueExternalizer,
                  boolean keyIsUniqueForIndexedFile,
                  @Nonnull IntIntFunction inputRemapping) throws IOException {
  super(file, keyKeyDescriptor, new ValueContainerExternalizer<>(valueExternalizer, inputRemapping));
  myValueExternalizer = valueExternalizer;
  myKeyIsUniqueForIndexedFile = keyIsUniqueForIndexedFile;
}
 
Example #7
Source File: SmallMapSerializer.java    From consulo with Apache License 2.0 5 votes vote down vote up
public SmallMapSerializer(final File file, final KeyDescriptor<K> keyDescriptor, final DataExternalizer<V> valueExternalizer) {
  myFile = file;
  myKeyDescriptor = keyDescriptor;
  myValueExternalizer = valueExternalizer;
  myMap = new HashMap<KeyWrapper<K>, V>();
  init();
}
 
Example #8
Source File: StubProvidedIndexExtension.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public DataExternalizer<SerializedStubTree> createValueExternalizer() {
  File path = getIndexPath();
  SerializationManagerImpl manager = new SerializationManagerImpl(new File(new File(path, StringUtil.toLowerCase(StubUpdatingIndex.INDEX_ID.getName())), "rep.names"), true);
  Disposer.register(ApplicationManager.getApplication(), manager);
  return new SerializedStubTreeDataExternalizer(false, manager);
}
 
Example #9
Source File: ValueContainerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@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;
        }
      }
    }
  }
}
 
Example #10
Source File: ServicesDefinitionStubIndex.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@NotNull
public DataExternalizer<ServiceSerializable> getValueExternalizer() {
    return EXTERNALIZER;
}
 
Example #11
Source File: IdIndex.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public DataExternalizer<Integer> getValueExternalizer() {
  return myValueExternalizer;
}
 
Example #12
Source File: AbstractForwardIndexAccessor.java    From consulo with Apache License 2.0 4 votes vote down vote up
public AbstractForwardIndexAccessor(@Nonnull DataExternalizer<DataType> externalizer) {
  myDataTypeExternalizer = externalizer;
}
 
Example #13
Source File: ContainerBuilderStubIndex.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@NotNull
public DataExternalizer<ContainerBuilderCall> getValueExternalizer() {
    return EXTERNALIZER;
}
 
Example #14
Source File: ArtifactsCompiler.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public DataExternalizer<VirtualFilePersistentState> getSourceStateExternalizer() {
  return VirtualFilePersistentState.EXTERNALIZER;
}
 
Example #15
Source File: AnnotationStubIndex.java    From idea-php-annotation-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
public DataExternalizer<Void> getValueExternalizer() {
    return VoidDataExternalizer.INSTANCE;
}
 
Example #16
Source File: PhpInjectFileReferenceIndex.java    From idea-php-advanced-autocomplete with MIT License 4 votes vote down vote up
@NotNull
public DataExternalizer<PhpInjectFileReference> getValueExternalizer() {
    return VALUE_EXTERNALIZER;
}
 
Example #17
Source File: ThriftSubDeclarationIndex.java    From intellij-thrift with Apache License 2.0 4 votes vote down vote up
@NotNull
@Override
public DataExternalizer<String> getValueExternalizer() {
  return myKeyDescriptor;
}
 
Example #18
Source File: TodoIndex.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public DataExternalizer<Integer> getValueExternalizer() {
  return myValueExternalizer;
}
 
Example #19
Source File: DoctrineMetadataFileStubIndex.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
public DataExternalizer<DoctrineModelSerializable> getValueExternalizer() {
    return EXTERNALIZER;
}
 
Example #20
Source File: RoutesStubIndex.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
public DataExternalizer<StubIndexedRoute> getValueExternalizer() {
    return EXTERNALIZER;
}
 
Example #21
Source File: ContainerIdUsagesStubIndex.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
public DataExternalizer<Integer> getValueExternalizer() {
    return EnumeratorIntegerDescriptor.INSTANCE;
}
 
Example #22
Source File: TwigBlockIndexExtension.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
public DataExternalizer<Set<String>> getValueExternalizer() {
    return DATA_EXTERNALIZER;
}
 
Example #23
Source File: TwigControllerStubIndex.java    From idea-php-symfony2-plugin with MIT License 4 votes vote down vote up
@NotNull
@Override
public DataExternalizer<Void> getValueExternalizer() {
    return VoidDataExternalizer.INSTANCE;
}
 
Example #24
Source File: HaxeTypeDefInheritanceIndex.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
@Override
public DataExternalizer<List<HaxeClassInfo>> getValueExternalizer() {
  return myExternalizer;
}
 
Example #25
Source File: HaxeInheritanceIndex.java    From intellij-haxe with Apache License 2.0 4 votes vote down vote up
@Override
public DataExternalizer<List<HaxeClassInfo>> getValueExternalizer() {
  return myExternalizer;
}
 
Example #26
Source File: AbstractForwardIndexAccessor.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static <Data> ByteArraySequence serializeToByteSeq(@Nonnull Data data, @Nonnull DataExternalizer<Data> externalizer, int bufferInitialSize) throws IOException {
  BufferExposingByteArrayOutputStream out = new BufferExposingByteArrayOutputStream(ourSpareByteArray.getBuffer(bufferInitialSize));
  DataOutputStream stream = new DataOutputStream(out);
  externalizer.save(stream, data);
  return out.toByteArraySequence();
}
 
Example #27
Source File: IgnoreFilesIndex.java    From idea-gitignore with MIT License 4 votes vote down vote up
/**
 * Returns {@link DataExternalizer} instance.
 *
 * @return {@link #DATA_EXTERNALIZER}
 */
@NotNull
@Override
public DataExternalizer<IgnoreEntryOccurrence> getValueExternalizer() {
    return DATA_EXTERNALIZER;
}
 
Example #28
Source File: ConfigSchemaIndex.java    From idea-php-drupal-symfony2-bridge with MIT License 4 votes vote down vote up
@NotNull
@Override
public DataExternalizer<Set<String>> getValueExternalizer() {
    return EXTERNALIZER;
}
 
Example #29
Source File: PermissionIndex.java    From idea-php-drupal-symfony2-bridge with MIT License 4 votes vote down vote up
@NotNull
public DataExternalizer<Void> getValueExternalizer() {
    return VoidDataExternalizer.INSTANCE;
}
 
Example #30
Source File: AbstractMapForwardIndexAccessor.java    From consulo with Apache License 2.0 4 votes vote down vote up
public AbstractMapForwardIndexAccessor(@Nonnull DataExternalizer<DataType> externalizer) {
  super(externalizer);
}