本文整理汇总了Java中it.unimi.dsi.fastutil.bytes.ByteArrays.grow方法的典型用法代码示例。如果您正苦于以下问题:Java ByteArrays.grow方法的具体用法?Java ByteArrays.grow怎么用?Java ByteArrays.grow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类it.unimi.dsi.fastutil.bytes.ByteArrays
的用法示例。
在下文中一共展示了ByteArrays.grow方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: append
import it.unimi.dsi.fastutil.bytes.ByteArrays; //导入方法依赖的package包/类
public void append(byte b) {
if (size >= bytes.length - 1) {
bytes = ByteArrays.grow(bytes, bytes.length + 1024);
}
switch (b) {
case -1:
bytes[size++] = -1;
bytes[size++] = MINUS_CODE;
break;
case (byte) '\n':
bytes[size++] = -1;
bytes[size++] = NL_CODE;
break;
case (byte) '\r':
bytes[size++] = -1;
bytes[size++] = RETURN_CODE;
break;
default:
bytes[size++] = b;
}
}
示例2: dequeue
import it.unimi.dsi.fastutil.bytes.ByteArrays; //导入方法依赖的package包/类
/** Dequeues an object from the queue in FIFO fashion. */
@SuppressWarnings("unchecked")
public synchronized T dequeue() throws IOException {
final int length = byteDiskQueue.dequeueInt();
fbaos.array = ByteArrays.grow(fbaos.array, length);
byteDiskQueue.dequeue(fbaos.array, 0, length);
size--;
try {
return (T)BinIO.loadObject(new FastByteArrayInputStream(fbaos.array, 0, length));
}
catch (final ClassNotFoundException e) {
throw new RuntimeException(e.getMessage(), e);
}
}
示例3: readLineFrom
import it.unimi.dsi.fastutil.bytes.ByteArrays; //导入方法依赖的package包/类
public boolean readLineFrom(FastBufferedInputStream stream) throws IOException {
int start = 0, len;
while ((len = stream.readLine(bytes, start, bytes.length - start)) == bytes.length - start) {
start += len;
bytes = ByteArrays.grow(bytes, bytes.length + 1024);
}
size = start + Math.max(len, 0);
return !(size == 0 && len < 0);
}
示例4: write
import it.unimi.dsi.fastutil.bytes.ByteArrays; //导入方法依赖的package包/类
public void write( final int b ) {
if ( position >= array.length ) array = ByteArrays.grow( array, position + 1, length );
array[ position++ ] = (byte)b;
if ( length < position ) length = position;
}
示例5: FileLinesList
import it.unimi.dsi.fastutil.bytes.ByteArrays; //导入方法依赖的package包/类
/** Creates a file-lines collection for the specified filename with the specified encoding, buffer size and terminator set.
*
* @param filename a filename.
* @param encoding an encoding.
* @param bufferSize the buffer size for {@link FastBufferedInputStream}.
* @param terminators a set of line terminators.
*/
public FileLinesList(final CharSequence filename, final String encoding, final int bufferSize, final EnumSet<FastBufferedInputStream.LineTerminator> terminators) throws IOException {
this.bufferSize = bufferSize;
this.terminators = terminators;
this.filename = filename.toString();
inputStream = new FastBufferedInputStream(new FileInputStream(this.filename), bufferSize);
decoder = (charset = Charset.forName(encoding)).newDecoder();
byte[] array = new byte[16];
int count = 0, start, len;
for(;;) {
start = 0;
while((len = inputStream.readLine(array, start, array.length - start, terminators)) == array.length - start) {
start += len;
array = ByteArrays.grow(array, array.length + 1);
};
if (len != -1) count++;
else break;
}
size = count;
byteBuffer = ByteBuffer.wrap(array);
charBuffer = CharBuffer.wrap(new char[array.length]);
inputStream.position(0);
borders = new EliasFanoMonotoneLongBigList(count, inputStream.length(), new LongIterator() {
long pos = 0;
byte[] buffer = byteBuffer.array();
@Override
public boolean hasNext() {
return pos < size;
}
@Override
public long nextLong() {
if (! hasNext()) throw new NoSuchElementException();
pos++;
try {
final long result = inputStream.position();
inputStream.readLine(buffer, terminators);
return result;
}
catch (final IOException e) {
throw new RuntimeException(e);
}
}
});
}
示例6: FileLinesBigList
import it.unimi.dsi.fastutil.bytes.ByteArrays; //导入方法依赖的package包/类
/** Creates a file-lines collection for the specified filename with the specified encoding, buffer size and terminator set.
*
* @param filename a filename.
* @param encoding an encoding.
* @param bufferSize the buffer size for {@link FastBufferedInputStream}.
* @param terminators a set of line terminators.
*/
public FileLinesBigList(final CharSequence filename, final String encoding, final int bufferSize, final EnumSet<FastBufferedInputStream.LineTerminator> terminators) throws IOException {
this.bufferSize = bufferSize;
this.terminators = terminators;
this.filename = filename.toString();
inputStream = new FastBufferedInputStream(new FileInputStream(this.filename), bufferSize);
decoder = (charset = Charset.forName(encoding)).newDecoder();
byte[] array = new byte[16];
long count = 0;
int start, len;
for(;;) {
start = 0;
while((len = inputStream.readLine(array, start, array.length - start, terminators)) == array.length - start) {
start += len;
array = ByteArrays.grow(array, array.length + 1);
};
if (len != -1) count++;
else break;
}
size = count;
byteBuffer = ByteBuffer.wrap(array);
charBuffer = CharBuffer.wrap(new char[array.length]);
inputStream.position(0);
borders = new EliasFanoMonotoneLongBigList(count, inputStream.length(), new LongIterator() {
long pos = 0;
byte[] buffer = byteBuffer.array();
@Override
public boolean hasNext() {
return pos < size;
}
@Override
public long nextLong() {
if (! hasNext()) throw new NoSuchElementException();
pos++;
try {
final long result = inputStream.position();
inputStream.readLine(buffer, terminators);
return result;
}
catch (final IOException e) {
throw new RuntimeException(e);
}
}
});
}