List of usage examples for java.io FileInputStream close
public void close() throws IOException
From source file:testSig.java
public static void main(String[] args) { /* Test generating and verifying a DSA signature */ try {/* ww w. j ava2 s.co m*/ /* generate a key pair */ KeyPairGenerator keyGen = KeyPairGenerator.getInstance("DSA"); keyGen.initialize(1024, new SecureRandom()); KeyPair pair = keyGen.generateKeyPair(); /* * create a Signature object to use for signing and verifying */ Signature dsa = Signature.getInstance("SHA/DSA"); /* initialize the Signature object for signing */ PrivateKey priv = pair.getPrivate(); dsa.initSign(priv); /* Update and sign the data */ FileInputStream fis = new FileInputStream(args[0]); byte b; while (fis.available() != 0) { b = (byte) fis.read(); dsa.update(b); } ; fis.close(); /* * Now that all the data to be signed has been read in, sign it */ byte[] sig = dsa.sign(); /* Verify the signature */ /* Initialize the Signature object for verification */ PublicKey pub = pair.getPublic(); dsa.initVerify(pub); /* Update and verify the data */ fis = new FileInputStream(args[0]); while (fis.available() != 0) { b = (byte) fis.read(); dsa.update(b); } ; fis.close(); boolean verifies = dsa.verify(sig); System.out.println("signature verifies: " + verifies); } catch (Exception e) { System.err.println("Caught exception " + e.toString()); } }
From source file:Main.java
public static void main(String[] args) { for (int i = 0; i < args.length; i++) { try {/*w w w . jav a 2 s . co m*/ FileInputStream fin = new FileInputStream(args[i]); FileOutputStream fout = new FileOutputStream(args[i] + "dfl"); DeflaterOutputStream dos = new DeflaterOutputStream(fout); for (int c = fin.read(); c != -1; c = fin.read()) { dos.write(c); } dos.close(); fin.close(); } catch (IOException ex) { System.err.println(ex); } } }
From source file:ByteReader.java
public static void main(String[] arguments) { try {//from ww w.ja va 2 s. co m FileInputStream file = new FileInputStream("class.dat"); boolean eof = false; int count = 0; while (!eof) { int input = file.read(); System.out.print(input + " "); if (input == -1) eof = true; else count++; } file.close(); System.out.println("\nBytes read: " + count); } catch (IOException e) { System.out.println("Error - " + e.toString()); } }
From source file:com.yahoo.pulsar.client.cli.PulsarClientTool.java
public static void main(String[] args) throws Exception { if (args.length == 0) { System.out.println("Usage: pulsar-client CONF_FILE_PATH [options] [command] [command options]"); System.exit(-1);//from w ww . ja v a 2s . c o m } String configFile = args[0]; Properties properties = new Properties(); if (configFile != null) { FileInputStream fis = null; try { fis = new FileInputStream(configFile); properties.load(fis); } finally { if (fis != null) { fis.close(); } } } PulsarClientTool clientTool = new PulsarClientTool(properties); int exit_code = clientTool.run(Arrays.copyOfRange(args, 1, args.length)); System.exit(exit_code); }
From source file:main.ReportGenerator.java
/** * Entry point for the program./*from ww w . ja v a 2 s. co m*/ * Takes the variables as JSON on the standard input. * @param args Arguments from the command line. */ public static void main(String[] args) { CommandLine cmd = createOptions(args); GeneratorError result = GeneratorError.NO_ERROR; try { //Build the output name, by default ./output String directory = cmd.getOptionValue("output", "./"); if (!directory.endsWith(File.separator)) directory += File.separator; String filename = cmd.getOptionValue("name", "output"); String output = directory + filename; //Get the JSON from file if given, or get it from the standard input. String jsonText = null; if (!cmd.hasOption("input")) { // Initializes the input with the standard input jsonText = IOUtils.toString(System.in, "UTF-8"); } else // read the file { FileInputStream inputStream = new FileInputStream(cmd.getOptionValue("input")); try { jsonText = IOUtils.toString(inputStream); } finally { inputStream.close(); } } //Build the report object Report report = new Report(jsonText, cmd.getOptionValue("template"), output); //Generate the document if (cmd.hasOption("all")) { new AllGenerator(report).generate(); } else { if (cmd.hasOption("html")) new HTMLGenerator(report).generate(); if (cmd.hasOption("pdf")) new PDFGenerator(report).generate(); if (cmd.hasOption("doc")) new DocGenerator(report).generate(); } } catch (IOException e) { System.err.println("Error: " + e.getMessage()); System.exit(GeneratorError.IO_ERROR.getCode()); } catch (GeneratorException e) { System.err.println("Error: " + e.getMessage()); System.exit(e.getError().getCode()); } System.exit(result.getCode()); }
From source file:Main.java
public static void main(String args[]) throws Exception { FileInputStream fIn = new FileInputStream("test.txt"); FileChannel fChan = fIn.getChannel(); long fSize = fChan.size(); ByteBuffer mBuf = ByteBuffer.allocate((int) fSize); fChan.read(mBuf);/*from w w w.j ava 2 s .co m*/ mBuf.rewind(); for (int i = 0; i < fSize; i++) { System.out.print((char) mBuf.get()); } fChan.close(); fIn.close(); }
From source file:Main.java
public static void main(String args[]) throws Exception { FileInputStream fIn = new FileInputStream("test.txt"); FileChannel fChan = fIn.getChannel(); long fSize = fChan.size(); ByteBuffer mBuf = ByteBuffer.allocate((int) fSize); fChan.read(mBuf, 10);//w w w. j ava2 s . c om mBuf.rewind(); for (int i = 0; i < fSize; i++) { System.out.print((char) mBuf.get()); } fChan.close(); fIn.close(); }
From source file:MainClass.java
public static void main(String[] args) { for (int i = 0; i < args.length; i++) { try {/*from w ww. j a va2 s . c o m*/ FileInputStream fin = new FileInputStream(args[i]); FileOutputStream fout = new FileOutputStream(args[i] + DEFLATE_SUFFIX); DeflaterOutputStream dos = new DeflaterOutputStream(fout); for (int c = fin.read(); c != -1; c = fin.read()) { dos.write(c); } dos.close(); fin.close(); } catch (IOException ex) { System.err.println(ex); } } }
From source file:Main.java
public static void main(String[] args) throws Exception { FileInputStream fis = new FileInputStream("main.java"); int i = 0;/*ww w .j a v a2 s. co m*/ int count = 0; while ((i = fis.read()) != -1) { if (i != -1) { System.out.printf("%02X ", i); count++; } if (count == 16) { System.out.println(""); count = 0; } } fis.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { boolean areFilesIdentical = true; File file1 = new File("c:\\file1.txt"); File file2 = new File("c:\\file2.txt"); FileInputStream fis1 = new FileInputStream(file1); FileInputStream fis2 = new FileInputStream(file2); int i1 = fis1.read(); int i2 = fis2.read(); while (i1 != -1) { if (i1 != i2) { areFilesIdentical = false;/*from www. j a v a2 s . c o m*/ break; } i1 = fis1.read(); i2 = fis2.read(); } fis1.close(); fis2.close(); System.out.println(areFilesIdentical); }