# Class ModelSource

java.lang.Object
com.codename1.ai.inference.ModelSource

public final class ModelSource extends Object
Describes where an `InferenceSession` should obtain a `.tflite` model. Byte sources are defensively copied. File sources are especially useful with `ModelCache` because native ports can open the cached path without loading the full model into the Java heap.

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `static final int`
  `BYTES`
  `static final int`
  `FILE`
  `static final int`
  `RESOURCE`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static ModelSource`
  `bytes(byte[] value)`
  Creates an in-memory model source.
  `static ModelSource`
  `file(String path)`
  Creates a source for an existing private filesystem path.
  `byte[]`
  `getBytes()`
  `byte[]`
  `getBytesUnsafe()`
  Returns the internal model byte array without copying it.
  `int`
  `getKind()`
  `String`
  `getPath()`
  `static ModelSource`
  `resource(String path)`
  Creates a source for a model packaged in application resources.

  ### Methods inherited from class Object

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

- ## Field Details

  - ### BYTES

    public static final int BYTES
    See Also:
      - Constant Field Values

  - ### FILE

    public static final int FILE
    See Also:
      - Constant Field Values

  - ### RESOURCE

    public static final int RESOURCE
    See Also:
      - Constant Field Values

- ## Method Details

  - ### bytes

    public static ModelSource bytes(byte[] value)
    Creates an in-memory model source.
    Parameters:
      `value` - complete model bytes, copied by this method
    Returns:
      a byte-backed source

  - ### file

    public static ModelSource file(String path)
    Creates a source for an existing private filesystem path.
    Parameters:
      `path` - path understood by `FileSystemStorage`
    Returns:
      a file-backed source; the session never owns or deletes the file

  - ### resource

    public static ModelSource resource(String path)
    Creates a source for a model packaged in application resources.
    Parameters:
      `path` - absolute classpath-style resource path
    Returns:
      a resource-backed source

  - ### getKind

    public int getKind()
    Returns:
      `BYTES`, `FILE`, or `RESOURCE`

  - ### getBytes

    public byte[] getBytes()
    Returns:
      a defensive copy of model bytes, or `null` for non-byte sources

  - ### getBytesUnsafe

    public byte[] getBytesUnsafe()

    Returns the internal model byte array without copying it.

    This escape hatch is intended for native backend handoff and memory-sensitive applications. The returned array must be treated as read-only: modifying it changes the model source and violates this class's immutability contract. Prefer `getBytes()` unless the additional full-model copy is known to be unacceptable.

    Returns:
      internal model bytes, or `null` for non-byte sources

  - ### getPath

    public String getPath()
    Returns:
      the file/resource path, or `null` for a byte source