Tabnine Logo
Unpooled.copiedBuffer
Code IndexAdd Tabnine to your IDE (free)

How to use
copiedBuffer
method
in
io.netty.buffer.Unpooled

Best Java code snippets using io.netty.buffer.Unpooled.copiedBuffer (Showing top 20 results out of 1,980)

origin: eclipse-vertx/vert.x

/**
 * Creates a new text frame from with the specified string.
 */
public WebSocketFrameImpl(String textData, boolean isFinalFrame) {
 this.type = FrameType.TEXT;
 this.isFinalFrame = isFinalFrame;
 this.binaryData = Unpooled.copiedBuffer(textData, CharsetUtil.UTF_8);
}
origin: netty/netty

/**
 * Creates a new big-endian buffer whose content is the specified
 * {@code array} encoded in the specified {@code charset}.
 * The new buffer's {@code readerIndex} and {@code writerIndex} are
 * {@code 0} and the length of the encoded string respectively.
 */
public static ByteBuf copiedBuffer(char[] array, Charset charset) {
  if (array == null) {
    throw new NullPointerException("array");
  }
  return copiedBuffer(array, 0, array.length, charset);
}
origin: netty/netty

/**
 * Creates a new big-endian buffer whose content is the specified
 * {@code string} encoded in the specified {@code charset}.
 * The new buffer's {@code readerIndex} and {@code writerIndex} are
 * {@code 0} and the length of the encoded string respectively.
 */
public static ByteBuf copiedBuffer(CharSequence string, Charset charset) {
  if (string == null) {
    throw new NullPointerException("string");
  }
  if (string instanceof CharBuffer) {
    return copiedBuffer((CharBuffer) string, charset);
  }
  return copiedBuffer(CharBuffer.wrap(string), charset);
}
origin: eclipse-vertx/vert.x

public void setTextData(String textData) {
 if (this.binaryData != null) {
  this.binaryData.release();
 }
 this.binaryData = Unpooled.copiedBuffer(textData, CharsetUtil.UTF_8);
}
origin: redisson/redisson

/**
 * Creates a new big-endian buffer whose content is the specified
 * {@code array} encoded in the specified {@code charset}.
 * The new buffer's {@code readerIndex} and {@code writerIndex} are
 * {@code 0} and the length of the encoded string respectively.
 */
public static ByteBuf copiedBuffer(char[] array, Charset charset) {
  if (array == null) {
    throw new NullPointerException("array");
  }
  return copiedBuffer(array, 0, array.length, charset);
}
origin: netty/netty

/**
 * Creates a new big-endian buffer whose content is a subregion of
 * the specified {@code array} encoded in the specified {@code charset}.
 * The new buffer's {@code readerIndex} and {@code writerIndex} are
 * {@code 0} and the length of the encoded string respectively.
 */
public static ByteBuf copiedBuffer(char[] array, int offset, int length, Charset charset) {
  if (array == null) {
    throw new NullPointerException("array");
  }
  if (length == 0) {
    return EMPTY_BUFFER;
  }
  return copiedBuffer(CharBuffer.wrap(array, offset, length), charset);
}
origin: eclipse-vertx/vert.x

private void sendServiceUnavailable(Channel ch) {
 ch.writeAndFlush(
  Unpooled.copiedBuffer("HTTP/1.1 503 Service Unavailable\r\n" +
   "Content-Length:0\r\n" +
   "\r\n", StandardCharsets.ISO_8859_1))
  .addListener(ChannelFutureListener.CLOSE);
}
origin: eclipse-vertx/vert.x

public static ByteBuf generateWSCloseFrameByteBuf(short statusCode, String reason) {
 if (reason != null)
  return Unpooled.copiedBuffer(
   Unpooled.copyShort(statusCode), // First two bytes are reserved for status code
   Unpooled.copiedBuffer(reason, Charset.forName("UTF-8"))
  );
 else
  return Unpooled.copyShort(statusCode);
}
origin: eclipse-vertx/vert.x

