Package javajs.util
Class OC
java.lang.Object
java.io.OutputStream
javajs.util.OC
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
,GenericOutputChannel
A generic output method. JmolOutputChannel can be used to:
add characters to a StringBuffer using fileName==null, append() and
toString()
add bytes utilizing ByteArrayOutputStream using writeBytes(),
writeByteAsInt(), append()*, and bytesAsArray() *append() can be used as long
as os==ByteArrayOutputStream or it is not used before one of the writeByte
methods.
output characters to a FileOutputStream using os==FileOutputStream,
asWriter==true, append(), and closeChannel()
output bytes to a FileOutputStream using os==FileOutputStream, writeBytes(),
writeByteAsInt(), append(), and closeChannel()
post characters or bytes to a remote server using fileName=="http://..." or
"https://...", writeBytes(), writeByteAsInt(), append(), and closeChannel()
send characters or bytes to a JavaScript function when JavaScript and (typeof
fileName == "function")
if fileName equals ";base64,", then the data are base64-encoded prior to
writing, and closeChannel() returns the data.
- Author:
- hansonr Bob Hanson hansonr@stolaf.edu 9/2013
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionwill go to string buffer if bw == null and os == nullvoid
cancel()
void
close()
Deprecated.int
getName()
getType()
boolean
isBase64()
boolean
static boolean
static boolean
void
reset()
void
setBigEndian
(boolean TF) setBytes
(byte[] b) setParams
(BytePoster bytePoster, String fileName, boolean asWriter, OutputStream os) Set up an output channel.void
byte[]
toString()
static int
urlTypeIndex
(String name) void
write
(byte[] buf, int i, int len) void
write
(int b) Deprecated.void
writeByteAsInt
(int b) void
writeFloat
(float x) void
writeInt
(int i) void
writeLong
(long b) void
writeShort
(short i) Methods inherited from class java.io.OutputStream
flush, nullOutputStream, write
-
Field Details
-
bigEndian
public boolean bigEndian -
urlPrefixes
-
URL_LOCAL
public static final int URL_LOCAL- See Also:
-
URL_CACHE
public static final int URL_CACHE- See Also:
-
-
Constructor Details
-
OC
public OC() -
OC
-
-
Method Details
-
setParams
Set up an output channel. String or byte data can be added without problem.- Parameters:
bytePoster
- a byte poster can take the output byte[] when closing and do something with themfileName
- TODO: It is possible that JavaScript will call this with a function name for fileNameasWriter
- string-basedos
- the desired target OutputStream - not the calling stream!- Returns:
- OC
-
isBigEndian
public boolean isBigEndian()- Specified by:
isBigEndian
in interfaceGenericOutputChannel
-
setBigEndian
public void setBigEndian(boolean TF) -
setBytes
-
getFileName
-
getName
-
getByteCount
public int getByteCount() -
setType
- Parameters:
type
- user-identified type (PNG, JPG, etc)
-
getType
-
append
will go to string buffer if bw == null and os == null- Parameters:
s
-- Returns:
- this, for chaining like a standard StringBuffer
-
reset
public void reset()- Specified by:
reset
in interfaceGenericOutputChannel
-
writeByteAsInt
public void writeByteAsInt(int b) - Specified by:
writeByteAsInt
in interfaceGenericOutputChannel
- Parameters:
b
-
-
write
public void write(byte[] buf, int i, int len) - Specified by:
write
in interfaceGenericOutputChannel
- Overrides:
write
in classOutputStream
-
writeShort
public void writeShort(short i) - Specified by:
writeShort
in interfaceGenericOutputChannel
-
writeLong
public void writeLong(long b) - Specified by:
writeLong
in interfaceGenericOutputChannel
-
write
Deprecated.Will break JavaScript if used.- Specified by:
write
in classOutputStream
- Parameters:
b
-
-
cancel
public void cancel() -
closeChannel
- Specified by:
closeChannel
in interfaceGenericOutputChannel
-
isBase64
public boolean isBase64() -
getBase64
-
toByteArray
public byte[] toByteArray() -
close
Deprecated.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
-
toString
-
isRemote
-
isLocal
-
urlTypeIndex
-
writeInt
public void writeInt(int i) - Specified by:
writeInt
in interfaceGenericOutputChannel
-
writeFloat
public void writeFloat(float x)
-