Interface IonDatagram

All Superinterfaces:
Cloneable, Collection<IonValue>, IonContainer, IonSequence, IonValue, Iterable<IonValue>, List<IonValue>, SequencedCollection<IonValue>
All Known Subinterfaces:
_Private_IonDatagram

public interface IonDatagram extends IonSequence
A datagram is a "top-level" container of Ion values, and the granularity of binary encoding Ion content.

WARNING: This interface should not be implemented or extended by code outside of this library. Some inherited methods are not yet implemented or are unsupported for datagrams.

Along with the normal user values, datagrams contain system values, notably the symbol table(s) used to atomize all symbols. Most uses of a datagram will not see system values, but applications that need visibility into that data can use the system*() methods.

  • Method Details

    • add

      void add(int index, IonValue element) throws ContainedValueException, NullPointerException
      This inherited method is not yet supported by datagrams.

      Vote for issue amazon-ion/ion-java/issues/48 if you need this.

      Specified by:
      add in interface IonSequence
      Specified by:
      add in interface List<IonValue>
      Parameters:
      element - is the element to be appended to this sequence.
      Throws:
      UnsupportedOperationException - at every call.
      ContainedValueException - if child is already part of a container.
      NullPointerException - if child is null.
      See Also:
    • add

      This inherited method is not yet supported by datagrams.

      Vote for issue amazon-ion/ion-java/issues/48 if you need this.

      Specified by:
      add in interface IonSequence
      Throws:
      UnsupportedOperationException - at every call.
      ContainedValueException
      NullPointerException
      See Also:
    • addAll

      boolean addAll(int index, Collection<? extends IonValue> c)
      This inherited method is not yet supported by datagrams.

      Vote for issue amazon-ion/ion-java/issues/47 if you need this.

      Specified by:
      addAll in interface IonSequence
      Specified by:
      addAll in interface List<IonValue>
      Parameters:
      index - index at which to insert first element from the specified collection.
      c - elements to be inserted into this sequence.
      Returns:
      true if this sequence changed as a result of the call.
      Throws:
      UnsupportedOperationException - at every call.
      See Also:
    • set

      IonValue set(int index, IonValue element)
      This inherited method is not yet supported by datagrams.

      Vote for issue amazon-ion/ion-java/issues/50 if you need this.

      Specified by:
      set in interface IonSequence
      Specified by:
      set in interface List<IonValue>
      Parameters:
      index - index of the element to replace.
      element - element to be stored at the specified position.
      Returns:
      the element previously at the specified index.
      Throws:
      UnsupportedOperationException - at every call.
      See Also:
    • isNullValue

      boolean isNullValue()
      Returns false at every call, since datagrams cannot be null.
      Specified by:
      isNullValue in interface IonValue
      Returns:
      false
    • getContainer

      IonContainer getContainer()
      Gets the container of this value, or null if this is not part of one.

      Datagrams always return null from this method, since by definition they have no container.

      Specified by:
      getContainer in interface IonValue
    • size

      int size()
      Gets the number of elements in the datagram, not counting system elements.
      Specified by:
      size in interface Collection<IonValue>
      Specified by:
      size in interface IonContainer
      Specified by:
      size in interface List<IonValue>
      Returns:
      the number of elements, zero if this.isNullValue().
    • systemSize

      int systemSize()
      Gets the number of elements in the datagram, including system elements such as version markers and symbol tables. Unless your application needs to be aware of such low-level details, you almost certainly want to use size() instead.
      See Also:
    • get

      IonValue get(int index) throws IndexOutOfBoundsException
      Gets a selected non-system element from this datagram.
      Specified by:
      get in interface IonSequence
      Specified by:
      get in interface List<IonValue>
      Parameters:
      index - must be less than size().
      Returns:
      the selected element; not null.
      Throws:
      IndexOutOfBoundsException - if the index is bad.
    • systemGet

      IonValue systemGet(int index) throws IndexOutOfBoundsException
      Gets a selected element from this datagram, potentially getting a hidden system element (such as a symbol table). Unless your application needs to be aware of such low-level details, you almost certainly want to use get(int) instead.
      Parameters:
      index - must be less than systemSize().
      Returns:
      the selected element; not null.
      Throws:
      IndexOutOfBoundsException - if the index is bad.
      See Also:
    • iterator

      Iterator<IonValue> iterator()
      Creates an iterator providing the (direct) elements of this datagram. Elements will be returned in order of their appearance in the Ion representation.

      This iterator returns only user values, ignoring symbol tables and other system values. It does not support the Iterator.remove() operation.

      Specified by:
      iterator in interface Collection<IonValue>
      Specified by:
      iterator in interface IonContainer
      Specified by:
      iterator in interface Iterable<IonValue>
      Specified by:
      iterator in interface List<IonValue>
      Returns:
      a new iterator, not null.
      See Also:
    • systemIterator

      ListIterator<IonValue> systemIterator()
      Iterate all values in the datagram, including the otherwise-hidden system values such as version markers and symbol tables. Unless your application needs to be aware of such low-level details, you almost certainly want to use iterator() instead.

      This iterator does not support the modification methods Iterator.remove(), ListIterator.add(Object), or ListIterator.set(Object).

      Returns:
      not null.
      See Also:
    • byteSize

      int byteSize() throws IonException
      Gets the number of bytes used to encode this datagram. As a side effect, this method encodes the entire datagram into Ion binary format.
      Returns:
      the number of bytes in the binary encoding of this datagram.
      Throws:
      IonException - if there's an error encoding the data.
    • toBytes

      @Deprecated byte[] toBytes() throws IonException
      Deprecated.
      Use getBytes() instead, which is renamed for consistency with other interfaces.
      Copies the binary-encoded form of this datagram into a new byte array.
      Returns:
      a new, non-empty byte array containing the encoded datagram.
      Throws:
      IonException - if there's an error encoding the data.
    • getBytes

      byte[] getBytes() throws IonException
      Copies the binary-encoded form of this datagram into a new byte array.
      Returns:
      a new, non-empty byte array containing the encoded datagram.
      Throws:
      IonException - if there's an error encoding the data.
    • getBytes

      @Deprecated int getBytes(byte[] dst) throws IonException
      Deprecated.
      Copies the binary-encoded form of this datagram into a given array.

      The given array must be large enough to contain all the bytes of this datagram.

      An invocation of this method of the form dg.get(a) behaves in exactly the same way as the invocation:

          dg.get(a, 0)
      
      Parameters:
      dst - the array into which bytes are to be written.
      Returns:
      the number of bytes copied into dst.
      Throws:
      IonException - if there's an error encoding the data.
      IndexOutOfBoundsException - if dst.length is smaller than the result of byteSize().
      See Also:
    • getBytes

      @Deprecated int getBytes(byte[] dst, int offset) throws IonException
      Deprecated.
      Copies the binary-encoded form of this datagram into a given sub-array.

      The given subarray must be large enough to contain all the bytes of this datagram.

      Parameters:
      dst - the array into which bytes are to be written.
      offset - the offset within the array of the first byte to be written; must be non-negative and no larger than dst.length
      Returns:
      the number of bytes copied into dst.
      Throws:
      IonException - if there's an error encoding the data.
      IndexOutOfBoundsException - if (dst.length - offset) is smaller than the result of byteSize().
    • getBytes

      int getBytes(OutputStream out) throws IOException, IonException
      Copies the binary-encoded form of this datagram to a specified stream.
      Parameters:
      out - the output stream to which to write the data.
      Returns:
      the number of bytes written.
      Throws:
      IonException - if there's an error encoding the data.
      IOException - if an error occurs writing the data to the stream.
    • getSymbolTable

      SymbolTable getSymbolTable()
      This inherited method is not supported by datagrams because there's no single symbol table used across the contents. Each value contained by the datagram may have its own symbol table.
      Specified by:
      getSymbolTable in interface IonValue
      Returns:
      nothing, always throws an exception.
      Throws:
      UnsupportedOperationException - at every call.
    • addTypeAnnotation

      void addTypeAnnotation(String annotation)
      This inherited method is not supported by datagrams.
      Specified by:
      addTypeAnnotation in interface IonValue
      Parameters:
      annotation - as a string value.
      Throws:
      UnsupportedOperationException - at every call.
    • makeNull

      void makeNull()
      This inherited method is not supported by datagrams.
      Specified by:
      makeNull in interface IonContainer
      Throws:
      UnsupportedOperationException - at every call.
    • clone

      Description copied from interface: IonValue
      Creates a copy of this value and all of its children. The cloned value may use the same shared symbol tables, but it will have an independent local symbol table if necessary. The cloned value will be modifiable regardless of whether this instance IonValue.isReadOnly().

      The cloned value will be created in the context of the same ValueFactory as this instance; if you want a copy using a different factory, then use ValueFactory.clone(IonValue) instead.

      Specified by:
      clone in interface IonContainer
      Specified by:
      clone in interface IonSequence
      Specified by:
      clone in interface IonValue
      Throws:
      UnknownSymbolException - if any part of this value has unknown text but known Sid for its field name, annotation or symbol.