Package anbxj

# Class Channel_Abstraction

java.lang.Object
anbxj.Channel_Abstraction

Direct Known Subclasses:
  `Channel_Client`, `Channel_Server`

public abstract class Channel_Abstraction extends Object
Channel Abstraction: a class abstracting TCP/IP channel

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected Channel_Properties`
  `cp`
  Properties specific to the channel.

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Channel_Abstraction(Channel_Properties cp)`
  Constructor for Channel Abstraction.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `protected void`
  `checkPort()`
  Checks if the provided port is within the valid range.
  `void`
  `Close()`
  Close channel streams
  `Channel_Roles`
  `getChannelRole()`
  Gets the role of the channel.
  `void`
  `Open()`
  Opens the channel, by invoking the checkPort method.
  `protected void`
  `OpenStreams(Socket s)`
  Opens input and output streams for the specified socket.
  `Object`
  `Receive()`
  Receives an object from the input stream.
  `<T> T`
  `Receive(Class<?> type, List<Class<?>> safeClasses, long maxObjects, long maxBytes)`
  Receives an object of a specified type with additional safety checks.
  `static <T> T`
  `safeReadObject(Class<?> type, List<Class<?>> safeClasses, long maxObjects, long maxBytes, InputStream in)`
  A method to replace the unsafe ObjectInputStream.readObject() method built into Java.
  `void`
  `Send(Object obj)`
  Sends an object through the output stream.

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

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

- ## Field Details

  - ### cp

    protected Channel_Properties cp
    Properties specific to the channel.

- ## Constructor Details

  - ### Channel_Abstraction

    public Channel_Abstraction(Channel_Properties cp)
    Constructor for Channel Abstraction.
    Parameters:
      `cp` - Channel properties for the abstraction.

- ## Method Details

  - ### Close

    public void Close()
    Close channel streams

  - ### getChannelRole

    public Channel_Roles getChannelRole()
    Gets the role of the channel.
    Returns:
      Channel role.

  - ### checkPort

    protected void checkPort()
    Checks if the provided port is within the valid range.

  - ### Open

    public void Open()
    Opens the channel, by invoking the checkPort method.

  - ### OpenStreams

    protected void OpenStreams(Socket s)
    Opens input and output streams for the specified socket.
    Parameters:
      `s` - Socket for which to open streams.

  - ### Receive

    public Object Receive()
    Receives an object from the input stream.
    Returns:
      Received object.

  - ### Receive

    public <T> T Receive(Class<?> type, List<Class<?>> safeClasses, long maxObjects, long maxBytes)
    Receives an object of a specified type with additional safety checks.
    Type Parameters:
      `T` - Parametric type.
    Parameters:
      `type` - Class representing the object type expected to be returned.
      `safeClasses` - List of Classes allowed in the serialized object being read.
      `maxObjects` - Maximum number of objects allowed inside the serialized object being read.
      `maxBytes` - Maximum number of bytes allowed to be read from the InputStream.
    Returns:
      Received object of the specified type.

  - ### safeReadObject

    public static <T> T safeReadObject(Class<?> type, List<Class<?>> safeClasses, long maxObjects, long maxBytes, InputStream in) throws IOException, ClassNotFoundException
    A method to replace the unsafe ObjectInputStream.readObject() method built into Java. This method checks to be sure the classes referenced are safe, the number of objects is limited to something sane, and the number of bytes is limited to a reasonable number. The returned Object is also cast to the specified type.
    Type Parameters:
      `T` - Parametric type
    Parameters:
      `type` - Class representing the object type expected to be returned
      `safeClasses` - List of Classes allowed in serialized object being read
      `maxObjects` - long representing the maximum number of objects allowed inside the serialized object being read
      `maxBytes` - long representing the maximum number of bytes allowed to be read from the InputStream
      `in` - InputStream containing an untrusted serialized object
    Returns:
      Object read from the stream (cast to the Class of the type parameter)
    Throws:
      `IOException` - I/O error exception
      `ClassNotFoundException` - Class not found exception

  - ### Send

    public void Send(Object obj)
    Sends an object through the output stream.
    Parameters:
      `obj` - Object to be sent.