Package org.ghost4j
Class Ghostscript
- java.lang.Object
-
- org.ghost4j.Ghostscript
-
public class Ghostscript extends java.lang.Object
Class representing the Ghostscript interpreter.
-
-
Field Summary
Fields Modifier and Type Field Description private static DisplayCallback
displayCallback
Display callback used to handle display.private static DisplayData
displayData
Stores display data when working with display callback.private static Ghostscript
instance
Holds singleton instance.private static GhostscriptLibrary.display_callback_s
nativeDisplayCallback
Holds the native display callback.private static GhostscriptLibrary.gs_main_instance.ByReference
nativeInstanceByRef
Holds Ghostscript interpreter native instance (C pointer).static java.lang.String
PROPERTY_NAME_ENCODING
Name of the system property used to set the encoding to use for stdin.private static java.io.OutputStream
stdErr
Error output stream.private static java.io.InputStream
stdIn
Standard input stream.private static java.io.OutputStream
stdOut
Standard output stream.
-
Constructor Summary
Constructors Modifier Constructor Description private
Ghostscript()
Private constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private GhostscriptLibrary.display_callback_s
buildNativeDisplayCallback(DisplayCallback displayCallback)
Builds a native display callback from a DisplayCallback object.static void
deleteInstance()
Deletes the singleton instance of the Ghostscript object.void
exit()
Exits Ghostscript interpreter.DisplayCallback
getDisplayCallback()
Gets the display callback set on the Ghostscript interpreter (may be null if not set).private DisplayData
getDisplayData()
static Ghostscript
getInstance()
Singleton access method.private GhostscriptLibrary.gs_main_instance.ByReference
getNativeInstanceByRef()
Singleton factory method for getting a Ghostscript,interpreter instance.static GhostscriptRevision
getRevision()
Gets Ghostscript revision data.java.io.OutputStream
getStdErr()
Gets the error output stream of the Ghostscript interpreter (may be null if not set).java.io.InputStream
getStdIn()
Gets the standard input stream of the Ghostscript interpreter (may be null if not set).java.io.OutputStream
getStdOut()
Gets the standard output stream of the Ghostscript interpreter (may be null if not set).void
initialize(java.lang.String[] args)
Initializes Ghostscript interpreter.void
runFile(java.lang.String fileName)
Sends file Ghostscript interpreter.void
runString(java.lang.String string)
Sends command string to Ghostscript interpreter.void
setDisplayCallback(DisplayCallback displayCallback)
Sets a display callback for the Ghostscript interpreter.void
setStdErr(java.io.OutputStream stdErr)
Sets the error output stream of the Ghostscript interpreter.void
setStdIn(java.io.InputStream stdIn)
Sets the standard input stream of the Ghostscript interpreter.void
setStdOut(java.io.OutputStream stdOut)
Sets the standard output stream of the Ghostscript interpreter.
-
-
-
Field Detail
-
PROPERTY_NAME_ENCODING
public static final java.lang.String PROPERTY_NAME_ENCODING
Name of the system property used to set the encoding to use for stdin.- See Also:
- Constant Field Values
-
nativeInstanceByRef
private static GhostscriptLibrary.gs_main_instance.ByReference nativeInstanceByRef
Holds Ghostscript interpreter native instance (C pointer).
-
instance
private static Ghostscript instance
Holds singleton instance.
-
stdIn
private static java.io.InputStream stdIn
Standard input stream.
-
stdOut
private static java.io.OutputStream stdOut
Standard output stream.
-
stdErr
private static java.io.OutputStream stdErr
Error output stream.
-
displayCallback
private static DisplayCallback displayCallback
Display callback used to handle display.
-
displayData
private static DisplayData displayData
Stores display data when working with display callback.
-
nativeDisplayCallback
private static GhostscriptLibrary.display_callback_s nativeDisplayCallback
Holds the native display callback.
-
-
Method Detail
-
getInstance
public static Ghostscript getInstance()
Singleton access method.- Returns:
- The singleton instance.
-
getDisplayCallback
public DisplayCallback getDisplayCallback()
Gets the display callback set on the Ghostscript interpreter (may be null if not set).- Returns:
- The DisplayCallback or null
-
setDisplayCallback
public void setDisplayCallback(DisplayCallback displayCallback)
Sets a display callback for the Ghostscript interpreter.- Parameters:
displayCallback
- DisplayCallback object
-
getStdErr
public java.io.OutputStream getStdErr()
Gets the error output stream of the Ghostscript interpreter (may be null if not set).- Returns:
- The OutputStream or null
-
setStdErr
public void setStdErr(java.io.OutputStream stdErr)
Sets the error output stream of the Ghostscript interpreter.- Parameters:
stdErr
- OutputStream object
-
getStdOut
public java.io.OutputStream getStdOut()
Gets the standard output stream of the Ghostscript interpreter (may be null if not set).- Returns:
- The OutputStream or null
-
setStdOut
public void setStdOut(java.io.OutputStream stdOut)
Sets the standard output stream of the Ghostscript interpreter.- Parameters:
stdOut
- OutputStream object
-
getStdIn
public java.io.InputStream getStdIn()
Gets the standard input stream of the Ghostscript interpreter (may be null if not set).- Returns:
- The InputStream or null
-
setStdIn
public void setStdIn(java.io.InputStream stdIn)
Sets the standard input stream of the Ghostscript interpreter.- Parameters:
stdIn
- InputStream object
-
getNativeInstanceByRef
private GhostscriptLibrary.gs_main_instance.ByReference getNativeInstanceByRef() throws GhostscriptException
Singleton factory method for getting a Ghostscript,interpreter instance. Only called from class itself.- Returns:
- Ghostscript instance.
- Throws:
GhostscriptException
-
getDisplayData
private DisplayData getDisplayData()
-
getRevision
public static GhostscriptRevision getRevision()
Gets Ghostscript revision data.- Returns:
- Revision data.
-
initialize
public void initialize(java.lang.String[] args) throws GhostscriptException
Initializes Ghostscript interpreter.- Parameters:
args
- Interpreter parameters. Use the same as Ghostscript command line arguments.- Throws:
GhostscriptException
-
buildNativeDisplayCallback
private GhostscriptLibrary.display_callback_s buildNativeDisplayCallback(DisplayCallback displayCallback) throws GhostscriptException
Builds a native display callback from a DisplayCallback object.- Parameters:
displayCallback
- DisplayCallback to use.- Returns:
- The created native display callback.
- Throws:
GhostscriptException
-
exit
public void exit() throws GhostscriptException
Exits Ghostscript interpreter. Must be called after initialize.- Throws:
GhostscriptException
-
runString
public void runString(java.lang.String string) throws GhostscriptException
Sends command string to Ghostscript interpreter. Must be called after initialize method.- Parameters:
string
- Command string- Throws:
GhostscriptException
-
runFile
public void runFile(java.lang.String fileName) throws GhostscriptException
Sends file Ghostscript interpreter. Must be called after initialize method.- Parameters:
fileName
- File name- Throws:
GhostscriptException
-
deleteInstance
public static void deleteInstance() throws GhostscriptException
Deletes the singleton instance of the Ghostscript object. This ensures that the native Ghostscrit interpreter instance is deleted. This method must be called if Ghostscript is not used anymore or maybe reinitialized.- Throws:
GhostscriptException
-
-