Package ai.sklearn4j.core.packaging
Class BinaryModelPackage
- java.lang.Object
-
- ai.sklearn4j.core.packaging.BinaryModelPackage
-
public class BinaryModelPackage extends Object
The python package (sklearn4x) implements a class named BinaryBuffer that saves the python objects in a binary format. BinaryModelPackage is its counterpart to load these files (or stream) in other languages.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancanRead()Checks if there is still available content in the input stream.static BinaryModelPackagefromFile(String path)Creates a new BinaryModelPackage that reads from a given file.static BinaryModelPackagefromStream(InputStream stream)Creates a new BinaryModelPackage that reads from a given stream.bytereadByte()Reads a byte from the stream.Map<String,Object>readDictionary()Reads a dictionary from the stream.doublereadDouble()Reads a 64-bits floating point value from the stream.floatreadFloat()Reads a 32-bits floating point value from the stream.intreadInteger()Reads a 32-bits integer from the stream.List<Object>readList()Reads a list from the stream.longreadLongInteger()Reads a 64-bits integer from the stream.NumpyArrayreadNumpyArray()Read a multidimensional numpy array from the stream.shortreadShort()Reads a 16-bits integer from the stream.StringreadString()Reads a string with UTF-8 encoding from stream.String[]readStringArray()Reads an array of string from the stream.
-
-
-
Method Detail
-
fromFile
public static BinaryModelPackage fromFile(String path)
Creates a new BinaryModelPackage that reads from a given file.- Parameters:
path- Path to the file to be read.- Returns:
- A BinaryModelPackage instance to read the package file.
-
fromStream
public static BinaryModelPackage fromStream(InputStream stream)
Creates a new BinaryModelPackage that reads from a given stream. This method is useful to load the files from a custom-made package or an encrypted one.- Parameters:
stream- The input stream that should be loaded. It is recommended to use a buffered stream.- Returns:
- A BinaryModelPackage instance to read the package stream.
-
readByte
public byte readByte()
Reads a byte from the stream.- Returns:
- A byte value stored in the stream.
-
readShort
public short readShort()
Reads a 16-bits integer from the stream. The values are stored in little endian formats.- Returns:
- A short value stored in the stream.
-
readInteger
public int readInteger()
Reads a 32-bits integer from the stream. The values are stored in little endian formats.- Returns:
- An integer value stored in the stream.
-
readLongInteger
public long readLongInteger()
Reads a 64-bits integer from the stream. The values are stored in little endian formats.- Returns:
- An integer value stored in the stream.
-
readFloat
public float readFloat()
Reads a 32-bits floating point value from the stream. The values are stored in IEE 754 and little endian formats.- Returns:
- A float value stored in the stream.
-
readDouble
public double readDouble()
Reads a 64-bits floating point value from the stream. The values are stored in IEE 754 and little endian formats.- Returns:
- A double value stored in the stream.
-
readString
public String readString()
Reads a string with UTF-8 encoding from stream.- Returns:
- The string stored in the stream, or null if it has no value.
-
readNumpyArray
public NumpyArray readNumpyArray()
Read a multidimensional numpy array from the stream.- Returns:
- The numpy array stored in the stream, or null if it has no value.
-
readList
public List<Object> readList()
Reads a list from the stream.- Returns:
- The list stored in the stream, or null if it has no value.
-
readDictionary
public Map<String,Object> readDictionary()
Reads a dictionary from the stream.- Returns:
- The dictionary stored in the stream, or null if it has no value.
-
readStringArray
public String[] readStringArray()
Reads an array of string from the stream.- Returns:
- The String[] stored in the stream, or null if it has no value.
-
canRead
public boolean canRead()
Checks if there is still available content in the input stream.- Returns:
- A boolean indicating if the stream still has content or not.
-
-