Java Code Examples for java.io.PushbackInputStream#available()

The following examples show how to use java.io.PushbackInputStream#available() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MaildirMessage.java    From james-project with Apache License 2.0 5 votes vote down vote up
/**
 * Return the position in the given {@link InputStream} at which the Body of
 * the MailboxMessage starts
 */
private int bodyStartOctet(InputStream msgIn) throws IOException {
    // we need to pushback maximal 3 bytes
    PushbackInputStream in = new PushbackInputStream(msgIn, 3);
    int localBodyStartOctet = in.available();
    int i;
    int count = 0;
    while ((i = in.read()) != -1 && in.available() > 4) {
        if (i == 0x0D) {
            int a = in.read();
            if (a == 0x0A) {
                int b = in.read();

                if (b == 0x0D) {
                    int c = in.read();

                    if (c == 0x0A) {
                        localBodyStartOctet = count + 4;
                        break;
                    }
                    in.unread(c);
                }
                in.unread(b);
            }
            in.unread(a);
        }
        count++;
    }
    return localBodyStartOctet;
}
 
Example 2
Source File: RemoteANSIConnection.java    From swift-k with Apache License 2.0 4 votes vote down vote up
public void run() {
	try {
		is = new PushbackInputStream(socket.getInputStream());
		os = socket.getOutputStream();
		osw = new OutputStreamWriter(os);
		if (is.available() > 0) {
			osw.write("HTTP/1.1 200 OK\n");
			osw.write("Date: " + new Date() + "\n");
			osw.write("Content-Length: -1\n");
			osw.write("Connection: close\n");
			osw.write("Content-Type: text/html;\n");
			osw.write("\n");
			osw.write("\n");
			osw.write("<html><head></head><body>Hello!</body></html>\n");
			osw.flush();
		}
		else {
			negotiateStuff();

			/*
			 * ANSIContext context = new ANSIContext(os, is); Screen screen =
			 * new Screen(context); screen.init(); Label text = new
			 * Label("Swift System Monitor"); text.setBgColor(ANSI.BLUE);
			 * text.setFgColor(ANSI.WHITE); text.setLocation(0, 0);
			 * text.setJustification(Label.CENTER);
			 * text.setSize(screen.getWidth(), 1);
			 * 
			 * CharacterMap map = new CharacterMap(); map.setLocation(10,
			 * 10);
			 * 
			 * screen.add(text); screen.add(map); screen.redraw();
			 * context.run();
			 */
			super.run();
		}
		socket.close();
	}
	catch (Exception e) {
		e.printStackTrace();
	}
}