Java Code Examples for java.io.InputStreamReader.ready()

The following are Jave code examples for showing how to use ready() of the java.io.InputStreamReader class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: VerveineC-Cpp   File: IncludeConfs.java   View Source Code Vote up 6 votes
public static void main(String[] args) {

        try {
        	/*
        	 * trying to automatically configure include path by running cpp -v
        	 */
            Process p = Runtime.getRuntime().exec("cpp -v");
            
            InputStreamReader stdInput = new //BufferedReader(new 
                 InputStreamReader(p.getInputStream()) ; //);

            // read the output from the command
            System.out.println("Here is the standard output of the command:\n");
            while (stdInput.ready() ) {
                System.out.print(stdInput.read());
            }
        }
        catch (IOException e) {
        	System.out.println("exception happened - here's what I know: ");
        	e.printStackTrace();
        	System.exit(-1);
        }
	}
 
Example 2
Project: FJ-VDMJ   File: CommandLine.java   View Source Code Vote up 5 votes
protected String promptLine() throws IOException
{
	if (startLine != null)
	{
		String line = startLine.trim();
		println("> " + startLine);
		startLine = null;
		return line;
	}

	StringBuilder lineTyped = new StringBuilder();
	InputStreamReader console = new InputStreamReader(System.in);
	boolean prompted = false;

	if (messages.isEmpty())
	{
		print(getPrompt());		// Otherwise nothing appears when quiet!
		prompted = true;
	}

	while (true)
	{
		if (!messages.isEmpty())
		{
			if (prompted)
			{
				print("\n");
			}

			while (!messages.isEmpty())
			{
				String msg = messages.poll();

				if (msg.length() > 0)
				{
					println(msg.toString());
				}
			}

			print(getPrompt());
			print(lineTyped.toString());
			prompted = true;
		}

		while (console.ready())
		{
			int c = console.read();

			if (c == '\r')
			{
				continue;
			}
			else if (c == '\n' || c == -1)
			{
				return lineTyped.toString().trim();
			}
			else
			{
				lineTyped.append((char)c);
			}
		}

		Utils.milliPause(10);
	}
}
 
Example 3
Project: JavaCommon   File: FileIODemo.java   View Source Code Vote up 4 votes
public static void fileStream() {
	try {
		File f = new File("mkdirs/test/filetest.txt");
		FileOutputStream fop = new FileOutputStream(f);
		// 构建FileOutputStream对象,文件不存在会自动新建

		OutputStreamWriter writer = new OutputStreamWriter(fop, "gbk");
		// 构建OutputStreamWriter对象,参数可以指定编码,默认为操作系统默认编码,windows上是gbk

		writer.append("中文输入");
		// 写入到缓冲区

		writer.append("\r\n");
		// 换行

		writer.append("English");
		// 刷新缓存冲,写入到文件,如果下面已经没有写入的内容了,直接close也会写入

		writer.close();
		// 关闭写入流,同时会把缓冲区内容写入文件,所以上面的注释掉

		fop.close();
		// 关闭输出流,释放系统资源

		FileInputStream fip = new FileInputStream(f);
		// 构建FileInputStream对象

		InputStreamReader reader = new InputStreamReader(fip, "UTF-8");
		// 构建InputStreamReader对象,编码与写入相同

		StringBuffer sb = new StringBuffer();
		while (reader.ready()) {
			sb.append((char) reader.read());
			// 转成char加到StringBuffer对象中
		}
		System.out.println(sb.toString());
		reader.close();
		// 关闭读取流

		fip.close();
		// 关闭输入流,释放系统资源
	} catch (Exception e) {
	}
}
 
Example 4
Project: FJ-VDMJ   File: CommandLine.java   View Source Code Vote up 4 votes
protected String promptLine() throws IOException
{
	if (startLine != null)
	{
		String line = startLine.trim();
		println("> " + startLine);
		startLine = null;
		return line;
	}

	StringBuilder lineTyped = new StringBuilder();
	InputStreamReader console = new InputStreamReader(System.in);
	boolean prompted = false;

	if (messages.isEmpty())
	{
		print(getPrompt());		// Otherwise nothing appears when quiet!
		prompted = true;
	}

	while (true)
	{
		if (!messages.isEmpty())
		{
			if (prompted)
			{
				print("\n");
			}

			while (!messages.isEmpty())
			{
				String msg = messages.poll();

				if (msg.length() > 0)
				{
					println(msg.toString());
				}
			}

			print(getPrompt());
			print(lineTyped.toString());
			prompted = true;
		}

		while (console.ready())
		{
			int c = console.read();

			if (c == '\r')
			{
				continue;
			}
			else if (c == '\n' || c == -1)
			{
				return lineTyped.toString().trim();
			}
			else
			{
				lineTyped.append((char)c);
			}
		}

		Utils.milliPause(10);
	}
}