All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.vertx.groovy.core.buffer.Buffer.groovy Maven / Gradle / Ivy

There is a newer version: 5.0.0.CR3
Show newest version
/*
 * Copyright 2014 Red Hat, Inc.
 *
 * Red Hat licenses this file to you under the Apache License, version 2.0
 * (the "License"); you may not use this file except in compliance with the
 * License.  You may obtain a copy of the License at:
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
 * License for the specific language governing permissions and limitations
 * under the License.
 */

package io.vertx.groovy.core.buffer;
import groovy.transform.CompileStatic
import io.vertx.lang.groovy.InternalHelper
import io.vertx.core.json.JsonObject
import io.vertx.core.json.JsonArray
import io.vertx.core.shareddata.impl.ClusterSerializable
import io.vertx.core.json.JsonObject
/**
 * Most data is shuffled around inside Vert.x using buffers.
 * 

* A buffer is a sequence of zero or more bytes that can read from or written to and which expands automatically as * necessary to accommodate any bytes written to it. You can perhaps think of a buffer as smart byte array. *

* Please consult the documentation for more information on buffers. */ @CompileStatic public class Buffer { private final def io.vertx.core.buffer.Buffer delegate; public Buffer(Object delegate) { this.delegate = (io.vertx.core.buffer.Buffer) delegate; } public Object getDelegate() { return delegate; } /** * Create a new, empty buffer. * @return the buffer */ public static Buffer buffer() { def ret= InternalHelper.safeCreate(io.vertx.core.buffer.Buffer.buffer(), io.vertx.groovy.core.buffer.Buffer.class); return ret; } /** * Create a new buffer given the initial size hint. *

* If you know the buffer will require a certain size, providing the hint can prevent unnecessary re-allocations * as the buffer is written to and resized. * @param initialSizeHint the hint, in bytes * @return the buffer */ public static Buffer buffer(int initialSizeHint) { def ret= InternalHelper.safeCreate(io.vertx.core.buffer.Buffer.buffer(initialSizeHint), io.vertx.groovy.core.buffer.Buffer.class); return ret; } /** * Create a new buffer from a string. The string will be UTF-8 encoded into the buffer. * @param string the string * @return the buffer */ public static Buffer buffer(String string) { def ret= InternalHelper.safeCreate(io.vertx.core.buffer.Buffer.buffer(string), io.vertx.groovy.core.buffer.Buffer.class); return ret; } /** * Create a new buffer from a string and using the specified encoding. * The string will be encoded into the buffer using the specified encoding. * @param string the string * @param enc * @return the buffer */ public static Buffer buffer(String string, String enc) { def ret= InternalHelper.safeCreate(io.vertx.core.buffer.Buffer.buffer(string, enc), io.vertx.groovy.core.buffer.Buffer.class); return ret; } /** * Returns a String representation of the Buffer with the UTF-8encoding * @return */ public String toString() { def ret = this.delegate.toString(); return ret; } /** * Returns a String representation of the Buffer with the encoding specified by enc * @param enc * @return */ public String toString(String enc) { def ret = this.delegate.toString(enc); return ret; } /** * Returns a Json object representation of the Buffer * @return */ public Map toJsonObject() { def ret = (Map)InternalHelper.wrapObject(this.delegate.toJsonObject()); return ret; } /** * Returns a Json array representation of the Buffer * @return */ public List toJsonArray() { def ret = (List)InternalHelper.wrapObject(this.delegate.toJsonArray()); return ret; } /** * Returns the byte at position pos in the Buffer. * @param pos * @return */ public byte getByte(int pos) { def ret = this.delegate.getByte(pos); return ret; } /** * Returns the unsigned byte at position pos in the Buffer, as a short. * @param pos * @return */ public short getUnsignedByte(int pos) { def ret = this.delegate.getUnsignedByte(pos); return ret; } /** * Returns the int at position pos in the Buffer. * @param pos * @return */ public int getInt(int pos) { def ret = this.delegate.getInt(pos); return ret; } /** * Returns the unsigned int at position pos in the Buffer, as a long. * @param pos * @return */ public long getUnsignedInt(int pos) { def ret = this.delegate.getUnsignedInt(pos); return ret; } /** * Returns the long at position pos in the Buffer. * @param pos * @return */ public long getLong(int pos) { def ret = this.delegate.getLong(pos); return ret; } /** * Returns the double at position pos in the Buffer. * @param pos * @return */ public double getDouble(int pos) { def ret = this.delegate.getDouble(pos); return ret; } /** * Returns the float at position pos in the Buffer. * @param pos * @return */ public float getFloat(int pos) { def ret = this.delegate.getFloat(pos); return ret; } /** * Returns the short at position pos in the Buffer. * @param pos * @return */ public short getShort(int pos) { def ret = this.delegate.getShort(pos); return ret; } /** * Returns the unsigned short at position pos in the Buffer, as an int. * @param pos * @return */ public int getUnsignedShort(int pos) { def ret = this.delegate.getUnsignedShort(pos); return ret; } /** * Returns a copy of a sub-sequence the Buffer as a {@link io.vertx.groovy.core.buffer.Buffer} starting at position start * and ending at position end - 1 * @param start * @param end * @return */ public Buffer getBuffer(int start, int end) { def ret= InternalHelper.safeCreate(this.delegate.getBuffer(start, end), io.vertx.groovy.core.buffer.Buffer.class); return ret; } /** * Returns a copy of a sub-sequence the Buffer as a String starting at position start * and ending at position end - 1 interpreted as a String in the specified encoding * @param start * @param end * @param enc * @return */ public String getString(int start, int end, String enc) { def ret = this.delegate.getString(start, end, enc); return ret; } /** * Returns a copy of a sub-sequence the Buffer as a String starting at position start * and ending at position end - 1 interpreted as a String in UTF-8 encoding * @param start * @param end * @return */ public String getString(int start, int end) { def ret = this.delegate.getString(start, end); return ret; } /** * Appends the specified Buffer to the end of this Buffer. The buffer will expand as necessary to accommodate * any bytes written.

* Returns a reference to this so multiple operations can be appended together. * @param buff * @return */ public Buffer appendBuffer(Buffer buff) { this.delegate.appendBuffer((io.vertx.core.buffer.Buffer)buff.getDelegate()); return this; } /** * Appends the specified Buffer starting at the offset using len to the end of this Buffer. The buffer will expand as necessary to accommodate * any bytes written.

* Returns a reference to this so multiple operations can be appended together. * @param buff * @param offset * @param len * @return */ public Buffer appendBuffer(Buffer buff, int offset, int len) { this.delegate.appendBuffer((io.vertx.core.buffer.Buffer)buff.getDelegate(), offset, len); return this; } /** * Appends the specified byte to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.

* Returns a reference to this so multiple operations can be appended together. * @param b * @return */ public Buffer appendByte(byte b) { this.delegate.appendByte(b); return this; } /** * Appends the specified unsigned byte to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.

* Returns a reference to this so multiple operations can be appended together. * @param b * @return */ public Buffer appendUnsignedByte(short b) { this.delegate.appendUnsignedByte(b); return this; } /** * Appends the specified int to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.

* Returns a reference to this so multiple operations can be appended together. * @param i * @return */ public Buffer appendInt(int i) { this.delegate.appendInt(i); return this; } /** * Appends the specified unsigned int to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.

* Returns a reference to this so multiple operations can be appended together. * @param i * @return */ public Buffer appendUnsignedInt(long i) { this.delegate.appendUnsignedInt(i); return this; } /** * Appends the specified long to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.

* Returns a reference to this so multiple operations can be appended together. * @param l * @return */ public Buffer appendLong(long l) { this.delegate.appendLong(l); return this; } /** * Appends the specified short to the end of the Buffer.The buffer will expand as necessary to accommodate any bytes written.

* Returns a reference to this so multiple operations can be appended together. * @param s * @return */ public Buffer appendShort(short s) { this.delegate.appendShort(s); return this; } /** * Appends the specified unsigned short to the end of the Buffer.The buffer will expand as necessary to accommodate any bytes written.

* Returns a reference to this so multiple operations can be appended together. * @param s * @return */ public Buffer appendUnsignedShort(int s) { this.delegate.appendUnsignedShort(s); return this; } /** * Appends the specified float to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.

* Returns a reference to this so multiple operations can be appended together. * @param f * @return */ public Buffer appendFloat(float f) { this.delegate.appendFloat(f); return this; } /** * Appends the specified double to the end of the Buffer. The buffer will expand as necessary to accommodate any bytes written.

* Returns a reference to this so multiple operations can be appended together. * @param d * @return */ public Buffer appendDouble(double d) { this.delegate.appendDouble(d); return this; } /** * Appends the specified String to the end of the Buffer with the encoding as specified by enc.

* The buffer will expand as necessary to accommodate any bytes written.

* Returns a reference to this so multiple operations can be appended together.

* @param str * @param enc * @return */ public Buffer appendString(String str, String enc) { this.delegate.appendString(str, enc); return this; } /** * Appends the specified String str to the end of the Buffer with UTF-8 encoding.

* The buffer will expand as necessary to accommodate any bytes written.

* Returns a reference to this so multiple operations can be appended together

* @param str * @return */ public Buffer appendString(String str) { this.delegate.appendString(str); return this; } /** * Sets the byte at position pos in the Buffer to the value b.

* The buffer will expand as necessary to accommodate any value written. * @param pos * @param b * @return */ public Buffer setByte(int pos, byte b) { this.delegate.setByte(pos, b); return this; } /** * Sets the unsigned byte at position pos in the Buffer to the value b.

* The buffer will expand as necessary to accommodate any value written. * @param pos * @param b * @return */ public Buffer setUnsignedByte(int pos, short b) { def ret= InternalHelper.safeCreate(this.delegate.setUnsignedByte(pos, b), io.vertx.groovy.core.buffer.Buffer.class); return ret; } /** * Sets the int at position pos in the Buffer to the value i.

* The buffer will expand as necessary to accommodate any value written. * @param pos * @param i * @return */ public Buffer setInt(int pos, int i) { this.delegate.setInt(pos, i); return this; } /** * Sets the unsigned int at position pos in the Buffer to the value i.

* The buffer will expand as necessary to accommodate any value written. * @param pos * @param i * @return */ public Buffer setUnsignedInt(int pos, long i) { this.delegate.setUnsignedInt(pos, i); return this; } /** * Sets the long at position pos in the Buffer to the value l.

* The buffer will expand as necessary to accommodate any value written. * @param pos * @param l * @return */ public Buffer setLong(int pos, long l) { this.delegate.setLong(pos, l); return this; } /** * Sets the double at position pos in the Buffer to the value d.

* The buffer will expand as necessary to accommodate any value written. * @param pos * @param d * @return */ public Buffer setDouble(int pos, double d) { this.delegate.setDouble(pos, d); return this; } /** * Sets the float at position pos in the Buffer to the value f.

* The buffer will expand as necessary to accommodate any value written. * @param pos * @param f * @return */ public Buffer setFloat(int pos, float f) { this.delegate.setFloat(pos, f); return this; } /** * Sets the short at position pos in the Buffer to the value s.

* The buffer will expand as necessary to accommodate any value written. * @param pos * @param s * @return */ public Buffer setShort(int pos, short s) { this.delegate.setShort(pos, s); return this; } /** * Sets the unsigned short at position pos in the Buffer to the value s.

* The buffer will expand as necessary to accommodate any value written. * @param pos * @param s * @return */ public Buffer setUnsignedShort(int pos, int s) { this.delegate.setUnsignedShort(pos, s); return this; } /** * Sets the bytes at position pos in the Buffer to the bytes represented by the Buffer b.

* The buffer will expand as necessary to accommodate any value written. * @param pos * @param b * @return */ public Buffer setBuffer(int pos, Buffer b) { this.delegate.setBuffer(pos, (io.vertx.core.buffer.Buffer)b.getDelegate()); return this; } /** * Sets the bytes at position pos in the Buffer to the bytes represented by the Buffer b on the given offset and len.

* The buffer will expand as necessary to accommodate any value written. * @param pos * @param b * @param offset * @param len * @return */ public Buffer setBuffer(int pos, Buffer b, int offset, int len) { this.delegate.setBuffer(pos, (io.vertx.core.buffer.Buffer)b.getDelegate(), offset, len); return this; } /** * Sets the bytes at position pos in the Buffer to the value of str encoded in UTF-8.

* The buffer will expand as necessary to accommodate any value written. * @param pos * @param str * @return */ public Buffer setString(int pos, String str) { this.delegate.setString(pos, str); return this; } /** * Sets the bytes at position pos in the Buffer to the value of str encoded in encoding enc.

* The buffer will expand as necessary to accommodate any value written. * @param pos * @param str * @param enc * @return */ public Buffer setString(int pos, String str, String enc) { this.delegate.setString(pos, str, enc); return this; } /** * Returns the length of the buffer, measured in bytes. * All positions are indexed from zero. * @return */ public int length() { def ret = this.delegate.length(); return ret; } /** * Returns a copy of the entire Buffer. * @return */ public Buffer copy() { def ret= InternalHelper.safeCreate(this.delegate.copy(), io.vertx.groovy.core.buffer.Buffer.class); return ret; } /** * Returns a slice of this buffer. Modifying the content * of the returned buffer or this buffer affects each other's content * while they maintain separate indexes and marks. * @return */ public Buffer slice() { def ret= InternalHelper.safeCreate(this.delegate.slice(), io.vertx.groovy.core.buffer.Buffer.class); return ret; } /** * Returns a slice of this buffer. Modifying the content * of the returned buffer or this buffer affects each other's content * while they maintain separate indexes and marks. * @param start * @param end * @return */ public Buffer slice(int start, int end) { def ret= InternalHelper.safeCreate(this.delegate.slice(start, end), io.vertx.groovy.core.buffer.Buffer.class); return ret; } }