FileDocCategorySizeDatePackage
NewlineOutputStream.javaAPI DocGlassfish v2 API3012Mon Oct 17 14:54:10 BST 2005None

NewlineOutputStream

public class NewlineOutputStream extends FilterOutputStream
Convert the various newline conventions to the local platform's newline convention.

This stream can be used with the Message.writeTo method to generate a message that uses the local plaform's line terminator for the purpose of (e.g.) saving the message to a local file.

Fields Summary
private int
lastb
private static byte[]
newline
Constructors Summary
public NewlineOutputStream(OutputStream os)


       
	super(os);
	if (newline == null) {
	    String s = System.getProperty("line.separator");
	    if (s == null || s.length() <= 0)
		s = "\n";
	    newline = new byte[s.length()];
	    s.getBytes(0, s.length(), newline, 0);
	}
    
Methods Summary
public voidwrite(int b)

	if (b == '\r") {
	    out.write(newline);
	} else if (b == '\n") {
	    if (lastb != '\r")
		out.write(newline);
	} else {
	    out.write(b);
	}
	lastb = b;
    
public voidwrite(byte[] b)

	write(b, 0, b.length);
    
public voidwrite(byte[] b, int off, int len)

	for (int i = 0 ; i < len ; i++) {
	    write(b[off + i]);
	}