@Override
public NetSocket write(String str) {
 write(Unpooled.copiedBuffer(str, CharsetUtil.UTF_8));
 return this;
}
origin: eclipse-vertx/vert.x

@Override
public NetSocket write(String str, String enc) {
 synchronized (conn) {
  Charset cs = enc != null ? Charset.forName(enc) : CharsetUtil.UTF_8;
  writeData(Unpooled.copiedBuffer(str, cs), false);
  return this;
 }
}
origin: alibaba/canal

public void write(byte[]... buf) throws IOException {
  if (channel != null && channel.isWritable()) {
    channel.writeAndFlush(Unpooled.copiedBuffer(buf));
  } else {
    throw new IOException("write failed ! please checking !");
  }
}
origin: eclipse-vertx/vert.x

@Override
public NetSocket write(String str, String enc) {
 if (enc == null) {
  write(str);
 } else {
  write(Unpooled.copiedBuffer(str, Charset.forName(enc)));
 }
 return this;
}
origin: eclipse-vertx/vert.x

private static ByteBuf paddedByteBuf(int padding, byte[] bytes) {
 byte[] data = new byte[padding + bytes.length];
 System.arraycopy(bytes, 0, data, padding, bytes.length);
 return Unpooled.copiedBuffer(data).slice(padding, bytes.length);
}
origin: Netflix/zuul

@Test
public void testBufferBody3GetBody() {
  final ZuulMessage msg = new ZuulMessageImpl(new SessionContext(), new Headers());
  msg.bufferBodyContents(new DefaultHttpContent(Unpooled.copiedBuffer("Hello ".getBytes())));
  msg.bufferBodyContents(new DefaultHttpContent(Unpooled.copiedBuffer("World!".getBytes())));
  msg.bufferBodyContents(new DefaultLastHttpContent());
  final String body = new String(msg.getBody());
  assertTrue(msg.hasBody());
  assertTrue(msg.hasCompleteBody());
  assertEquals("Hello World!", body);
}
origin: eclipse-vertx/vert.x

@Test
public void testAppendDoesNotModifyByteBufIndex() throws Exception {
 ByteBuf buf = Unpooled.copiedBuffer("foobar".getBytes());
 assertEquals(0, buf.readerIndex());
 assertEquals(6, buf.writerIndex());
 Buffer buffer = Buffer.buffer(buf);
 Buffer other = Buffer.buffer("prefix");
 other.appendBuffer(buffer);
 assertEquals(0, buf.readerIndex());
 assertEquals(6, buf.writerIndex());
 assertEquals(other.toString(), "prefixfoobar");
}
origin: Netflix/zuul

@Test
public void testBufferBody3GetBodyAsText() {
  final ZuulMessage msg = new ZuulMessageImpl(new SessionContext(), new Headers());
  msg.bufferBodyContents(new DefaultHttpContent(Unpooled.copiedBuffer("Hello ".getBytes())));
  msg.bufferBodyContents(new DefaultHttpContent(Unpooled.copiedBuffer("World!".getBytes())));
  msg.bufferBodyContents(new DefaultLastHttpContent());
  final String body = msg.getBodyAsText();
  assertTrue(msg.hasBody());
  assertTrue(msg.hasCompleteBody());
  assertEquals("Hello World!", body);
}
origin: Netflix/zuul

@Override
public void setBodyAsText(String bodyText) {
  disposeBufferedBody();
  if (! Strings.isNullOrEmpty(bodyText)) {
    final ByteBuf content = Unpooled.copiedBuffer(bodyText.getBytes(Charsets.UTF_8));
    bufferBodyContents(new DefaultLastHttpContent(content));
    setContentLength(bodyText.getBytes(CS_UTF8).length);
  } else {
    bufferBodyContents(new DefaultLastHttpContent());
    setContentLength(0);
  }
}
origin: eclipse-vertx/vert.x

