public class CharsetEncoderByteIterator extends Object implements ByteIterator
Constructor and Description |
---|
CharsetEncoderByteIterator(String string,
Charset charset)
Constructs a new encoder instance that iterates over
string , converting
it to bytes using the charset charset . |
CharsetEncoderByteIterator(String string,
Charset charset,
int stepSize)
Constructs a new encoder instance that iterates over
string , converting
it to bytes using the charset charset . |
Modifier and Type | Method and Description |
---|---|
boolean |
hasNext()
Returns
true iff the byte stream contains more bytes. |
Byte |
next()
Returns the next byte from the byte stream and increments the byte position.
|
byte |
nextByte()
Returns the next byte from the sequence and increments the byte position.
|
void |
remove()
Always throws an
UnsupportedOperationException , since this is a read-only iterator. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
forEachRemaining
public CharsetEncoderByteIterator(String string, Charset charset, int stepSize)
string
, converting
it to bytes using the charset charset
.
The encoder reads up to stepSize
characters at the same time,
buffering the results internally. stepSize
must be at least 2 (this is to
ensure that surrogate pairs are processed correctly).
string
- the string to iterate over, must not be null
charset
- the charset to use for encoding characters to bytes, must not be null
stepSize
- the number to characters to try encoding in each encoding step,
must be positiveNullPointerException
- if string
or charset
is null
IllegalArgumentException
- if stepSize
is lesser than 2public CharsetEncoderByteIterator(String string, Charset charset)
string
, converting
it to bytes using the charset charset
.
To customise the number of characters encoded in every encoding step, use
CharsetEncoderByteIterator(String, Charset, int)
. This method uses
a reasonable default value for step size.
string
- the string to iterate over, must not be null
charset
- the charset to use for encoding characters to bytes, must not be null
NullPointerException
- if string
or charset
is null
public boolean hasNext()
true
iff the byte stream contains more bytes. In other words,
returns false
iff nextByte()
would throw a NoSuchElementException
.public byte nextByte()
ByteIterator
When there is no next byte to be read from the stream, this method throws
a NoSuchElementException
. Use Iterator.hasNext()
to detect this condition.
nextByte
in interface ByteIterator
public Byte next()
In order to avoid boxing and unboxing the result, call nextByte()
directly.
This method is provided in order to implement the Iterator
interface.
next
in interface Iterator<Byte>
NoSuchElementException
- if there are no more bytes in the streampublic void remove()
UnsupportedOperationException
, since this is a read-only iterator.Copyright © 2016. All rights reserved.