# Class OC

java.lang.Object
java.io.OutputStream
javajs.util.OC

All Implemented Interfaces:
  `Closeable, Flushable, AutoCloseable, GenericOutputChannel`

public class OC extends OutputStream implements 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
Modifier and Type
Field
Description
`boolean`
`bigEndian`
`static final int`
`URL_CACHE`
`static final int`
`URL_LOCAL`
`static final String[]`
`urlPrefixes`

## Constructor Summary

Constructors
Constructor
Description
`OC()`
`OC(String fileName)`

## Method Summary

Modifier and Type
Method
Description
`OC`
`append(String s)`
will go to string buffer if bw == null and os == null
`void`
`cancel()`
`void`
`close()`
Deprecated.
`String`
`closeChannel()`
`String`
`getBase64()`
`int`
`getByteCount()`
`String`
`getFileName()`
`String`
`getName()`
`String`
`getType()`
`boolean`
`isBase64()`
`boolean`
`isBigEndian()`
`static boolean`
`isLocal(String fileName)`
`static boolean`
`isRemote(String fileName)`
`void`
`reset()`
`void`
`setBigEndian(boolean TF)`
`OC`
`setBytes(byte[] b)`
`OC`
`setParams(BytePoster bytePoster, String fileName, boolean asWriter, OutputStream os)`
Set up an output channel.
`void`
`setType(String type)`
`byte[]`
`toByteArray()`
`String`
`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 OutputStream

`flush, nullOutputStream, write`

### Methods inherited from class Object

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

## Field Details

### bigEndian

public boolean bigEndian

### urlPrefixes

public static final String[] urlPrefixes

### URL_LOCAL

public static final int URL_LOCAL

See Also:
  - Constant Field Values

### URL_CACHE

public static final int URL_CACHE

See Also:
  - Constant Field Values

## Constructor Details

### OC

public OC()

### OC

public OC(String fileName)

## Method Details

### setParams

public OC setParams(BytePoster bytePoster, String fileName, boolean asWriter, OutputStream os)
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 them
  `fileName` - TODO: It is possible that JavaScript will call this with a function name for fileName
  `asWriter` - string-based
  `os` - the desired target OutputStream - not the calling stream!
Returns:
  OC

### isBigEndian

public boolean isBigEndian()

Specified by:
  `isBigEndian` in interface `GenericOutputChannel`

### setBigEndian

public void setBigEndian(boolean TF)

### setBytes

public OC setBytes(byte[] b)

### getFileName

public String getFileName()

### getName

public String getName()

### getByteCount

public int getByteCount()

### setType

public void setType(String type)

Parameters:
  `type` - user-identified type (PNG, JPG, etc)

### getType

public String getType()

### append

public OC append(String s)
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 interface `GenericOutputChannel`

### writeByteAsInt

public void writeByteAsInt(int b)

Specified by:
  `writeByteAsInt` in interface `GenericOutputChannel`
Parameters:
  `b` -

### write

public void write(byte[] buf, int i, int len)

Specified by:
  `write` in interface `GenericOutputChannel`
Overrides:
  `write` in class `OutputStream`

### writeShort

public void writeShort(short i)

Specified by:
  `writeShort` in interface `GenericOutputChannel`

### writeLong

public void writeLong(long b)

Specified by:
  `writeLong` in interface `GenericOutputChannel`

### write

@Deprecated public void write(int b)
Deprecated.
Will break JavaScript if used.

Specified by:
  `write` in class `OutputStream`
Parameters:
  `b` -

### cancel

public void cancel()

### closeChannel

public String closeChannel()

Specified by:
  `closeChannel` in interface `GenericOutputChannel`

### isBase64

public boolean isBase64()

### getBase64

public String getBase64()

### toByteArray

public byte[] toByteArray()

### close

@Deprecated public void close()
Deprecated.

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`
Overrides:
  `close` in class `OutputStream`

### toString

public String toString()

Overrides:
  `toString` in class `Object`

### isRemote

public static boolean isRemote(String fileName)

### isLocal

public static boolean isLocal(String fileName)

### urlTypeIndex

public static int urlTypeIndex(String name)

### writeInt

public void writeInt(int i)

Specified by:
  `writeInt` in interface `GenericOutputChannel`

### writeFloat

public void writeFloat(float x)