Package org.arch.buffer

Examples of org.arch.buffer.Buffer


    try
    {
      int t = BufferHelper.readVarInt(buffer);
      type = CompressorType.fromInt(t);
      int size = BufferHelper.readVarInt(buffer);
      Buffer content = buffer;
      byte[] raw = buffer.getRawBuffer();
     
      switch (type)
      {
        case QUICKLZ:
View Full Code Here


  @Override
  protected boolean onEncode(Buffer outbuf)
  {
    BufferHelper.writeVarInt(outbuf, type.getValue());
    Buffer content = new Buffer(256);
    ev.encode(content);
    byte[] raw = content.getRawBuffer();
    switch (type)
    {
      case NONE:
      {
        BufferHelper.writeVarInt(outbuf, content.readableBytes());
        outbuf.write(raw,content.getReadIndex(), content.readableBytes());
        break;
      }
      case QUICKLZ:
      {
        try
        {
          byte[] newbuf = QuickLZ.compress(raw,
                  content.getReadIndex(), content.readableBytes(), 1);
          BufferHelper.writeVarInt(outbuf, newbuf.length);
          outbuf.write(newbuf);
        }
        catch (Exception e)
        {
          //logger.error("Failed to compress by QuickLZ.", e);
          return false;
        }

        break;
      }
      case FASTLZ:
      {
        byte[] newbuf = new byte[raw.length];
        JFastLZ fastlz = new JFastLZ();
        int afterCompress;
        try
        {
          afterCompress = fastlz.fastlzCompress(raw,
                  content.getReadIndex(), content.readableBytes(),
                  newbuf, 0, newbuf.length);
          BufferHelper.writeVarInt(outbuf, afterCompress);
          outbuf.write(newbuf, 0, afterCompress);
        }
        catch (IOException e)
        {
          //logger.error("Failed to compress by FastLZ.", e);
          return false;
        }
        break;
      }
      case SNAPPY:
      {
        try
        {
          byte[] newbuf = new byte[Snappy.maxCompressedLength(content.readableBytes())];
          int len = Snappy.compress(raw,
                  content.getReadIndex(), content.readableBytes(), newbuf, 0);
//          SnappyBuffer newbuf = SnappyCompressor.compress(raw,
//                  content.getReadIndex(), content.readableBytes());
          BufferHelper.writeVarInt(outbuf, len);
          outbuf.write(newbuf, 0, len);
        }
        catch (Exception e)
        {
          //logger.error("Failed to compress by Snappy.", e);
          return false;
        }

        break;
      }
      case LZF:
      {
        try
        {
          byte[] newbuf = LZFEncoder.encode(raw,
                  content.readableBytes());
          BufferHelper.writeVarInt(outbuf, newbuf.length);
          outbuf.write(newbuf);
        }
        catch (Exception e)
        {
View Full Code Here

    int t;
    try
    {
      t = BufferHelper.readVarInt(buffer);
      type = EncryptType.fromInt(t);
      Buffer content = buffer;
      switch (type)
      {
        case SE1:
        {
          SimpleEncrypt se1 = new SimpleEncrypt();
View Full Code Here

 
  @Override
  protected boolean onEncode(Buffer buffer)
  {
    BufferHelper.writeVarInt(buffer, type.getValue());
    Buffer content = new Buffer(256);
    ev.encode(content);
    switch (type)
    {
      case SE1:
      {
        SimpleEncrypt se1 = new SimpleEncrypt();
        se1.encrypt(content);
        break;
      }
      case RC4:
      {
        content = RC4.encrypt(buffer);
        break;
      }
      default:
      {
        break;
      }
    }
    buffer.write(content, content.readableBytes());
    return true;
  }
View Full Code Here

  {
    try
    {
      int t = BufferHelper.readVarInt(buffer);
      type = CompressorType.fromInt(t);
      Buffer content = buffer;
      byte[] raw = buffer.getRawBuffer();
      switch (type)
      {
        case QUICKLZ:
        {
View Full Code Here

  @Override
  protected boolean onEncode(Buffer outbuf)
  {
    BufferHelper.writeVarInt(outbuf, type.getValue());
    Buffer content = new Buffer(256);
    ev.encode(content);
    byte[] raw = content.getRawBuffer();
    switch (type)
    {
      case NONE:
      {
        outbuf.write(raw,content.getReadIndex(), content.readableBytes());
        break;
      }
      case QUICKLZ:
      {
        try
        {
          byte[] newbuf = QuickLZ.compress(raw,
                  content.getReadIndex(), content.readableBytes(), 1);
          outbuf.write(newbuf);
        }
        catch (Exception e)
        {
          //logger.error("Failed to compress by QuickLZ.", e);
          return false;
        }

        break;
      }
      case FASTLZ:
      {
        byte[] newbuf = new byte[raw.length];
        JFastLZ fastlz = new JFastLZ();
        int afterCompress;
        try
        {
          afterCompress = fastlz.fastlzCompress(raw,
                  content.getReadIndex(), content.readableBytes(),
                  newbuf, 0, newbuf.length);
          outbuf.write(newbuf, 0, afterCompress);
        }
        catch (IOException e)
        {
          //logger.error("Failed to compress by FastLZ.", e);
          return false;
        }
        break;
      }
      case SNAPPY:
      {
        try
        {
          byte[] newbuf = new byte[Snappy.maxCompressedLength(content.readableBytes())];
          int len = Snappy.compress(raw,
                  content.getReadIndex(), content.readableBytes(), newbuf, 0);
//          SnappyBuffer newbuf = SnappyCompressor.compress(raw,
//                  content.getReadIndex(), content.readableBytes());
          outbuf.write(newbuf, 0, len);
        }
        catch (Exception e)
        {
          //logger.error("Failed to compress by Snappy.", e);
          return false;
        }

        break;
      }
      case LZF:
      {
        try
        {
          byte[] newbuf = LZFEncoder.encode(raw,
                  content.readableBytes());
          outbuf.write(newbuf);
        }
        catch (Exception e)
        {
          //logger.error("Failed to compress by LZF.", e);
View Full Code Here

    {
      t = BufferHelper.readVarInt(buffer);
      type = EncryptType.fromInt(t);
      int size = BufferHelper.readVarInt(buffer);
     
      Buffer content = buffer;
      switch (type)
      {
        case SE1:
        {
          SimpleEncrypt se1 = new SimpleEncrypt();
View Full Code Here

 
  @Override
  protected boolean onEncode(Buffer buffer)
  {
    BufferHelper.writeVarInt(buffer, type.getValue());
    Buffer content = new Buffer(256);
    ev.encode(content);
    switch (type)
    {
      case SE1:
      {
        SimpleEncrypt se1 = new SimpleEncrypt();
        se1.encrypt(content);
        break;
      }
      case RC4:
      {
        content = RC4.encrypt(content);
        break;
      }
      default:
      {
        break;
      }
    }
    BufferHelper.writeVarInt(buffer, content.readableBytes());
    buffer.write(content, content.readableBytes());
    return true;
  }
View Full Code Here

    {
      encrypt.type = EncryptType.NONE;
    }
    encrypt.ev = ev;
    encrypt.setHash(ev.getHash());
    Buffer buf = new Buffer(256);
    BufferHelper.writeFixInt32(buf, 1, true);
    encrypt.encode(buf);
    int tmp = buf.getWriteIndex();
    int len = tmp - 4;
    buf.setWriteIndex(0);
    BufferHelper.writeFixInt32(buf, len, true);
    buf.setWriteIndex(tmp);
    workers[index].write(buf);
  }
View Full Code Here

        logger.info(String.format("Session[%d]Recv range chunk:%s",
                this.sessionID, contentRangeHeader));
        chunks.put((int) v.getFirstBytePos(), res.content);
        while (chunks.containsKey(expectedRangePos))
        {
          Buffer chunk = chunks.remove(expectedRangePos);
          expectedRangePos += chunk.readableBytes();
          cb.onRangeChunk(chunk);
        }
        if (expectedRangePos < this.contentEnd)
        {
          logger.info(String.format(
View Full Code Here

TOP

Related Classes of org.arch.buffer.Buffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.