Exemplo n.º 1
0
 public void readFrom(DataInputStream stream, DataExternalizer<Value> externalizer)
     throws IOException {
   while (stream.available() > 0) {
     final int valueCount = DataInputOutputUtil.readINT(stream);
     if (valueCount < 0) {
       removeAssociatedValue(
           -valueCount); // ChangeTrackingValueContainer marked inputId as invalidated, see
                         // ChangeTrackingValueContainer.saveTo
       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);
         } else {
           idCountOrSingleValue = -idCountOrSingleValue;
           ensureFileSetCapacityForValue(value, idCountOrSingleValue);
           int prev = 0;
           for (int i = 0; i < idCountOrSingleValue; i++) {
             final int id = DataInputOutputUtil.readINT(stream);
             addValue(prev + id, value);
             prev += id;
           }
         }
       }
     }
   }
 }
Exemplo n.º 2
0
    public ValueContainerImpl<T> read(final DataInput in) throws IOException {
      DataInputStream stream = (DataInputStream) in;
      final ValueContainerImpl<T> valueContainer = new ValueContainerImpl<T>();

      while (stream.available() > 0) {
        final int valueCount = DataInputOutputUtil.readSINT(in);
        if (valueCount < 0) {
          valueContainer.removeAllValues(-valueCount);
          valueContainer.setNeedsCompacting(true);
        } else {
          for (int valueIdx = 0; valueIdx < valueCount; valueIdx++) {
            final T value = myExternalizer.read(in);
            final int idCount = DataInputOutputUtil.readSINT(in);
            for (int i = 0; i < idCount; i++) {
              final int id = DataInputOutputUtil.readSINT(in);
              if (id < 0) {
                valueContainer.removeValue(-id, value);
                valueContainer.setNeedsCompacting(true);
              } else {
                valueContainer.addValue(id, value);
              }
            }
          }
        }
      }
      return valueContainer;
    }
Exemplo n.º 3
0
 ClassType(final DependencyContext context, final DataInput in) {
   try {
     className = DataInputOutputUtil.readINT(in);
     final int size = DataInputOutputUtil.readINT(in);
     if (size == 0) {
       typeArgs = EMPTY_TYPE_ARRAY;
     } else {
       typeArgs = new AbstractType[size];
       final DataExternalizer<AbstractType> externalizer = externalizer(context);
       for (int i = 0; i < size; i++) {
         typeArgs[i] = externalizer.read(in);
       }
     }
   } catch (IOException e) {
     throw new BuildDataCorruptedException(e);
   }
 }
 @Override
 public Collection<V> read(final DataInput in) throws IOException {
   final Collection<V> result = myCollectionFactory.create();
   final DataInputStream stream = (DataInputStream) in;
   while (stream.available() > 0) {
     result.add(myElementExternalizer.read(in));
   }
   return result;
 }
Exemplo n.º 5
0
    private void saveImpl(
        final DataOutput out, final ValueContainer<T> container, final boolean asRemovedData)
        throws IOException {
      DataInputOutputUtil.writeSINT(out, container.size());
      for (final Iterator<T> valueIterator = container.getValueIterator();
          valueIterator.hasNext(); ) {
        final T value = valueIterator.next();
        myExternalizer.save(out, value);

        final ValueContainer.IntIterator ids = container.getInputIdsIterator(value);
        if (ids != null) {
          DataInputOutputUtil.writeSINT(out, ids.size());
          while (ids.hasNext()) {
            final int id = ids.next();
            DataInputOutputUtil.writeSINT(out, asRemovedData ? -id : id);
          }
        } else {
          DataInputOutputUtil.writeSINT(out, 0);
        }
      }
    }
 @Override
 public void save(final DataOutput out, final Collection<V> value) throws IOException {
   for (V x : value) {
     myElementExternalizer.save(out, x);
   }
 }
Exemplo n.º 7
0
  @Override
  public void saveTo(DataOutput out, DataExternalizer<Value> externalizer) throws IOException {
    DataInputOutputUtil.writeINT(out, size());

    for (final Iterator<Value> valueIterator = getValueIterator(); valueIterator.hasNext(); ) {
      final Value value = valueIterator.next();
      externalizer.save(out, value);
      Object input = getInput(value);

      if (input instanceof Integer) {
        DataInputOutputUtil.writeINT(
            out, (Integer) input); // most common 90% case during index building
      } else {
        // serialize positive file ids with delta encoding
        ChangeBufferingList originalInput = (ChangeBufferingList) input;
        IntIterator intIterator = originalInput.intIterator();
        DataInputOutputUtil.writeINT(out, -intIterator.size());

        if (intIterator.hasAscendingOrder()) {
          IdSet checkSet = originalInput.getCheckSet();
          if (checkSet != null && checkSet.size() != intIterator.size()) { // debug code
            int a = 1;
            assert false;
          }
          int prev = 0;

          while (intIterator.hasNext()) {
            int fileId = intIterator.next();
            if (checkSet != null && !checkSet.contains(fileId)) { // debug code
              int a = 1;
              assert false;
            }
            DataInputOutputUtil.writeINT(out, fileId - prev);
            prev = fileId;
          }
        } else {
          // sorting numbers via bitset before writing deltas
          int max = 0, min = Integer.MAX_VALUE;

          while (intIterator.hasNext()) {
            int nextInt = intIterator.next();
            max = Math.max(max, nextInt);
            min = Math.min(min, nextInt);
          }

          assert min > 0;

          final int offset = (min >> INT_BITS_SHIFT) << INT_BITS_SHIFT;
          final int bitsLength = ((max - offset) >> INT_BITS_SHIFT) + 1;
          final int[] bits = ourSpareBuffer.getBuffer(bitsLength);
          for (int i = 0; i < bitsLength; ++i) bits[i] = 0;

          intIterator = originalInput.intIterator();
          while (intIterator.hasNext()) {
            final int id = intIterator.next() - offset;
            bits[id >> INT_BITS_SHIFT] |= (1 << (id));
          }

          int pos = nextSetBit(0, bits, bitsLength);
          int prev = 0;

          while (pos != -1) {
            DataInputOutputUtil.writeINT(out, pos + offset - prev);
            prev = pos + offset;
            pos = nextSetBit(pos + 1, bits, bitsLength);
          }
        }
      }
    }
  }