Tabnine Logo
DefaultDataBuffer
Code IndexAdd Tabnine to your IDE (free)

How to use
DefaultDataBuffer
in
org.springframework.core.io.buffer

Best Java code snippets using org.springframework.core.io.buffer.DefaultDataBuffer (Showing top 20 results out of 315)

origin: spring-projects/spring-framework

  @Override
  public void write(byte[] bytes, int off, int len) throws IOException {
    DefaultDataBuffer.this.write(bytes, off, len);
  }
}
origin: spring-projects/spring-framework

static DefaultDataBuffer fromFilledByteBuffer(DefaultDataBufferFactory dataBufferFactory, ByteBuffer byteBuffer) {
  DefaultDataBuffer dataBuffer = new DefaultDataBuffer(dataBufferFactory, byteBuffer);
  dataBuffer.writePosition(byteBuffer.remaining());
  return dataBuffer;
}
origin: spring-projects/spring-framework

  throw new IllegalArgumentException(String.format("'newCapacity' %d must be higher than 0", newCapacity));
int readPosition = readPosition();
int writePosition = writePosition();
int oldCapacity = capacity();
  ByteBuffer newBuffer = allocate(newCapacity, oldBuffer.isDirect());
  ((Buffer) oldBuffer).position(0).limit(oldBuffer.capacity());
  ((Buffer) newBuffer).position(0).limit(oldBuffer.capacity());
  newBuffer.put(oldBuffer);
  newBuffer.clear();
  setNativeBuffer(newBuffer);
  ByteBuffer newBuffer = allocate(newCapacity, oldBuffer.isDirect());
  if (readPosition < newCapacity) {
    if (writePosition > newCapacity) {
      writePosition = newCapacity;
      writePosition(writePosition);
    readPosition(newCapacity);
    writePosition(newCapacity);
  setNativeBuffer(newBuffer);
origin: spring-projects/spring-framework

@Override
public DataBuffer ensureCapacity(int length) {
  if (length > writableByteCount()) {
    int newCapacity = calculateCapacity(this.writePosition + length);
    capacity(newCapacity);
  }
  return this;
}
origin: spring-projects/spring-framework

@Override
public ByteBuffer asByteBuffer() {
  return asByteBuffer(this.readPosition, readableByteCount());
}
origin: spring-projects/spring-framework

@Override
public DefaultDataBuffer writePosition(int writePosition) {
  assertIndex(writePosition >= this.readPosition, "'writePosition' %d must be >= %d",
      writePosition, this.readPosition);
  assertIndex(writePosition <= this.capacity, "'writePosition' %d must be <= %d",
      writePosition, this.capacity);
  this.writePosition = writePosition;
  return this;
}
origin: spring-projects/spring-framework

@Override
public DefaultDataBuffer write(byte b) {
  ensureCapacity(1);
  int pos = this.writePosition;
  this.byteBuffer.put(pos, b);
  this.writePosition = pos + 1;
  return this;
}
origin: spring-projects/spring-framework

@Override
public ByteBuffer asByteBuffer(int index, int length) {
  checkIndex(index, length);
  ByteBuffer duplicate = this.byteBuffer.duplicate();
  // Explicit access via Buffer base type for compatibility
  // with covariant return type on JDK 9's ByteBuffer...
  Buffer buffer = duplicate;
  buffer.position(index);
  buffer.limit(index + length);
  return duplicate.slice();
}
origin: spring-projects/spring-framework

@Override
public DefaultDataBuffer allocateBuffer(int initialCapacity) {
  ByteBuffer byteBuffer = (this.preferDirect ?
      ByteBuffer.allocateDirect(initialCapacity) :
      ByteBuffer.allocate(initialCapacity));
  return DefaultDataBuffer.fromEmptyByteBuffer(this, byteBuffer);
}
origin: spring-projects/spring-framework

static DefaultDataBuffer fromEmptyByteBuffer(DefaultDataBufferFactory dataBufferFactory, ByteBuffer byteBuffer) {
  return new DefaultDataBuffer(dataBufferFactory, byteBuffer);
}
origin: org.springframework/spring-core

@Override
public DataBuffer ensureCapacity(int length) {
  if (length > writableByteCount()) {
    int newCapacity = calculateCapacity(this.writePosition + length);
    capacity(newCapacity);
  }
  return this;
}
origin: spring-projects/spring-framework

@Override
public DefaultDataBuffer readPosition(int readPosition) {
  assertIndex(readPosition >= 0, "'readPosition' %d must be >= 0", readPosition);
  assertIndex(readPosition <= this.writePosition, "'readPosition' %d must be <= %d",
      readPosition, this.writePosition);
  this.readPosition = readPosition;
  return this;
}
origin: org.springframework/spring-core

@Override
public ByteBuffer asByteBuffer() {
  return asByteBuffer(this.readPosition, readableByteCount());
}
origin: spring-projects/spring-framework

@Override
public DefaultDataBuffer write(ByteBuffer... buffers) {
  if (!ObjectUtils.isEmpty(buffers)) {
    int capacity = Arrays.stream(buffers).mapToInt(ByteBuffer::remaining).sum();
    ensureCapacity(capacity);
    Arrays.stream(buffers).forEach(this::write);
  }
  return this;
}
origin: spring-projects/spring-framework

@Override
public DefaultDataBuffer slice(int index, int length) {
  checkIndex(index, length);
  int oldPosition = this.byteBuffer.position();
  // Explicit access via Buffer base type for compatibility
  // with covariant return type on JDK 9's ByteBuffer...
  Buffer buffer = this.byteBuffer;
  try {
    buffer.position(index);
    ByteBuffer slice = this.byteBuffer.slice();
    // Explicit cast for compatibility with covariant return type on JDK 9's ByteBuffer
    ((Buffer) slice).limit(length);
    return new SlicedDefaultDataBuffer(slice, this.dataBufferFactory, length);
  }
  finally {
    buffer.position(oldPosition);
  }
}
origin: org.springframework/spring-core

@Override
public DefaultDataBuffer allocateBuffer(int initialCapacity) {
  ByteBuffer byteBuffer = (this.preferDirect ?
      ByteBuffer.allocateDirect(initialCapacity) :
      ByteBuffer.allocate(initialCapacity));
  return DefaultDataBuffer.fromEmptyByteBuffer(this, byteBuffer);
}
origin: org.springframework/spring-core

static DefaultDataBuffer fromEmptyByteBuffer(DefaultDataBufferFactory dataBufferFactory, ByteBuffer byteBuffer) {
  return new DefaultDataBuffer(dataBufferFactory, byteBuffer);
}
origin: org.springframework/spring-core

  throw new IllegalArgumentException(String.format("'newCapacity' %d must be higher than 0", newCapacity));
int readPosition = readPosition();
int writePosition = writePosition();
int oldCapacity = capacity();
  ByteBuffer newBuffer = allocate(newCapacity, oldBuffer.isDirect());
  ((Buffer) oldBuffer).position(0).limit(oldBuffer.capacity());
  ((Buffer) newBuffer).position(0).limit(oldBuffer.capacity());
  newBuffer.put(oldBuffer);
  newBuffer.clear();
  setNativeBuffer(newBuffer);
  ByteBuffer newBuffer = allocate(newCapacity, oldBuffer.isDirect());
  if (readPosition < newCapacity) {
    if (writePosition > newCapacity) {
      writePosition = newCapacity;
      writePosition(writePosition);
    readPosition(newCapacity);
    writePosition(newCapacity);
  setNativeBuffer(newBuffer);
origin: spring-projects/spring-framework

@Override
public void write(int b) throws IOException {
  DefaultDataBuffer.this.write((byte) b);
}
origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.spring-core

private void ensureCapacity(int length) {
  if (length <= writableByteCount()) {
    return;
  }
  int newCapacity = calculateCapacity(this.writePosition + length);
  capacity(newCapacity);
}
org.springframework.core.io.bufferDefaultDataBuffer

Javadoc

Default implementation of the DataBuffer interface that uses a ByteBuffer internally. with separate read and write positions. Constructed using the DefaultDataBufferFactory.

Inspired by Netty's ByteBuf. Introduced so that non-Netty runtimes (i.e. Servlet) do not require Netty on the classpath.

Most used methods

  • write
  • <init>
  • allocate
  • asByteBuffer
  • assertIndex
  • calculateCapacity
    Calculate the capacity of the buffer.
  • capacity
  • checkIndex
  • ensureCapacity
  • fromEmptyByteBuffer
  • fromFilledByteBuffer
  • read
  • fromFilledByteBuffer,
  • read,
  • readPosition,
  • readableByteCount,
  • setNativeBuffer,
  • writableByteCount,
  • writePosition,
  • getNativeBuffer

Popular in Java

  • Reactive rest calls using spring rest template
  • notifyDataSetChanged (ArrayAdapter)
  • scheduleAtFixedRate (Timer)
  • requestLocationUpdates (LocationManager)
  • FlowLayout (java.awt)
    A flow layout arranges components in a left-to-right flow, much like lines of text in a paragraph. F
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • Manifest (java.util.jar)
    The Manifest class is used to obtain attribute information for a JarFile and its entries.
  • JTextField (javax.swing)
  • Scheduler (org.quartz)
    This is the main interface of a Quartz Scheduler. A Scheduler maintains a registry of org.quartz.Job
  • CodeWhisperer alternatives
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