Top Description Inners Fields Constructors Methods
org.apache.avro.io

public Class BinaryData

extends Object
Class Inheritance
Imports
java.io.IOException, org.apache.avro.Schema, .Schema.Field, .AvroRuntimeException, org.apache.avro.generic.GenericDatumReader, org.apache.avro.util.internal.ThreadLocalWithInitial

Utilities for binary-encoded data.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private static final ThreadLocal<BinaryData.Decoders>
private static final ThreadLocal<BinaryData.HashData>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static int
compare(byte[] b1, int s1, byte[] b2, int s2, Schema schema)

Compare binary encoded data.

public static int
compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2, Schema schema)

Compare binary encoded data.

private static int
compare(BinaryData.Decoders d, Schema schema)

If equal, return the number of bytes consumed.

public static int
compareBytes(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2)

Lexicographically compare bytes.

public static int

Returns:

The number of bytes written to the buffer, 1.
encodeBoolean
(boolean b, byte[] buf, int pos)

Encode a boolean to the byte array at the given position.

public static int

Returns:

Returns the number of bytes written to the buffer, 8.
encodeDouble
(double d, byte[] buf, int pos)

Encode a double to the byte array at the given position.

public static int

Returns:

Returns the number of bytes written to the buffer, 4.
encodeFloat
(float f, byte[] buf, int pos)

Encode a float to the byte array at the given position.

public static int

Returns:

The number of bytes written to the buffer, between 1 and 5.
encodeInt
(int n, byte[] buf, int pos)

Encode an integer to the byte array at the given position.

public static int

Returns:

The number of bytes written to the buffer, between 1 and 10.
encodeLong
(long n, byte[] buf, int pos)

Encode a long to the byte array at the given position.

private static int
hashBytes(int init, BinaryData.HashData data, int len, boolean rev)

public static int
hashCode(byte[] bytes, int start, int length, Schema schema)

Hash binary encoded data.

private static int
public static int
skipLong(final byte[] bytes, int start)

Skip a binary-encoded long, returning the position after it.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

DECODERSback to summary
private static final ThreadLocal<BinaryData.Decoders> DECODERS
HASH_DATAback to summary
private static final ThreadLocal<BinaryData.HashData> HASH_DATA

Constructor Detail

BinaryDataback to summary
private BinaryData()

Method Detail

compareback to summary
public static int compare(byte[] b1, int s1, byte[] b2, int s2, Schema schema)

Compare binary encoded data. If equal, return zero. If greater-than, return 1, if less than return -1. Order is consistent with that of org.apache.avro.generic.GenericData#compare(Object, Object, Schema).

compareback to summary
public static int compare(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2, Schema schema)

Compare binary encoded data. If equal, return zero. If greater-than, return 1, if less than return -1. Order is consistent with that of org.apache.avro.generic.GenericData#compare(Object, Object, Schema).

compareback to summary
private static int compare(BinaryData.Decoders d, Schema schema) throws IOException

If equal, return the number of bytes consumed. If greater than, return GT, if less than, return LT.

compareBytesback to summary
public static int compareBytes(byte[] b1, int s1, int l1, byte[] b2, int s2, int l2)

Lexicographically compare bytes. If equal, return zero. If greater-than, return a positive value, if less than return a negative value.

encodeBooleanback to summary
public static int encodeBoolean(boolean b, byte[] buf, int pos)

Encode a boolean to the byte array at the given position. Will throw IndexOutOfBounds if the position is not valid.

Returns:int

The number of bytes written to the buffer, 1.

encodeDoubleback to summary
public static int encodeDouble(double d, byte[] buf, int pos)

Encode a double to the byte array at the given position. Will throw IndexOutOfBounds if it overflows. Users should ensure that there are at least 8 bytes left in the buffer before calling this method.

Returns:int

Returns the number of bytes written to the buffer, 8.

encodeFloatback to summary
public static int encodeFloat(float f, byte[] buf, int pos)

Encode a float to the byte array at the given position. Will throw IndexOutOfBounds if it overflows. Users should ensure that there are at least 4 bytes left in the buffer before calling this method.

Returns:int

Returns the number of bytes written to the buffer, 4.

encodeIntback to summary
public static int encodeInt(int n, byte[] buf, int pos)

Encode an integer to the byte array at the given position. Will throw IndexOutOfBounds if it overflows. Users should ensure that there are at least 5 bytes left in the buffer before calling this method.

Returns:int

The number of bytes written to the buffer, between 1 and 5.

encodeLongback to summary
public static int encodeLong(long n, byte[] buf, int pos)

Encode a long to the byte array at the given position. Will throw IndexOutOfBounds if it overflows. Users should ensure that there are at least 10 bytes left in the buffer before calling this method.

Returns:int

The number of bytes written to the buffer, between 1 and 10.

hashBytesback to summary
private static int hashBytes(int init, BinaryData.HashData data, int len, boolean rev) throws IOException
hashCodeback to summary
public static int hashCode(byte[] bytes, int start, int length, Schema schema)

Hash binary encoded data. Consistent with org.apache.avro.generic.GenericData#hashCode(Object, Schema).

hashCodeback to summary
private static int hashCode(BinaryData.HashData data, Schema schema) throws IOException
skipLongback to summary
public static int skipLong(final byte[] bytes, int start)

Skip a binary-encoded long, returning the position after it.

org.apache.avro.io back to summary

private Class BinaryData.Decoders

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final BinaryDecoder
private final BinaryDecoder

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
public void
set(byte[] data1, int off1, int len1, byte[] data2, int off2, int len2)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

d1back to summary
private final BinaryDecoder d1
d2back to summary
private final BinaryDecoder d2

Constructor Detail

Decodersback to summary
public Decoders()

Method Detail

clearback to summary
public void clear()
setback to summary
public void set(byte[] data1, int off1, int len1, byte[] data2, int off2, int len2)
org.apache.avro.io back to summary

private Class BinaryData.HashData

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private final BinaryDecoder

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
set(byte[] bytes, int start, int len)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

decoderback to summary
private final BinaryDecoder decoder

Constructor Detail

HashDataback to summary
public HashData()

Method Detail

setback to summary
public void set(byte[] bytes, int start, int len)