public class PrintableObject
extends java.lang.Object
-
Constructor Summary
Constructors Constructor Description PrintableObject(java.io.InputStream file, int width, int height)
Loads the object from a text file -
Method Summary
Modifier and Type Method Description int
getHeight()
height getterjava.lang.String[][]
getObject()
int
getWidth()
width getterstatic PrintableObject
load(java.lang.Object caller, java.lang.String filename, int width, int height)
static PrintableObject
load(java.lang.String filePath, int width, int height)
-
Constructor Details
-
PrintableObject
public PrintableObject(java.io.InputStream file, int width, int height) throws java.io.IOExceptionLoads the object from a text fileTo work properly, each object has to be divided in a String matrix; each element of the matrix contains a printable char and a special sequence (\033), followed by some parameters to color the char; the file must not contain '\' characters other than the ones used for the escape code: when parsing the file, all the backslashes are transcribed as '\003', and the "003" in the file is dumped, because it is not possible to read an escape code; 'm' characters are also forbidden, as they mark that the end of the color sequence. Note that the reset sequence is also stored in the matrix, so the caller has to take this into account.
In case those conditions are not satisfied, the method will not behave properly, but could end without throwing exceptions: in case the object size is bigger than the provided size, all chars outside the matrix will be ignored; if smaller, the elements of the matrix will be left to null.
For further information see ANSI colors- Parameters:
file
- the object file pathheight
- the expected matrix heightwidth
- the expected matrix width- Throws:
java.io.IOException
- if an I/O error occurs
-
-
Method Details
-
load
public static PrintableObject load(java.lang.Object caller, java.lang.String filename, int width, int height) throws java.io.IOException- Throws:
java.io.IOException
-
load
public static PrintableObject load(java.lang.String filePath, int width, int height) throws java.io.IOException- Throws:
java.io.IOException
-
getWidth
public int getWidth()width getterTakes in account the ANSI reset code
- Returns:
- the number of columns in the matrix
-
getHeight
public int getHeight()height getter- Returns:
- the object height
-
getObject
public java.lang.String[][] getObject()- Returns:
- the object, as a string matrix
-