本文整理汇总了Java中java.nio.ByteBuffer.remaining方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.remaining方法的具体用法?Java ByteBuffer.remaining怎么用?Java ByteBuffer.remaining使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.ByteBuffer
的用法示例。
在下文中一共展示了ByteBuffer.remaining方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void process(ByteBuffer inBuffer, ByteBuffer outBuffer)
throws IOException {
try {
int inputSize = inBuffer.remaining();
// Cipher#update will maintain crypto context.
int n = cipher.update(inBuffer, outBuffer);
if (n < inputSize) {
/**
* Typically code will not get here. Cipher#update will consume all
* input data and put result in outBuffer.
* Cipher#doFinal will reset the crypto context.
*/
contextReset = true;
cipher.doFinal(inBuffer, outBuffer);
}
} catch (Exception e) {
throw new IOException(e);
}
}
示例2: dequeueOutputBuffer
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Save the encoded (output) buffer into the complete encoded recording.
* TODO: copy directly (without the intermediate byte array)
*/
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void dequeueOutputBuffer(MediaCodec codec, ByteBuffer[] outputBuffers, int index, MediaCodec.BufferInfo info) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
ByteBuffer buffer = outputBuffers[index];
Log.i("size/remaining: " + info.size + "/" + buffer.remaining());
if (info.size <= buffer.remaining()) {
final byte[] bufferCopied = new byte[info.size];
buffer.get(bufferCopied); // TODO: catch BufferUnderflow
// TODO: do we need to clear?
// on N5: always size == remaining(), clearing is not needed
// on SGS2: remaining decreases until it becomes less than size, which results in BufferUnderflow
// (but SGS2 records only zeros anyway)
//buffer.clear();
codec.releaseOutputBuffer(index, false);
addEncoded(bufferCopied);
if (Log.DEBUG) {
AudioUtils.showSomeBytes("out", bufferCopied);
}
} else {
Log.e("size > remaining");
codec.releaseOutputBuffer(index, false);
}
}
}
开发者ID:vaibhavs4424,项目名称:AI-Powered-Intelligent-Banking-Platform,代码行数:29,代码来源:EncodedAudioRecorder.java
示例3: parse
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Sweep through the master buffer and remember all the entries
*/
private void parse(ByteBuffer master, long after) throws Exception {
if (master.remaining() < 16) throw new IllegalStateException("Cache invalid");
if (master.getLong() != magic) throw new IllegalStateException("Wrong format");
if (master.getLong() < after) throw new IllegalStateException("Cache outdated");
int srcCounter = 0;
while (master.remaining() > 0) {
int type = master.get();
switch (type) {
case 1: // source header
String name = parseString(master);
sources.put(name, srcCounter++);
break;
case 2:
Entry en = new Entry(master); // shifts the buffer
entries.put(en, en);
break;
default:
throw new IllegalStateException("Cache invalid");
}
}
master.rewind();
}
示例4: inflateDirect
import java.nio.ByteBuffer; //导入方法依赖的package包/类
int inflateDirect(ByteBuffer src, ByteBuffer dst) throws IOException {
assert (this instanceof ZlibDirectDecompressor);
ByteBuffer presliced = dst;
if (dst.position() > 0) {
presliced = dst;
dst = dst.slice();
}
Buffer originalCompressed = compressedDirectBuf;
Buffer originalUncompressed = uncompressedDirectBuf;
int originalBufferSize = directBufferSize;
compressedDirectBuf = src;
compressedDirectBufOff = src.position();
compressedDirectBufLen = src.remaining();
uncompressedDirectBuf = dst;
directBufferSize = dst.remaining();
int n = 0;
try {
n = inflateBytesDirect();
presliced.position(presliced.position() + n);
if (compressedDirectBufLen > 0) {
src.position(compressedDirectBufOff);
} else {
src.position(src.limit());
}
} finally {
compressedDirectBuf = originalCompressed;
uncompressedDirectBuf = originalUncompressed;
compressedDirectBufOff = 0;
compressedDirectBufLen = 0;
directBufferSize = originalBufferSize;
}
return n;
}
示例5: parseChildBoxes
import java.nio.ByteBuffer; //导入方法依赖的package包/类
protected final void parseChildBoxes(ByteBuffer content) {
try {
while (content.remaining() >= 8) { // 8 is the minimal size for a sane box
boxes.add(boxParser.parseBox(new ByteBufferByteChannel(content), this));
}
if (content.remaining() != 0) {
setDeadBytes(content.slice());
LOG.severe("Some sizes are wrong");
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例6: testEncode
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static final void testEncode(Base64.Encoder enc, ByteBuffer bin, byte[] expected)
throws Throwable {
ByteBuffer bout = enc.encode(bin);
byte[] buf = new byte[bout.remaining()];
bout.get(buf);
if (bin.hasRemaining()) {
throw new RuntimeException(
"Base64 enc.encode(ByteBuffer) failed!");
}
checkEqual(buf, expected, "Base64 enc.encode(bf, bf) failed!");
}
示例7: toUtf8String
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static String toUtf8String(ByteBuffer buffer) {
if (!buffer.hasRemaining()) {
return EMPTY;
}
if (buffer.hasArray()) {
return new String(buffer.array(), buffer.arrayOffset() + buffer.position(), buffer.remaining(), UTF_8);
} else {
byte[] content = new byte[buffer.remaining()];
buffer.get(content);
return new String(content, UTF_8);
}
}
示例8: read
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public int read(ByteBuffer buffer, long endPos) {
long remained = endPos - filePos;
if (remained <= 0)
return 0;
if (remained < buffer.remaining()) {
int newLimit = (int) (buffer.position() + remained);
buffer.limit(newLimit);
}
return read(buffer);
}
示例9: readFromInputStream
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* Reads data from given input stream into byte buffer.
* This helper does not overflow destination byte buffer.
* Bytes are read until input stream have those or until byte buffer has remaining space for them.
*
* @param src source input stream
* @param dest destination byte buffer
* @param closeStream whereas to close src input stream
* @return number of read (from input stream) / written (to buffer) bytes
* @throws IOException - if any error occurs during input stream read
*/
public static int readFromInputStream(InputStream src, ByteBuffer dest, boolean closeStream) throws IOException {
try {
int chunkSize = dest.remaining() > _16_KB ? _16_KB : dest.remaining();
byte[] chunk = new byte[chunkSize];
int read;
int written = 0;
while ((read = src.read(chunk)) != -1) {
if (!dest.hasRemaining()) {
return written;
}
if (read > dest.remaining()) {
read = dest.remaining();
}
written += read;
dest.put(chunk, 0, read);
}
return written;
} finally {
if (closeStream) {
src.close();
}
}
}
示例10: realNetSend
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void realNetSend(ByteBuffer buffer) throws IOException {
long bufLen = buffer.remaining();
long writeLen = channel.write(buffer);
if (bufLen != writeLen) {
throw new IOException("Write mysql packet failed.[write=" + writeLen
+ ", needToWrite=" + bufLen + "]");
}
channel.write(buffer);
isSend = true;
}
示例11: read
import java.nio.ByteBuffer; //导入方法依赖的package包/类
public void read(ByteBuffer source, Appendable destination) {
for (int i = 0, len = source.remaining(); i < len; i++) {
char c = (char) (source.get() & 0xff);
try {
destination.append(c);
} catch (IOException e) {
throw new UncheckedIOException
("Error appending to the destination", e);
}
}
}
示例12: sendPong
import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public void sendPong(ByteBuffer applicationData) throws IOException,
IllegalArgumentException {
if (applicationData.remaining() > 125) {
throw new IllegalArgumentException(sm.getString("wsRemoteEndpoint.tooMuchData"));
}
startMessageBlock(Constants.OPCODE_PONG, applicationData, true);
}
示例13: decodeString
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static String decodeString(ByteBuffer src) throws CharacterCodingException
{
// the decoder needs to be reset every time we use it, hence the copy per thread
CharsetDecoder theDecoder = TL_UTF8_DECODER.get();
theDecoder.reset();
CharBuffer dst = TL_CHAR_BUFFER.get();
int capacity = (int) ((double) src.remaining() * theDecoder.maxCharsPerByte());
if (dst == null)
{
capacity = Math.max(capacity, 4096);
dst = CharBuffer.allocate(capacity);
TL_CHAR_BUFFER.set(dst);
}
else
{
dst.clear();
if (dst.capacity() < capacity)
{
dst = CharBuffer.allocate(capacity);
TL_CHAR_BUFFER.set(dst);
}
}
CoderResult cr = theDecoder.decode(src, dst, true);
if (!cr.isUnderflow())
cr.throwException();
return dst.flip().toString();
}
示例14: readFrom
import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
* read data from byte buffer
* @param buffer
* read from this buffer
* @return
* buffer's current position
*/
public int readFrom(ByteBuffer buffer) {
int start = buffer.position();
byte[] data = new byte[buffer.remaining()];
buffer.get(data);
int pos = readFromBytes(data);
buffer.position(start + pos);
return pos;
}
示例15: verifyRemaining
import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static void verifyRemaining(ByteBuffer buffer, int expected) {
if (buffer.remaining() < expected) {
throw new IllegalArgumentException("Must have at least " + expected + " bytes to write");
}
}