home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / java / io / Console.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  4.5 KB  |  222 lines

  1. package java.io;
  2.  
  3. import java.nio.charset.Charset;
  4. import java.util.Arrays;
  5. import java.util.Formatter;
  6. import sun.misc.SharedSecrets;
  7. import sun.nio.cs.StreamDecoder;
  8. import sun.nio.cs.StreamEncoder;
  9.  
  10. public final class Console implements Flushable {
  11.    private Object readLock;
  12.    private Object writeLock;
  13.    private Reader reader;
  14.    private Writer out;
  15.    // $FF: renamed from: pw java.io.PrintWriter
  16.    private PrintWriter field_0;
  17.    private Formatter formatter;
  18.    // $FF: renamed from: cs java.nio.charset.Charset
  19.    private Charset field_1;
  20.    private char[] rcb;
  21.    private static boolean echoOff;
  22.    private static Console cons;
  23.  
  24.    public PrintWriter writer() {
  25.       return this.field_0;
  26.    }
  27.  
  28.    public Reader reader() {
  29.       return this.reader;
  30.    }
  31.  
  32.    public Console format(String var1, Object... var2) {
  33.       this.formatter.format(var1, var2).flush();
  34.       return this;
  35.    }
  36.  
  37.    public Console printf(String var1, Object... var2) {
  38.       return this.format(var1, var2);
  39.    }
  40.  
  41.    public String readLine(String var1, Object... var2) {
  42.       String var3 = null;
  43.       synchronized(this.writeLock) {
  44.          synchronized(this.readLock) {
  45.             if (var1.length() != 0) {
  46.                this.field_0.format(var1, var2);
  47.             }
  48.  
  49.             try {
  50.                char[] var6 = this.readline(false);
  51.                if (var6 != null) {
  52.                   var3 = new String(var6);
  53.                }
  54.             } catch (IOException var9) {
  55.                throw new IOError(var9);
  56.             }
  57.          }
  58.  
  59.          return var3;
  60.       }
  61.    }
  62.  
  63.    public String readLine() {
  64.       return this.readLine("");
  65.    }
  66.  
  67.    public char[] readPassword(String var1, Object... var2) {
  68.       Object var3 = null;
  69.       synchronized(this.writeLock) {
  70.          char[] var22;
  71.          synchronized(this.readLock) {
  72.             if (var1.length() != 0) {
  73.                this.field_0.format(var1, var2);
  74.             }
  75.  
  76.             try {
  77.                echoOff = echo(false);
  78.                var22 = this.readline(true);
  79.             } catch (IOException var18) {
  80.                throw new IOError(var18);
  81.             } finally {
  82.                try {
  83.                   echoOff = echo(true);
  84.                } catch (IOException var17) {
  85.                }
  86.  
  87.             }
  88.  
  89.             this.field_0.println();
  90.          }
  91.  
  92.          return var22;
  93.       }
  94.    }
  95.  
  96.    public char[] readPassword() {
  97.       return this.readPassword("");
  98.    }
  99.  
  100.    public void flush() {
  101.       this.field_0.flush();
  102.    }
  103.  
  104.    private static native String encoding();
  105.  
  106.    private static native boolean echo(boolean var0) throws IOException;
  107.  
  108.    private char[] readline(boolean var1) throws IOException {
  109.       int var2 = this.reader.read(this.rcb, 0, this.rcb.length);
  110.       if (var2 < 0) {
  111.          return null;
  112.       } else {
  113.          if (this.rcb[var2 - 1] == '\r') {
  114.             --var2;
  115.          } else if (this.rcb[var2 - 1] == '\n') {
  116.             --var2;
  117.             if (var2 > 0 && this.rcb[var2 - 1] == '\r') {
  118.                --var2;
  119.             }
  120.          }
  121.  
  122.          char[] var3 = new char[var2];
  123.          if (var2 > 0) {
  124.             System.arraycopy(this.rcb, 0, var3, 0, var2);
  125.             if (var1) {
  126.                Arrays.fill(this.rcb, 0, var2, ' ');
  127.             }
  128.          }
  129.  
  130.          return var3;
  131.       }
  132.    }
  133.  
  134.    private char[] grow() {
  135.       assert Thread.holdsLock(this.readLock);
  136.  
  137.       char[] var1 = new char[this.rcb.length * 2];
  138.       System.arraycopy(this.rcb, 0, var1, 0, this.rcb.length);
  139.       this.rcb = var1;
  140.       return this.rcb;
  141.    }
  142.  
  143.    private static native boolean istty();
  144.  
  145.    private Console() {
  146.       this.readLock = new Object();
  147.       this.writeLock = new Object();
  148.       String var1 = encoding();
  149.       if (var1 != null) {
  150.          try {
  151.             this.field_1 = Charset.forName(var1);
  152.          } catch (Exception var3) {
  153.          }
  154.       }
  155.  
  156.       if (this.field_1 == null) {
  157.          this.field_1 = Charset.defaultCharset();
  158.       }
  159.  
  160.       this.out = StreamEncoder.forOutputStreamWriter(new FileOutputStream(FileDescriptor.out), this.writeLock, this.field_1);
  161.       this.field_0 = new 2(this, this.out, true);
  162.       this.formatter = new Formatter(this.out);
  163.       this.reader = new LineReader(this, StreamDecoder.forInputStreamReader(new FileInputStream(FileDescriptor.in), this.readLock, this.field_1));
  164.       this.rcb = new char[1024];
  165.    }
  166.  
  167.    // $FF: synthetic method
  168.    static Object access$000(Console var0) {
  169.       return var0.readLock;
  170.    }
  171.  
  172.    // $FF: synthetic method
  173.    static char[] access$100(Console var0) {
  174.       return var0.rcb;
  175.    }
  176.  
  177.    // $FF: synthetic method
  178.    static char[] access$200(Console var0) {
  179.       return var0.grow();
  180.    }
  181.  
  182.    // $FF: synthetic method
  183.    static boolean access$300() {
  184.       return istty();
  185.    }
  186.  
  187.    // $FF: synthetic method
  188.    static Console access$400() {
  189.       return cons;
  190.    }
  191.  
  192.    // $FF: synthetic method
  193.    static Console access$402(Console var0) {
  194.       cons = var0;
  195.       return var0;
  196.    }
  197.  
  198.    // $FF: synthetic method
  199.    Console(1 var1) {
  200.       this();
  201.    }
  202.  
  203.    // $FF: synthetic method
  204.    static boolean access$600() {
  205.       return echoOff;
  206.    }
  207.  
  208.    // $FF: synthetic method
  209.    static boolean access$700(boolean var0) throws IOException {
  210.       return echo(var0);
  211.    }
  212.  
  213.    // $FF: synthetic method
  214.    static Charset access$800(Console var0) {
  215.       return var0.field_1;
  216.    }
  217.  
  218.    static {
  219.       SharedSecrets.setJavaIOAccess(new 1());
  220.    }
  221. }
  222.