public static CompressedLongsIndexedSupplier fromByteBuffer(ByteBuffer buffer, ByteOrder order) {
    byte versionFromBuffer = buffer.get();

    if (versionFromBuffer == version) {
      final int totalSize = buffer.getInt();
      final int sizePer = buffer.getInt();
      final CompressedObjectStrategy.CompressionStrategy compression =
          CompressedObjectStrategy.CompressionStrategy.forId(buffer.get());
      return new CompressedLongsIndexedSupplier(
          totalSize,
          sizePer,
          GenericIndexed.read(
              buffer,
              CompressedLongBufferObjectStrategy.getBufferForOrder(order, compression, sizePer)),
          compression);
    } else if (versionFromBuffer == LZF_VERSION) {
      final int totalSize = buffer.getInt();
      final int sizePer = buffer.getInt();
      final CompressedObjectStrategy.CompressionStrategy compression =
          CompressedObjectStrategy.CompressionStrategy.LZF;
      return new CompressedLongsIndexedSupplier(
          totalSize,
          sizePer,
          GenericIndexed.read(
              buffer,
              CompressedLongBufferObjectStrategy.getBufferForOrder(order, compression, sizePer)),
          compression);
    }

    throw new IAE("Unknown version[%s]", versionFromBuffer);
  }
 public CompressedLongsIndexedSupplier convertByteOrder(ByteOrder order) {
   return new CompressedLongsIndexedSupplier(
       totalSize,
       sizePer,
       GenericIndexed.fromIterable(
           baseLongBuffers,
           CompressedLongBufferObjectStrategy.getBufferForOrder(order, compression, sizePer)),
       compression);
 }
  public static CompressedLongsIndexedSupplier fromList(
      final List<Long> list,
      final int chunkFactor,
      final ByteOrder byteOrder,
      CompressedObjectStrategy.CompressionStrategy compression) {
    Preconditions.checkArgument(
        chunkFactor <= MAX_LONGS_IN_BUFFER,
        "Chunks must be <= 64k bytes. chunkFactor was[%s]",
        chunkFactor);

    return new CompressedLongsIndexedSupplier(
        list.size(),
        chunkFactor,
        GenericIndexed.fromIterable(
            new Iterable<ResourceHolder<LongBuffer>>() {
              @Override
              public Iterator<ResourceHolder<LongBuffer>> iterator() {
                return new Iterator<ResourceHolder<LongBuffer>>() {
                  int position = 0;

                  @Override
                  public boolean hasNext() {
                    return position < list.size();
                  }

                  @Override
                  public ResourceHolder<LongBuffer> next() {
                    LongBuffer retVal = LongBuffer.allocate(chunkFactor);

                    if (chunkFactor > list.size() - position) {
                      retVal.limit(list.size() - position);
                    }
                    final List<Long> longs = list.subList(position, position + retVal.remaining());
                    for (long value : longs) {
                      retVal.put(value);
                    }
                    retVal.rewind();
                    position += retVal.remaining();

                    return StupidResourceHolder.create(retVal);
                  }

                  @Override
                  public void remove() {
                    throw new UnsupportedOperationException();
                  }
                };
              }
            },
            CompressedLongBufferObjectStrategy.getBufferForOrder(
                byteOrder, compression, chunkFactor)),
        compression);
  }
  public static CompressedLongsIndexedSupplier fromLongBuffer(
      final LongBuffer buffer,
      final int chunkFactor,
      final ByteOrder byteOrder,
      CompressedObjectStrategy.CompressionStrategy compression) {
    Preconditions.checkArgument(
        chunkFactor <= MAX_LONGS_IN_BUFFER,
        "Chunks must be <= 64k bytes. chunkFactor was[%s]",
        chunkFactor);

    return new CompressedLongsIndexedSupplier(
        buffer.remaining(),
        chunkFactor,
        GenericIndexed.fromIterable(
            new Iterable<ResourceHolder<LongBuffer>>() {
              @Override
              public Iterator<ResourceHolder<LongBuffer>> iterator() {
                return new Iterator<ResourceHolder<LongBuffer>>() {
                  LongBuffer myBuffer = buffer.asReadOnlyBuffer();

                  @Override
                  public boolean hasNext() {
                    return myBuffer.hasRemaining();
                  }

                  @Override
                  public ResourceHolder<LongBuffer> next() {
                    LongBuffer retVal = myBuffer.asReadOnlyBuffer();

                    if (chunkFactor < myBuffer.remaining()) {
                      retVal.limit(retVal.position() + chunkFactor);
                    }
                    myBuffer.position(myBuffer.position() + retVal.remaining());

                    return StupidResourceHolder.create(retVal);
                  }

                  @Override
                  public void remove() {
                    throw new UnsupportedOperationException();
                  }
                };
              }
            },
            CompressedLongBufferObjectStrategy.getBufferForOrder(
                byteOrder, compression, chunkFactor)),
        compression);
  }