Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF 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 org.apache.avro.io;
 
 
Low-level support for de-serializing Avro values.

This class has two types of methods. One type of methods support the reading of leaf values (for example, readLong() and readString(org.apache.avro.util.Utf8)). The other type of methods support the reading of maps and arrays. These methods are readArrayStart(), arrayNext(), and similar methods for maps). See readArrayStart() for details on these methods.)

See also:
Encoder
 
 
 public abstract class Decoder {
  
  
Start reading against a different input stream. Stateful subclasses will reset their states to their initial state.

A Decoder may read ahead beyond the minimum bytes necessary, similar to a BufferedInputStream. In order to interleave reads on this stream's data between Decoder and another reader, the other reader must use the buffer-aware input stream returned by the Decoder implementation, if applicable.

 
   public abstract void init(InputStream inthrows IOException;

  
"Reads" a null value. (Doesn't actually read anything, but advances the state of the parser if the implementation is stateful.)

Throws:
AvroTypeException If this is a stateful reader and null is not the type of the next value to be read
 
   public abstract void readNull() throws IOException;

  
Reads a boolean value written by Encoder.writeBoolean(boolean).

Throws:
AvroTypeException If this is a stateful reader and boolean is not the type of the next value to be read
 
 
   public abstract boolean readBoolean() throws IOException;

  
Reads an integer written by Encoder.writeInt(int).

Throws:
AvroTypeException If encoded value is larger than 32-bits
AvroTypeException If this is a stateful reader and int is not the type of the next value to be read
 
   public abstract int readInt() throws IOException;

  
Reads a long written by Encoder.writeLong(long).

Throws:
AvroTypeException If this is a stateful reader and long is not the type of the next value to be read
 
   public abstract long readLong() throws IOException;

  
Reads a float written by Encoder.writeFloat(float).

Throws:
AvroTypeException If this is a stateful reader and is not the type of the next value to be read
 
   public abstract float readFloat() throws IOException;

  
Reads a double written by Encoder.writeDouble(double).

Throws:
AvroTypeException If this is a stateful reader and is not the type of the next value to be read
 
  public abstract double readDouble() throws IOException;
    
  
Reads a char-string written by Encoder.writeString(org.apache.avro.util.Utf8).

Throws:
AvroTypeException If this is a stateful reader and char-string is not the type of the next value to be read
  public abstract Utf8 readString(Utf8 oldthrows IOException;
    
  
Discards a char-string written by Encoder.writeString(org.apache.avro.util.Utf8).

Throws:
AvroTypeException If this is a stateful reader and char-string is not the type of the next value to be read
  public abstract void skipString() throws IOException;

  
Reads a byte-string written by Encoder.writeBytes(java.nio.ByteBuffer). if old is not null and has sufficient capacity to take in the bytes being read, the bytes are returned in old.

Throws:
AvroTypeException If this is a stateful reader and byte-string is not the type of the next value to be read
  public abstract ByteBuffer readBytes(ByteBuffer oldthrows IOException;

  
Discards a byte-string written by Encoder.writeBytes(java.nio.ByteBuffer).

Throws:
AvroTypeException If this is a stateful reader and byte-string is not the type of the next value to be read
  public abstract void skipBytes() throws IOException;
  
  
Reads fixed sized binary object.

Parameters:
bytes The buffer to store the contents being read.
start The position where the data needs to be written.
length The size of the binary object.
Throws:
AvroTypeException If this is a stateful reader and fixed sized binary object is not the type of the next value to be read or the length is incorrect.
java.io.IOException
  public abstract void readFixed(byte[] bytesint startint length)
    throws IOException;

  
A shorthand for readFixed(bytes, 0, bytes.length).

Throws:
AvroTypeException If this is a stateful reader and fixed sized binary object is not the type of the next value to be read or the length is incorrect.
java.io.IOException
  public void readFixed(byte[] bytesthrows IOException {
    readFixed(bytes, 0, bytes.length);
  }
  
  
Discards fixed sized binary object.

Parameters:
length The size of the binary object to be skipped.
Throws:
AvroTypeException If this is a stateful reader and fixed sized binary object is not the type of the next value to be read or the length is incorrect.
java.io.IOException
  public abstract void skipFixed(int lengththrows IOException;

  
Reads an enumeration.

Returns:
The enumeration's value.
Throws:
AvroTypeException If this is a stateful reader and enumeration is not the type of the next value to be read.
java.io.IOException
  public abstract int readEnum() throws IOException;
  
  
Reads and returns the size of the first block of an array. If this method returns non-zero, then the caller should read the indicated number of items, and then call arrayNext() to find out the number of items in the next block. The typical pattern for consuming an array looks like:
   for(long i = in.readArrayStart(); i != 0; i = in.arrayNext()) {
     for (long j = 0; j < i; j++) {
       read next element of the array;
     }
   }
 

Throws:
AvroTypeException If this is a stateful reader and array is not the type of the next value to be read
  public abstract long readArrayStart() throws IOException;

  
Processes the next block of an array andreturns the number of items in the block and let's the caller read those items.

Throws:
AvroTypeException When called outside of an array context
  public abstract long arrayNext() throws IOException;

  
Used for quickly skipping through an array. Note you can either skip the entire array, or read the entire array (with readArrayStart()), but you can't mix the two on the same array. This method will skip through as many items as it can, all of them if possible. It will return zero if there are no more items to skip through, or an item count if it needs the client's help in skipping. The typical usage pattern is:
   for(long i = in.skipArray(); i != 0; i = i.skipArray()) {
     for (long j = 0; j < i; j++) {
       read and discard the next element of the array;
     }
   }
 
Note that this method can automatically skip through items if a byte-count is found in the underlying data, or if a schema has been provided to the implementation, but otherwise the client will have to skip through items itself.

Throws:
AvroTypeException If this is a stateful reader and array is not the type of the next value to be read
  public abstract long skipArray() throws IOException;

  
Reads and returns the size of the next block of map-entries. Similar to readArrayStart(). As an example, let's say you want to read a map of records, the record consisting of an Long field and a Boolean field. Your code would look something like this:
   Map<String,Record> m = new HashMap<String,Record>();
   Record reuse = new Record();
   for(long i = in.readMapStart(); i != 0; i = in.readMapNext()) {
     for (long j = 0; j < i; j++) {
       String key = in.readString();
       reuse.intField = in.readInt();
       reuse.boolField = in.readBoolean();
       m.put(key, reuse);
     }
   }
 

Throws:
AvroTypeException If this is a stateful reader and map is not the type of the next value to be read
  public abstract long readMapStart() throws IOException;

  
Processes the next block of map entries and returns the count of them. Similar to arrayNext(). See readMapStart() for details.

Throws:
AvroTypeException When called outside of a map context
  public abstract long mapNext() throws IOException;

  
Support for quickly skipping through a map similar to skipArray(). As an example, let's say you want to skip a map of records, the record consisting of an Long field and a Boolean field. Your code would look something like this:
   for(long i = in.skipMap(); i != 0; i = in.skipMap()) {
     for (long j = 0; j < i; j++) {
       in.skipString();  // Discard key
       in.readInt(); // Discard int-field of value
       in.readBoolean(); // Discard boolean-field of value
     }
   }
 

Throws:
AvroTypeException If this is a stateful reader and array is not the type of the next value to be read
  public abstract long skipMap() throws IOException;

  
Reads the tag of a union written by Encoder.writeIndex(int).

Throws:
AvroTypeException If this is a stateful reader and union is not the type of the next value to be read
  public abstract int readIndex() throws IOException;
New to GrepCode? Check out our FAQ X