PacketReceiver (Apache Hadoop HDFS Client 3.5.0 API)
Description: declaration: package: org.apache.hadoop.hdfs.protocol.datatransfer, class: PacketReceiver

Package org.apache.hadoop.hdfs.protocol.datatransfer

# Class PacketReceiver

java.lang.Object
org.apache.hadoop.hdfs.protocol.datatransfer.PacketReceiver

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`

@Private public class PacketReceiver extends Object implements Closeable
Class to handle reading packets one-at-a-time from the wire. These packets are used both for reading and writing data to/from DataNodes.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `MAX_PACKET_SIZE`
  The max size of any single packet.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `PacketReceiver(boolean useDirectBuffers)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `close()`
  `protected void`
  `finalize()`
  `ByteBuffer`
  `getChecksumSlice()`
  `ByteBuffer`
  `getDataSlice()`
  `PacketHeader`
  `getHeader()`
  `void`
  `mirrorPacketTo(DataOutputStream mirrorOut)`
  Rewrite the last-read packet on the wire to the given output stream.
  `void`
  `receiveNextPacket(InputStream in)`
  `void`
  `receiveNextPacket(ReadableByteChannel in)`
  Reads all of the data for the next packet into the appropriate buffers.

  ### Methods inherited from class java.lang.Object

  `clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Field Details

  - ### MAX_PACKET_SIZE

    public static final int MAX_PACKET_SIZE
    The max size of any single packet. This prevents OOMEs when invalid data is sent.

- ## Constructor Details

  - ### PacketReceiver

    public PacketReceiver(boolean useDirectBuffers)

- ## Method Details

  - ### getHeader

    public PacketHeader getHeader()

  - ### getDataSlice

    public ByteBuffer getDataSlice()

  - ### getChecksumSlice

    public ByteBuffer getChecksumSlice()

  - ### receiveNextPacket

    public void receiveNextPacket(ReadableByteChannel in) throws IOException
    Reads all of the data for the next packet into the appropriate buffers. The data slice and checksum slice members will be set to point to the user data and corresponding checksums. The header will be parsed and set.
    Throws:
      `IOException`

  - ### receiveNextPacket

    public void receiveNextPacket(InputStream in) throws IOException
    Throws:
      `IOException`
    See Also:
      - `receiveNextPacket(ReadableByteChannel)`

  - ### mirrorPacketTo

    public void mirrorPacketTo(DataOutputStream mirrorOut) throws IOException
    Rewrite the last-read packet on the wire to the given output stream.
    Throws:
      `IOException`

  - ### close

    public void close()
    Specified by:
      `close` in interface `AutoCloseable`
    Specified by:
      `close` in interface `Closeable`

  - ### finalize

    protected void finalize() throws Throwable
    Overrides:
      `finalize` in class `Object`
    Throws:
      `Throwable`