@Test
public void testLength2() throws Exception {
 byte[] bytes = TestUtils.randomByteArray(100);
 assertEquals(90, Buffer.buffer(Unpooled.copiedBuffer(bytes).slice(10, 90)).length());
}
origin: Netflix/zuul

@Test
public void testBufferBody2GetBody() {
  final ZuulMessage msg = new ZuulMessageImpl(new SessionContext(), new Headers());
  msg.bufferBodyContents(new DefaultHttpContent(Unpooled.copiedBuffer("Hello ".getBytes())));
  msg.bufferBodyContents(new DefaultLastHttpContent(Unpooled.copiedBuffer("World!".getBytes())));
  final String body = new String(msg.getBody());
  assertTrue(msg.hasBody());
  assertTrue(msg.hasCompleteBody());
  assertEquals("Hello World!", body);
}
origin: Netflix/zuul

@Test
public void testBufferBody3GetBodyAsText() {
  final ZuulMessage msg = new ZuulMessageImpl(new SessionContext(), new Headers());
  msg.bufferBodyContents(new DefaultHttpContent(Unpooled.copiedBuffer("Hello ".getBytes())));
  msg.bufferBodyContents(new DefaultHttpContent(Unpooled.copiedBuffer("World!".getBytes())));
  msg.bufferBodyContents(new DefaultLastHttpContent());
  final String body = msg.getBodyAsText();
  assertTrue(msg.hasBody());
  assertTrue(msg.hasCompleteBody());
  assertEquals("Hello World!", body);
}
io.netty.bufferUnpooledcopiedBuffer

Javadoc

Creates a new buffer whose content is a copy of the specified buffer's readable bytes. The new buffer's readerIndexand writerIndex are 0 and buffer.readableBytesrespectively.

Popular methods of Unpooled

  • wrappedBuffer
    Creates a new big-endian composite buffer which wraps the specified arrays without copying them. A m
  • buffer
    Creates a new big-endian Java heap buffer with the specified initialCapacity, that may grow up to ma
  • compositeBuffer
    Returns a new big-endian composite buffer with no components.
  • directBuffer
    Creates a new big-endian direct buffer with the specified initialCapacity, that may grow up to maxCa
  • unreleasableBuffer
    Return a unreleasable view on the given ByteBuf which will just ignore release and retain calls.
  • copyLong
    Create a new big-endian buffer that holds a sequence of the specified 64-bit integers.
  • copyShort
    Create a new big-endian buffer that holds a sequence of the specified 16-bit integers.
  • unmodifiableBuffer
    Wrap the given ByteBufs in an unmodifiable ByteBuf. Be aware the returned ByteBuf will not try to sl
  • wrappedUnmodifiableBuffer
    Wrap the given ByteBufs in an unmodifiable ByteBuf. Be aware the returned ByteBuf will not try to sl
  • copyInt
    Create a big-endian buffer that holds a sequence of the specified 32-bit integers.
  • copyMedium
    Create a new big-endian buffer that holds a sequence of the specified 24-bit integers.
  • copyDouble
    Create a new big-endian buffer that holds a sequence of the specified 64-bit floating point numbers.
  • copyMedium,
  • copyDouble,
  • copyFloat

Popular in Java

  • Reactive rest calls using spring rest template
  • findViewById (Activity)
  • getContentResolver (Context)
  • getSupportFragmentManager (FragmentActivity)
  • FileInputStream (java.io)
    An input stream that reads bytes from a file. File file = ...finally if (in != null) in.clos
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • Arrays (java.util)
    This class contains various methods for manipulating arrays (such as sorting and searching). This cl
  • JLabel (javax.swing)
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
  • SAXParseException (org.xml.sax)
    Encapsulate an XML parse error or warning.> This module, both source code and documentation, is in t
  • Top plugins for WebStorm
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now