当前位置: 首页>>代码示例>>Java>>正文


Java ByteBuffer.reset方法代码示例

本文整理汇总了Java中java.nio.ByteBuffer.reset方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBuffer.reset方法的具体用法?Java ByteBuffer.reset怎么用?Java ByteBuffer.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.nio.ByteBuffer的用法示例。


在下文中一共展示了ByteBuffer.reset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: findDesigBuf

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private int findDesigBuf(ByteBuffer in, byte[][] desigs) {
    if (desigs == null) return -1;
    int i = 0;
    while (i < desigs.length) {
        if (desigs[i] != null && in.remaining() >= desigs[i].length) {
            int j = 0;
            in.mark();
            while (j < desigs[i].length && in.get() == desigs[i][j]) { j++; }
            if (j == desigs[i].length)
                return i;
            in.reset();
        }
        i++;
    }
    return -1;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:17,代码来源:ISO2022.java

示例2: c

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public List<com.meiqia.core.a.a.d.d> c(ByteBuffer byteBuffer) {
    byteBuffer.mark();
    List<com.meiqia.core.a.a.d.d> e = super.e(byteBuffer);
    if (e == null) {
        byteBuffer.reset();
        e = this.g;
        this.f = true;
        if (this.h == null) {
            this.h = ByteBuffer.allocate(2);
            if (byteBuffer.remaining() > this.h.remaining()) {
                throw new com.meiqia.core.a.a.c.c();
            }
            this.h.put(byteBuffer);
            if (this.h.hasRemaining()) {
                this.g = new LinkedList();
            } else if (Arrays.equals(this.h.array(), j)) {
                e.add(new com.meiqia.core.a.a.d.b(1000));
            } else {
                throw new com.meiqia.core.a.a.c.c();
            }
        }
        throw new com.meiqia.core.a.a.c.c();
    }
    return e;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:26,代码来源:h.java

示例3: bytesToCodePoint

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Returns the next code point at the current position in
 * the buffer. The buffer's position will be incremented.
 * Any mark set on this buffer will be changed by this method!
 */
public static int bytesToCodePoint(ByteBuffer bytes) {
  bytes.mark();
  byte b = bytes.get();
  bytes.reset();
  int extraBytesToRead = bytesFromUTF8[(b & 0xFF)];
  if (extraBytesToRead < 0) return -1; // trailing byte!
  int ch = 0;

  switch (extraBytesToRead) {
  case 5: ch += (bytes.get() & 0xFF); ch <<= 6; /* remember, illegal UTF-8 */
  case 4: ch += (bytes.get() & 0xFF); ch <<= 6; /* remember, illegal UTF-8 */
  case 3: ch += (bytes.get() & 0xFF); ch <<= 6;
  case 2: ch += (bytes.get() & 0xFF); ch <<= 6;
  case 1: ch += (bytes.get() & 0xFF); ch <<= 6;
  case 0: ch += (bytes.get() & 0xFF);
  }
  ch -= offsetsFromUTF8[extraBytesToRead];

  return ch;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:26,代码来源:Text.java

示例4: isFlashEdgeCase

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private HandshakeState isFlashEdgeCase(ByteBuffer request) throws IncompleteHandshakeException {
    request.mark();
    if (request.limit() > Draft.FLASH_POLICY_REQUEST.length) {
        return HandshakeState.NOT_MATCHED;
    } else if (request.limit() < Draft.FLASH_POLICY_REQUEST.length) {
        throw new IncompleteHandshakeException(Draft.FLASH_POLICY_REQUEST.length);
    } else {

        for (int flash_policy_index = 0; request.hasRemaining(); flash_policy_index++) {
            if (Draft.FLASH_POLICY_REQUEST[flash_policy_index] != request.get()) {
                request.reset();
                return HandshakeState.NOT_MATCHED;
            }
        }
        return HandshakeState.MATCHED;
    }
}
 
开发者ID:GloriousEggroll,项目名称:quorrabot,代码行数:18,代码来源:WebSocketImpl.java

示例5: cloneChunkWithData

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Clone chunk along with copying the associated data. It respects how the
 * chunk buffer is allocated, direct or non-direct. It avoids affecting the
 * original chunk.
 * @param chunk
 * @return a new chunk
 */
protected ECChunk cloneChunkWithData(ECChunk chunk) {
  if (chunk == null) {
    return null;
  }

  ByteBuffer srcBuffer = chunk.getBuffer();

  byte[] bytesArr = new byte[srcBuffer.remaining()];
  srcBuffer.mark();
  srcBuffer.get(bytesArr, 0, bytesArr.length);
  srcBuffer.reset();

  ByteBuffer destBuffer = allocateOutputBuffer(bytesArr.length);
  int pos = destBuffer.position();
  destBuffer.put(bytesArr);
  destBuffer.flip();
  destBuffer.position(pos);

  return new ECChunk(destBuffer);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:28,代码来源:TestCoderBase.java

示例6: createBinaryFrame

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public ByteBuffer createBinaryFrame(Framedata framedata) {
    if (framedata.getOpcode() != Opcode.TEXT) {
        throw new RuntimeException("only text frames supported");
    }

    ByteBuffer pay = framedata.getPayloadData();
    ByteBuffer b = ByteBuffer.allocate(pay.remaining() + 2);
    b.put(START_OF_FRAME);
    pay.mark();
    b.put(pay);
    pay.reset();
    b.put(END_OF_FRAME);
    b.flip();
    return b;
}
 
开发者ID:GloriousEggroll,项目名称:quorrabot,代码行数:17,代码来源:Draft_75.java

示例7: readBytes

import java.nio.ByteBuffer; //导入方法依赖的package包/类
/**
 * Read a buffer into a Byte array for the given offset and length
 */
public static byte[] readBytes(ByteBuffer buffer, int offset, int length) {
    byte[] dest = new byte[length];
    if (buffer.hasArray()) {
        System.arraycopy(buffer.array(), buffer.arrayOffset() + offset, dest, 0, length);
    } else {
        buffer.mark();
        buffer.position(offset);
        buffer.get(dest, 0, length);
        buffer.reset();
    }
    return dest;
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:16,代码来源:Utils.java

示例8: parseAttributes

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void parseAttributes(ByteBuffer buffer) {
    int offset = this.offset + getHeaderSize() + attributeStart;
    int endOffset = offset + XmlAttribute.SIZE * attributeCount;
    buffer.mark();
    buffer.position(offset);
    while (offset < endOffset) {
        XmlAttribute attribute = XmlAttribute.create(buffer, this);
        nameIndexToAttribute.put(attribute.nameIndex(), attribute);
        offset += XmlAttribute.SIZE;
    }
    buffer.reset();
}
 
开发者ID:CalebFenton,项目名称:apkfile,代码行数:13,代码来源:XmlStartElementChunk.java

示例9: doIntelE8Decoding

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private void doIntelE8Decoding(ByteBuffer outBuf) {
    long curPos = intelCurPos;
    long fileSize = intelFileSize;

    outBuf.mark();
    while (outBuf.position() < outBuf.limit() - 10) {
        int b = outBuf.get() & 0xff;
        if (b != 0xe8) {
            curPos++;
            continue;
        }

        int markedOutBufPos = outBuf.position();

        // get UInt32
        int tmp = outBuf.getInt();
        long absoluteOffset = tmp & 0x00000000ffffffffL;

        if ((absoluteOffset >= -curPos) && (absoluteOffset < fileSize)) {
            long relativeOffset;
            if (absoluteOffset >= 0) {
                relativeOffset = absoluteOffset - curPos;
            } else {
                relativeOffset = absoluteOffset + fileSize;
            }
            outBuf.position(markedOutBufPos);
            outBuf.put((byte) (relativeOffset & 0xFF));
            outBuf.put((byte) ((relativeOffset >>> 8) & 0xFF));
            outBuf.put((byte) ((relativeOffset >>> 16) & 0xFF));
            outBuf.put((byte) ((relativeOffset >>> 24) & 0xFF));
        }
        curPos += 5;
    }
    outBuf.reset();
}
 
开发者ID:chimenchen,项目名称:jchmlib,代码行数:36,代码来源:LZXInflator.java

示例10: a

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public ByteBuffer a(d dVar) {
    if (dVar.f() != e.TEXT) {
        throw new RuntimeException("only text frames supported");
    }
    ByteBuffer c = dVar.c();
    ByteBuffer allocate = ByteBuffer.allocate(c.remaining() + 2);
    allocate.put((byte) 0);
    c.mark();
    allocate.put(c);
    c.reset();
    allocate.put((byte) -1);
    allocate.flip();
    return allocate;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:15,代码来源:g.java

示例11: translateFrame

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public List<Framedata> translateFrame(ByteBuffer buffer) throws InvalidDataException {
    buffer.mark();
    List<Framedata> frames = super.translateRegularFrame(buffer);
    if (frames == null) {
        buffer.reset();
        frames = readyframes;
        readingState = true;
        if (currentFrame == null) {
            currentFrame = ByteBuffer.allocate(2);
        } else {
            throw new InvalidFrameException();
        }
        if (buffer.remaining() > currentFrame.remaining()) {
            throw new InvalidFrameException();
        } else {
            currentFrame.put(buffer);
        }
        if (!currentFrame.hasRemaining()) {
            if (Arrays.equals(currentFrame.array(), closehandshake)) {
                frames.add(new CloseFrameBuilder(CloseFrame.NORMAL));
                return frames;
            } else {
                throw new InvalidFrameException();
            }
        } else {
            readyframes = new LinkedList<Framedata>();
            return frames;
        }
    } else {
        return frames;
    }
}
 
开发者ID:GloriousEggroll,项目名称:quorrabot,代码行数:34,代码来源:Draft_76.java

示例12: directify

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private static ByteBuffer directify(ByteBuffer dataBuf) {
  ByteBuffer newBuf = ByteBuffer.allocateDirect(dataBuf.capacity());
  newBuf.position(dataBuf.position());
  newBuf.mark();
  newBuf.put(dataBuf);
  newBuf.reset();
  newBuf.limit(dataBuf.limit());
  return newBuf;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:10,代码来源:TestDataChecksum.java

示例13: enumerateResources

import java.nio.ByteBuffer; //导入方法依赖的package包/类
private List<Integer> enumerateResources(ByteBuffer buffer) {
  int resourceCount = (getOriginalChunkSize() - getHeaderSize()) / RESOURCE_SIZE;
  List<Integer> result = new ArrayList<>(resourceCount);
  int offset = this.offset + getHeaderSize();
  buffer.mark();
  buffer.position(offset);

  for (int i = 0; i < resourceCount; ++i) {
    result.add(buffer.getInt());
  }

  buffer.reset();
  return result;
}
 
开发者ID:madisp,项目名称:android-chunk-utils,代码行数:15,代码来源:XmlResourceMapChunk.java

示例14: willDecode

import java.nio.ByteBuffer; //导入方法依赖的package包/类
@Override
public boolean willDecode(ByteBuffer bb) {
    bb.mark();
    if (bb.get() == 0x12 && bb.get() == 0x34) {
        return true;
    }
    bb.reset();
    return false;
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:10,代码来源:TestEncodingDecoding.java

示例15: stringUtf8

import java.nio.ByteBuffer; //导入方法依赖的package包/类
public static String stringUtf8(ByteBuffer bytes) throws InvalidDataException {
    CharsetDecoder decode = Charset.forName("UTF8").newDecoder();
    decode.onMalformedInput(codingErrorAction);
    decode.onUnmappableCharacter(codingErrorAction);
    // decode.replaceWith( "X" );
    String s;
    try {
        bytes.mark();
        s = decode.decode(bytes).toString();
        bytes.reset();
    } catch (CharacterCodingException e) {
        throw new InvalidDataException(CloseFrame.NO_UTF8, e);
    }
    return s;
}
 
开发者ID:GloriousEggroll,项目名称:quorrabot,代码行数:16,代码来源:Charsetfunctions.java


注:本文中的java.nio.ByteBuffer.reset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。