Example usage for java.io FileInputStream FileInputStream

List of usage examples for java.io FileInputStream FileInputStream

Introduction

In this page you can find the example usage for java.io FileInputStream FileInputStream.

Prototype

public FileInputStream(FileDescriptor fdObj) 

Source Link

Document

Creates a FileInputStream by using the file descriptor fdObj, which represents an existing connection to an actual file in the file system.

Usage

From source file:MainClass.java

public static void main(String[] args) {

    for (int i = 0; i < args.length; i++) {
        if (args[i].toLowerCase().endsWith(".gz")) {
            try {
                FileInputStream fin = new FileInputStream(args[i]);
                GZIPInputStream gzin = new GZIPInputStream(fin);
                FileOutputStream fout = new FileOutputStream(args[i].substring(0, args[i].length() - 3));
                for (int c = gzin.read(); c != -1; c = gzin.read()) {
                    fout.write(c);/* www. j a  v  a 2  s .c o  m*/
                }
                fout.close();
            } catch (IOException ex) {
                System.err.println(ex);
            }
        } else {
            System.err.println(args[i] + " does not appear to be a gzipped file.");
        }
    }
}

From source file:MainClass.java

public static void main(String args[]) throws Exception {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    FileInputStream in = new FileInputStream(args[0]);
    java.security.cert.Certificate c = cf.generateCertificate(in);
    in.close();//from  ww w .  j av  a  2 s . c  o m

    X509Certificate t = (X509Certificate) c;
    System.out.println(t.getVersion());
    System.out.println(t.getSerialNumber().toString(16));
    System.out.println(t.getSubjectDN());
    System.out.println(t.getIssuerDN());
    System.out.println(t.getNotBefore());
    System.out.println(t.getNotAfter());
    System.out.println(t.getSigAlgName());
    byte[] sig = t.getSignature();
    System.out.println(new BigInteger(sig).toString(16));
    PublicKey pk = t.getPublicKey();
    byte[] pkenc = pk.getEncoded();
    for (int i = 0; i < pkenc.length; i++) {
        System.out.print(pkenc[i] + ",");
    }
}

From source file:MainClass.java

public static void main(String args[]) {
    FileInputStream fileInputStream;
    FileChannel fileChannel;//from  w w w.  ja v a2  s .  c  o m
    long fileSize;
    MappedByteBuffer mBuf;

    try {
        fileInputStream = new FileInputStream("test.txt");
        fileChannel = fileInputStream.getChannel();
        fileSize = fileChannel.size();
        mBuf = fileChannel.map(FileChannel.MapMode.READ_ONLY, 0, fileSize);

        for (int i = 0; i < fileSize; i++)
            System.out.print((char) mBuf.get());

        fileChannel.close();
        fileInputStream.close();
    } catch (IOException exc) {
        System.out.println(exc);
        System.exit(1);
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Pattern pattern = Pattern.compile("pattern");
    FileInputStream input = new FileInputStream("file.txt");
    FileChannel channel = input.getChannel();

    ByteBuffer bbuf = channel.map(FileChannel.MapMode.READ_ONLY, 0, (int) channel.size());
    CharBuffer cbuf = Charset.forName("8859_1").newDecoder().decode(bbuf);

    Matcher matcher = pattern.matcher(cbuf);
    while (matcher.find()) {
        String match = matcher.group();
        System.out.println(match);
    }//w w  w. j a v  a  2s .co m
}

From source file:Main.java

public static void main(String[] args) {

    try {// w  ww  . j ava2 s  .  c  om
        // create a new OutputStreamWriter
        OutputStream os = new FileOutputStream("test.txt");
        OutputStreamWriter writer = new OutputStreamWriter(os);

        // create a new FileInputStream to read what we write
        FileInputStream in = new FileInputStream("test.txt");

        // write something in the file
        writer.write(70);

        // flush the stream
        writer.flush();
        // read what we write
        System.out.println((char) in.read());
        writer.close();
        os.close();

    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String outFilename = "outfile.gzip";
    GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(outFilename));

    String inFilename = "infilename";
    FileInputStream in = new FileInputStream(inFilename);

    byte[] buf = new byte[1024];
    int len;//from   www.  jav a2 s  .c o  m
    while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
    }
    in.close();

    out.finish();
    out.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    FileInputStream in = new FileInputStream(args[0]);
    X509CRL crl = (X509CRL) cf.generateCRL(in);
    Set s = crl.getRevokedCertificates();
    if (s != null && s.isEmpty() == false) {
        Iterator t = s.iterator();
        while (t.hasNext()) {
            X509CRLEntry entry = (X509CRLEntry) t.next();
            System.out.println("serial number = " + entry.getSerialNumber().toString(16));
            System.out.println("revocation date = " + entry.getRevocationDate());
            System.out.println("extensions = " + entry.hasExtensions());
        }//from w ww  .j a  v a2 s  .  c o  m
    }
    in.close();
}

From source file:MainClass.java

public static void main(String[] args) {
    File aFile = new File("C:/test.bin");
    FileInputStream inFile = null;
    try {/*from   w w w .j a va 2 s  . c o  m*/
        inFile = new FileInputStream(aFile);
    } catch (FileNotFoundException e) {
        e.printStackTrace(System.err);
    }
    FileChannel inChannel = inFile.getChannel();
    final int PRIMECOUNT = 6;
    ByteBuffer buf = ByteBuffer.allocate(8 * PRIMECOUNT);
    long[] primes = new long[PRIMECOUNT];
    try {
        while (inChannel.read(buf) != -1) {
            ((ByteBuffer) (buf.flip())).asLongBuffer().get(primes);
            for (long prime : primes) {
                System.out.printf("%10d", prime);
            }
            buf.clear();
        }
        inFile.close();
    } catch (IOException e) {
        e.printStackTrace(System.err);
    }
}

From source file:Main.java

  public static void main(String[] argv) throws Exception {
  String inFilename = "infile.zip";
  ZipInputStream in = new ZipInputStream(new FileInputStream(inFilename));

  ZipEntry entry = in.getNextEntry();

  String outFilename = "o";
  OutputStream out = new FileOutputStream(outFilename);

  byte[] buf = new byte[1024];
  int len;/*from www .  j  ava 2s  .c o  m*/
  while ((len = in.read(buf)) > 0) {
    out.write(buf, 0, len);
  }

  out.close();
  in.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Pack200.Unpacker unpacker = Pack200.newUnpacker();
    JarOutputStream out = new JarOutputStream(new FileOutputStream("outName"));
    InputStream in = new FileInputStream("inName");
    // in = new GZIPInputStream(in);
    unpacker.unpack(in, out);//from   w  ww  . j a v  a  2s. co  m
    out.close();
}