FormatCode Code Formatter is based on serveral powerful syntax parser engines
so you can exactly control the appearance of your source code. Here is the code formatting demo of
FormatCode Java Code Formatter to prove the ability of code formatting
functions of FormatCode:
package ninja2.core.io_core.nbio;import java.io.*;/**
* Package-internal class implementing NonblockingOutputStream for
* nonblocking sockets. */class NonblockingSocketOutputStream extends
NonblockingOutputStream{private NBIOFileDescriptor fd;private boolean eof;
private NonblockingSocketImpl impl;private byte temp[]=new byte[1];private
static final int SKIPBUFLEN=4096;
private native int nbSocketWrite
(byte b[],int off,int len)throws IOException;NonblockingSocketOutputStream(
NonblockingSocketImpl impl){fd=impl.getFileDescriptor();this.impl=impl;}/**
* Perform a <b>blocking</b> write of one byte to this output stream.
* Throws an EOFException if the end of stream has been reached.
* Use nbWrite() to perform a non-blocking write of one byte. */public
void write(int b)throws IOException{if(eof)throw new EOFException("EOF on "+
toString());int n;temp[0]=(byte)b;while((n=nbSocketWrite(temp,0,1))==0);if(n<0){eof=true;throw new EOFException(
"EOF on "+toString());}}/**
* Perform a blocking write of <code>b.length</code> bytes
* to the underlying stream. Use nbWrite() to perform a nonblocking
* write. * */public void write(byte b[])throws IOException{if(eof)throw
new EOFException("EOF on "+toString());int n,count=0;while(count<b.length){n=
nbSocketWrite(b,count,(b.length-count));if(n<0){eof=true;throw new EOFException
("EOF on "+toString());}count+=n;}}/**
* Perform a blocking write of <code>len</code> bytes to the
* underlying stream from the byte array <code>b</code> starting at
* offset <code>off</code>. */public void write(byte b[],int off,int len)
throws IOException{if(eof)throw new EOFException("EOF on "+toString());int n,
count=0;while(count<len){n=nbSocketWrite(b,count+off,(len-count));if(n<0){eof=
true;throw new EOFException("EOF on "+toString());}count+=n;}}/**
* Perform a non-blocking write of one byte to this output stream.
* Returns 1 if the data was written or 0 if it could not be.
* Throws an EOFException if the end of the stream has been reached.
* Use write() to perform a blocking write of one byte. */public int
nbWrite(byte b)throws IOException{if(eof)throw new EOFException("EOF on "+
toString());temp[0]=(byte)b;int n=nbSocketWrite(temp,0,1);if(n<0){eof=true;
throw new EOFException("EOF on "+toString());}return n;}/**
* Perform a nonblocking write of up to <code>b.length</code> bytes
* to the underlying stream. Returns the number of bytes written, or
* 0 if nothing was written. Use write() to perform a blocking * write.
*/public int nbWrite(byte b[])throws IOException{if(eof)throw new
EOFException("EOF on "+toString());int n=nbSocketWrite(b,0,b.length);if(n<0){
eof=true;throw new EOFException("EOF on "+toString());}return n;}/**
* Perform a nonblocking write of up to <code>len</code> bytes
* to the underlying stream starting at offset <code>off</code>.
* Returns the number of bytes written, or 0 if nothing was written.
* Use write() to perform a blocking write. */public int nbWrite(byte b[],
int off,int len)throws IOException{if(eof)throw new EOFException("EOF on "+
toString());int n=nbSocketWrite(b,off,len);if(n<0){eof=true;throw new
EOFException("EOF on "+toString());}return n;}public void flush(){}public void
close()throws IOException{impl.close();}}
package ninja2.core.io_core.nbio;
import java.io.*;
/**
* Package-internal class implementing NonblockingOutputStream for
* nonblocking sockets.
*/
class NonblockingSocketOutputStream extends NonblockingOutputStream
{
private NBIOFileDescriptor fd;
private boolean eof;
private NonblockingSocketImpl impl;
private byte temp[] = new byte[1];
private static final int SKIPBUFLEN = 4096;
private native int nbSocketWrite(byte b[], int off, int len) throws
IOException;
NonblockingSocketOutputStream(NonblockingSocketImpl impl)
{
fd = impl.getFileDescriptor();
this.impl = impl;
}
/**
* Perform a <b>blocking</b> write of one byte to this output stream.
* Throws an EOFException if the end of stream has been reached.
* Use nbWrite() to perform a non-blocking write of one byte.
*/
public void write(int b) throws IOException
{
if (eof)
throw new EOFException("EOF on " + toString());
int n;
temp[0] = (byte)b;
while ((n = nbSocketWrite(temp, 0, 1)) == 0);
if (n < 0)
{
eof = true;
throw new EOFException("EOF on " + toString());
}
}
/**
* Perform a blocking write of <code>b.length</code> bytes
* to the underlying stream. Use nbWrite() to perform a nonblocking
* write.
*
*/
public void write(byte b[]) throws IOException
{
if (eof)
throw new EOFException("EOF on " + toString());
int n, count = 0;
while (count < b.length)
{
n = nbSocketWrite(b, count, (b.length - count));
if (n < 0)
{
eof = true;
throw new EOFException("EOF on " + toString());
}
count += n;
}
}
/**
* Perform a blocking write of <code>len</code> bytes to the
* underlying stream from the byte array <code>b</code> starting at
* offset <code>off</code>.
*/
public void write(byte b[], int off, int len) throws IOException
{
if (eof)
throw new EOFException("EOF on " + toString());
int n, count = 0;
while (count < len)
{
n = nbSocketWrite(b, count + off, (len - count));
if (n < 0)
{
eof = true;
throw new EOFException("EOF on " + toString());
}
count += n;
}
}
/**
* Perform a non-blocking write of one byte to this output stream.
* Returns 1 if the data was written or 0 if it could not be.
* Throws an EOFException if the end of the stream has been reached.
* Use write() to perform a blocking write of one byte.
*/
public int nbWrite(byte b) throws IOException
{
if (eof)
throw new EOFException("EOF on " + toString());
temp[0] = (byte)b;
int n = nbSocketWrite(temp, 0, 1);
if (n < 0)
{
eof = true;
throw new EOFException("EOF on " + toString());
}
return n;
}
/**
* Perform a nonblocking write of up to <code>b.length</code> bytes
* to the underlying stream. Returns the number of bytes written, or
* 0 if nothing was written. Use write() to perform a blocking
* write.
*/
public int nbWrite(byte b[]) throws IOException
{
if (eof)
throw new EOFException("EOF on " + toString());
int n = nbSocketWrite(b, 0, b.length);
if (n < 0)
{
eof = true;
throw new EOFException("EOF on " + toString());
}
return n;
}
/**
* Perform a nonblocking write of up to <code>len</code> bytes
* to the underlying stream starting at offset <code>off</code>.
* Returns the number of bytes written, or 0 if nothing was written.
* Use write() to perform a blocking write.
*/
public int nbWrite(byte b[], int off, int len) throws IOException
{
if (eof)
throw new EOFException("EOF on " + toString());
int n = nbSocketWrite(b, off, len);
if (n < 0)
{
eof = true;
throw new EOFException("EOF on " + toString());
}
return n;
}
public void flush(){}
public void close()throws IOException
{
impl.close();
}
}
Click here to preview the Java Code Formatting Demo 2.
With FormatCode Java Code Formatters, you can format and transform any foreign Java source code to meet your preferred coding style or any common code convention in several seconds!
|