/** Stores an array fragment to a given print stream. * * @param array an array whose elements will be written to {@code stream}. * @param offset the index of the first element of {@code array} to be written. * @param length the number of elements of {@code array} to be written. * @param stream a print stream. */ public static void storeBytes(final byte array[], final int offset, final int length, final PrintStream stream) { it.unimi.dsi.fastutil.bytes.ByteArrays.ensureOffsetLength(array, offset, length); for(int i = 0; i < length; i++) stream.println(array[offset + i]); } /** Stores an array to a given print stream.
/** Loads elements from a given data input, storing them in a given array fragment. * * @param dataInput a data input. * @param array an array which will be filled with data from {@code dataInput}. * @param offset the index of the first element of {@code array} to be filled. * @param length the number of elements of {@code array} to be filled. * @return the number of elements actually read from {@code dataInput} (it might be less than {@code length} if {@code dataInput} ends). */ public static int loadBytes(final DataInput dataInput, final byte[] array, final int offset, final int length) throws IOException { it.unimi.dsi.fastutil.bytes.ByteArrays.ensureOffsetLength(array, offset, length); int i = 0; try { for(i = 0; i < length; i++) array[i + offset] = dataInput.readByte(); } catch(EOFException itsOk) {} return i; } /** Loads elements from a given data input, storing them in a given array.
/** * Returns a copy of a portion of an array. * * @param array * an array. * @param offset * the first element to copy. * @param length * the number of elements to copy. * @return a new array containing {@code length} elements of {@code array} * starting at {@code offset}. */ public static byte[] copy(final byte[] array, final int offset, final int length) { ensureOffsetLength(array, offset, length); final byte[] a = length == 0 ? EMPTY_ARRAY : new byte[length]; System.arraycopy(array, offset, a, 0, length); return a; } /**
/** * Copies element of this type-specific list into the given array using * optimized system calls. * * @param from * the start index (inclusive). * @param a * the destination array. * @param offset * the offset into the destination array where to store the first * element copied. * @param length * the number of elements to be copied. */ @Override public void getElements(final int from, final byte[] a, final int offset, final int length) { ByteArrays.ensureOffsetLength(a, offset, length); System.arraycopy(this.a, from, a, offset, length); } /**
public int read( final byte[] array, final int offset, final int length ) throws IOException { if ( length == 0 ) return 0; ByteArrays.ensureOffsetLength( array, offset, length ); connection.outputStream.writeByte( RemoteInputStream.READ_ARRAY ); connection.outputStream.writeInt( length ); connection.outputStream.flush(); final int result = connection.inputStream.readInt(); if ( result <= 0 ) return result; connection.inputStream.read( array, offset, result ); return result; }
public int read( final byte[] array, final int offset, final int length ) throws IOException { if ( length == 0 ) return 0; ByteArrays.ensureOffsetLength( array, offset, length ); connection.outputStream.writeByte( RemoteInputStream.READ_ARRAY ); connection.outputStream.writeInt( length ); connection.outputStream.flush(); final int result = connection.inputStream.readInt(); if ( result <= 0 ) return result; connection.inputStream.read( array, offset, result ); return result; }
public int read( final byte[] array, final int offset, final int length ) throws IOException { if ( length == 0 ) return 0; ByteArrays.ensureOffsetLength( array, offset, length ); connection.outputStream.writeByte( RemoteInputStream.READ_ARRAY ); connection.outputStream.writeInt( length ); connection.outputStream.flush(); final int result = connection.inputStream.readInt(); if ( result <= 0 ) return result; connection.inputStream.read( array, offset, result ); return result; }
/** Stores an array fragment to a given data output. * * @param array an array whose elements will be written to {@code dataOutput}. * @param offset the index of the first element of {@code array} to be written. * @param length the number of elements of {@code array} to be written. * @param dataOutput a data output. */ public static void storeBytes(final byte array[], final int offset, final int length, final DataOutput dataOutput) throws IOException { it.unimi.dsi.fastutil.bytes.ByteArrays.ensureOffsetLength(array, offset, length); write(dataOutput, array, offset, length); } /** Stores an array to a given data output.
@Override public void write(final byte[] b, final int off, final int len) throws IOException { ByteArrays.ensureOffsetLength(b, off, len); if (position + len > array.length) array = ByteArrays.grow(array, position + len, position); System.arraycopy(b, off, array, position, len); if (position + len > length) length = position += len; }
/** Loads elements from a given fast buffered reader, storing them in a given array fragment. * * @param reader a buffered reader. * @param array an array which will be filled with data from {@code reader}. * @param offset the index of the first element of {@code array} to be filled. * @param length the number of elements of {@code array} to be filled. * @return the number of elements actually read from {@code reader} (it might be less than {@code length} if {@code reader} ends). */ public static int loadBytes(final BufferedReader reader, final byte[] array, final int offset, final int length) throws IOException { it.unimi.dsi.fastutil.bytes.ByteArrays.ensureOffsetLength(array, offset, length); int i = 0; String s; try { for(i = 0; i < length; i++) if ((s = reader.readLine()) != null) array[i + offset] = Byte.parseByte(s.trim()); else break; } catch(EOFException itsOk) {} return i; } /** Loads elements from a given buffered reader, storing them in a given array.
/** Loads elements from a file given by a {@link File} object, storing them in a given array fragment. * * @param file a file. * @param array an array which will be filled with data from the specified file. * @param offset the index of the first element of {@code array} to be filled. * @param length the number of elements of {@code array} to be filled. * @return the number of elements actually read from the given file (it might be less than {@code length} if the file is too short). */ public static int loadBytes(final File file, final byte[] array, final int offset, final int length) throws IOException { it.unimi.dsi.fastutil.bytes.ByteArrays.ensureOffsetLength(array, offset, length); final FileInputStream fis = new FileInputStream(file); final int result = read(fis, array, offset, length); fis.close(); return result; } /** Loads elements from a file given by a pathname, storing them in a given array fragment.
/** * Creates a new hash set and fills it with the elements of a given array. * * @param a * an array whose elements will be used to fill the set. * @param offset * the first element to use. * @param length * the number of elements to use. * @param f * the load factor. */ public ByteLinkedOpenHashSet(final byte[] a, final int offset, final int length, final float f) { this(length < 0 ? 0 : length, f); ByteArrays.ensureOffsetLength(a, offset, length); for (int i = 0; i < length; i++) add(a[offset + i]); } /**
/** * Creates a new hash set and fills it with the elements of a given array. * * @param a * an array whose elements will be used to fill the set. * @param offset * the first element to use. * @param length * the number of elements to use. * @param f * the load factor. */ public ByteOpenHashSet(final byte[] a, final int offset, final int length, final float f) { this(length < 0 ? 0 : length, f); ByteArrays.ensureOffsetLength(a, offset, length); for (int i = 0; i < length; i++) add(a[offset + i]); } /**
/** * Creates a new tree set and fills it with the elements of a given array using * a given {@link Comparator}. * * @param a * an array whose elements will be used to fill the set. * @param offset * the first element to use. * @param length * the number of elements to use. * @param c * a {@link Comparator} (even better, a type-specific comparator). */ public ByteRBTreeSet(final byte[] a, final int offset, final int length, final Comparator<? super Byte> c) { this(c); ByteArrays.ensureOffsetLength(a, offset, length); for (int i = 0; i < length; i++) add(a[offset + i]); } /**
/** * Creates a new tree set and fills it with the elements of a given array using * a given {@link Comparator}. * * @param a * an array whose elements will be used to fill the set. * @param offset * the first element to use. * @param length * the number of elements to use. * @param c * a {@link Comparator} (even better, a type-specific comparator). */ public ByteAVLTreeSet(final byte[] a, final int offset, final int length, final Comparator<? super Byte> c) { this(c); ByteArrays.ensureOffsetLength(a, offset, length); for (int i = 0; i < length; i++) add(a[offset + i]); } /**
/** Stores an array fragment to a file given by a {@link File} object. * * @param array an array whose elements will be written to {@code filename}. * @param offset the index of the first element of {@code array} to be written. * @param length the number of elements of {@code array} to be written. * @param file a file. */ public static void storeBytes(final byte array[], final int offset, final int length, final File file) throws IOException { it.unimi.dsi.fastutil.bytes.ByteArrays.ensureOffsetLength(array, offset, length); final OutputStream os = new FastBufferedOutputStream(new FileOutputStream(file)); write(os, array, offset, length); os.close(); } /** Stores an array fragment to a file given by a pathname.
@Override public int read(final byte b[], final int off, final int len) throws IOException { ensureNotClosed(); ByteArrays.ensureOffsetLength(b, off, len); if (len == 0) return 0; // Requested by InputStream. if (eofInBlock()) return -1; int effectivelen = Math.min(segmentLen - relativePos, len); effectivelen = in.read(b, off, effectivelen); relativePos += effectivelen; return effectivelen; }
public int read( final byte b[], final int off, final int len ) throws IOException { ensureNotClosed(); ByteArrays.ensureOffsetLength( b, off, len ); if ( len == 0 ) return 0; // Requested by InputStream. if ( eofInBlock() ) return -1; int effectivelen = Math.min( segmentLen - relativePos, len ); effectivelen = in.read( b, off, effectivelen ); relativePos += effectivelen; return effectivelen; }
public int read( final byte b[], final int off, final int len ) throws IOException { ensureNotClosed(); ByteArrays.ensureOffsetLength( b, off, len ); if ( len == 0 ) return 0; // Requested by InputStream. if ( eofInBlock() ) return -1; int effectivelen = Math.min( segmentLen - relativePos, len ); effectivelen = in.read( b, off, effectivelen ); relativePos += effectivelen; return effectivelen; }
/** * Adds elements to this type-specific list using optimized system calls. * * @param index * the index at which to add elements. * @param a * the array containing the elements. * @param offset * the offset of the first element to add. * @param length * the number of elements to add. */ @Override public void addElements(final int index, final byte a[], final int offset, final int length) { ensureIndex(index); ByteArrays.ensureOffsetLength(a, offset, length); grow(size + length); System.arraycopy(this.a, index, this.a, index + length, size - index); System.arraycopy(a, offset, this.a, index, length); size += length; } @Override