/** * Unwraps an iterator, returning an array. * * <p> * This method iterates over the given type-specific iterator and returns an * array containing the elements returned by the iterator. * * @param i * a type-specific iterator. * @return an array containing the elements returned by the iterator. */ public static byte[] unwrap(final ByteIterator i) { return unwrap(i, Integer.MAX_VALUE); } /**
/** * Unwraps an iterator into an array. * * <p> * This method iterates over the given type-specific iterator and stores the * elements returned in the given array. The iteration will stop when the * iterator has no more elements or when the end of the array has been reached. * * @param i * a type-specific iterator. * @param array * an array to contain the output of the iterator. * @return the number of elements unwrapped. */ public static int unwrap(final ByteIterator i, final byte array[]) { return unwrap(i, array, 0, array.length); } /**
/** * Creates a new array list and fills it with a given collection. * * @param c * a collection that will be used to fill the array list. */ public ByteArrayList(final Collection<? extends Byte> c) { this(c.size()); size = ByteIterators.unwrap(ByteIterators.asByteIterator(c.iterator()), a); } /**
/** * Generates a byte array by reading the provided stream up to exhaustion, and passes the result * to {@link #fromByteArray(byte[])}. */ @Override public J fromInputStream( InputStream inputStream ) throws IllegalArgumentException, IOException { return fromByteArray( ByteIterators.unwrap( BinIO.asByteIterator( new DataInputStream( inputStream ) ) ) ); }
/** * Creates a new array list and fills it with a given type-specific collection. * * @param c * a type-specific collection that will be used to fill the array * list. */ public ByteArrayList(final ByteCollection c) { this(c.size()); size = ByteIterators.unwrap(c.iterator(), a); } /**
@Override public byte[] toArray(byte a[]) { if (a == null || a.length < size()) a = new byte[size()]; ByteIterators.unwrap(iterator(), a); return a; } @Override