Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Apache License 

import java.io.IOException;
import java.io.InputStream;

import java.io.OutputStream;

public class Main {
    static public final String readPassword(OutputStream out, InputStream in) throws IOException {
        int rd = in.read();
        if (rd == -1)
            return null;
        byte r = (byte) rd;
        int i = 0;
        int l = 50;
        byte[] buf = new byte[l];
        while (r != '\n') {
            if (i >= l - 1) {
                l += 50;
                byte[] old = buf;
                buf = new byte[l];
                System.arraycopy(old, 0, buf, 0, old.length);
            }
            if (r != '\r') {
                buf[i++] = r;
                out.write('\b');
                out.write('*');
                out.flush();
            }
            rd = in.read();
            if (rd == -1)
                break;
            r = (byte) rd;
        }
        return new String(buf, 0, i);
    }
}