printstream.java
来自「纯java操作系统jnode,安装简单和操作简单的个人使用的Java操作系统」· Java 代码 · 共 574 行 · 第 1/2 页
JAVA
574 行
pw.print(d);
}
/*************************************************************************/
/**
* This method prints an array of characters to the stream. The actual
* value printed depends on the system default encoding.
*
* @param s The array of characters to print.
*/
public void
print(char[] s)
{
pw.print(s);
if (auto_flush)
for (int i = 0; i < s.length; i++)
if ((s[i] == '\r') || (s[i] == '\n'))
{
flush();
break;
}
}
/*************************************************************************/
/**
* This method prints a <code>String</code> to the stream. The actual
* value printed depends on the system default encoding.
*
* @param s The <code>String</code> to print.
*/
public void
print(String s)
{
pw.print(s);
if (auto_flush)
if ((s.indexOf('\r') != -1) || (s.indexOf('\n') != -1))
flush();
}
/*************************************************************************/
/**
* This method prints an <code>Object</code> to the stream. The actual
* value printed is determined by calling the <code>String.valueOf()</code>
* method.
*
* @param obj The <code>Object</code> to print.
*/
public void
print(Object obj)
{
// Don't call pw directly. Convert to String so we scan for newline
// characters on auto-flush;
print(String.valueOf(obj));
}
/*************************************************************************/
/**
* This method prints a line separator sequence to the stream. The value
* printed is determined by the system property <xmp>line.separator</xmp>
* and is not necessarily the Unix '\n' newline character.
*/
public void
println()
{
pw.println();
}
/*************************************************************************/
/**
* This methods prints a boolean value to the stream. <code>true</code>
* values are printed as "true" and <code>false</code> values are printed
* as "false".
* <p>
* This method prints a line termination sequence after printing the value.
*
* @param b The <code>boolean</code> value to print
*/
public void
println(boolean b)
{
pw.println(b);
}
/*************************************************************************/
/**
* This method prints a char to the stream. The actual value printed is
* determined by the character encoding in use.
* <p>
* This method prints a line termination sequence after printing the value.
*
* @param c The <code>char</code> value to be printed
*/
public void
println(char c)
{
pw.println(c);
}
/*************************************************************************/
/**
* This method prints an integer to the stream. The value printed is
* determined using the <code>String.valueOf()</code> method.
* <p>
* This method prints a line termination sequence after printing the value.
*
* @param i The <code>int</code> value to be printed
*/
public void
println(int i)
{
pw.println(i);
}
/*************************************************************************/
/**
* This method prints a long to the stream. The value printed is
* determined using the <code>String.valueOf()</code> method.
* <p>
* This method prints a line termination sequence after printing the value.
*
* @param l The <code>long</code> value to be printed
*/
public void
println(long l)
{
pw.println(l);
}
/*************************************************************************/
/**
* This method prints a float to the stream. The value printed is
* determined using the <code>String.valueOf()</code> method.
* <p>
* This method prints a line termination sequence after printing the value.
*
* @param f The <code>float</code> value to be printed
*/
public void
println(float f)
{
pw.println(f);
}
/*************************************************************************/
/**
* This method prints a double to the stream. The value printed is
* determined using the <code>String.valueOf()</code> method.
* <p>
* This method prints a line termination sequence after printing the value.
*
* @param d The <code>double</code> value to be printed
*/
public void
println(double d)
{
pw.println(d);
}
/*************************************************************************/
/**
* This method prints an array of characters to the stream. The actual
* value printed depends on the system default encoding.
* <p>
* This method prints a line termination sequence after printing the value.
*
* @param s The array of characters to print.
*/
public void
println(char[] s)
{
pw.println(s);
}
/*************************************************************************/
/**
* This method prints a <code>String</code> to the stream. The actual
* value printed depends on the system default encoding.
* <p>
* This method prints a line termination sequence after printing the value.
*
* @param s The <code>String</code> to print.
*/
public void
println(String s)
{
pw.println(s);
}
/*************************************************************************/
/**
* This method prints an <code>Object</code> to the stream. The actual
* value printed is determined by calling the <code>String.valueOf()</code>
* method.
* <p>
* This method prints a line termination sequence after printing the value.
*
* @param obj The <code>Object</code> to print.
*/
public void
println(Object obj)
{
pw.println(obj);
}
/*************************************************************************/
/**
* This method writes a byte of data to the stream. If auto-flush is
* enabled, printing a newline character will cause the stream to be
* flushed after the character is written.
*
* @param b The byte to be written
*/
public synchronized void
write(int b)
{
// Sigh, we actually have to implement this method. Flush first so that
// things get written in the right order.
flush();
try
{
out.write(b);
if (auto_flush)
if ((b == '\n') || (b == '\n'))
flush();
}
catch(IOException e)
{
error_occurred = true;
}
}
/*************************************************************************/
/**
* This method writes <code>len</code> bytes from the specified array
* starting at index <code>offset</code> into the array.
*
* @param buf The array of bytes to write
* @param offset The index into the array to start writing from
* @param len The number of bytes to write
*/
public synchronized void
write(byte[] buf, int offset, int len)
{
// We actually have to implement this method too. Flush first so that
// things get written in the right order.
flush();
try
{
out.write(buf, offset, len);
if (auto_flush)
for (int i = offset; i < len; i++)
if ((buf[i] == '\r') || (buf[i] == '\n'))
{
flush();
break;
}
}
catch(IOException e)
{
error_occurred = true;
}
}
} // class PrintStream
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?