List of usage examples for java.io FileInputStream FileInputStream
public FileInputStream(FileDescriptor fdObj)
FileInputStream
by using the file descriptor fdObj
, which represents an existing connection to an actual file in the file system. From source file:shutdown.java
License:asdf
public static void main(String[] args) throws ClassNotFoundException, IOException { FileOutputStream fos = new FileOutputStream("objects.tmp"); ObjectOutputStream oos = new ObjectOutputStream(fos); oos.writeObject("asdf"); oos.flush();// ww w . j ava2 s . c o m fos.close(); FileInputStream fis = new FileInputStream("objects.tmp"); ObjectInputStream ois = new ObjectInputStream(fis); String t = (String) ois.readObject(); fis.close(); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { X509CertSelector selec = new X509CertSelector(); CertificateFactory cf = CertificateFactory.getInstance("X.509"); FileInputStream in = new FileInputStream(args[0]); Certificate c = cf.generateCertificate(in); System.out.println(selec.match(c)); selec.setIssuer("CN=Peter,OU=Network Center," + "O=University,L=ZB,ST=Vancouver,C=CN"); System.out.println(selec.match(c)); Calendar cld = Calendar.getInstance(); int year = Integer.parseInt(args[1]); int month = Integer.parseInt(args[2]) - 1; int day = Integer.parseInt(args[3]); cld.set(year, month, day);/* w ww .jav a2s. com*/ Date d = cld.getTime(); selec.setCertificateValid(d); System.out.println(selec.match(c)); BigInteger sn = new BigInteger("1039056963"); selec.setSerialNumber(sn); System.out.println(selec.match(c)); }
From source file:MainClass.java
public static void main(String args[]) throws Exception { Certificate[] certpath = new Certificate[args.length - 1]; CertificateFactory cf = CertificateFactory.getInstance("X.509"); int i;//from ww w .java2 s . c o m for (i = 0; i < args.length - 1; i++) { FileInputStream in = new FileInputStream(args[i]); certpath[i] = cf.generateCertificate(in); } FileInputStream in = new FileInputStream(args[i]); Certificate trust = cf.generateCertificate(in); boolean pass = false; String reason = ""; for (i = 0; i < certpath.length; i++) { try { PublicKey pbk; if (i == certpath.length - 1) { pbk = trust.getPublicKey(); } else { pbk = certpath[i + 1].getPublicKey(); } certpath[i].verify(pbk); pass = true; } catch (Exception e) { pass = false; reason += i + " " + e.toString(); break; } } System.out.println(pass); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { PdfReader reader;/*from w w w .j a v a 2s.co m*/ KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType()); ks.load(new FileInputStream(".keystore"), "string".toCharArray()); PrivateKey key = (PrivateKey) ks.getKey("key", "value".toCharArray()); Certificate[] chain = ks.getCertificateChain("foobar"); reader = new PdfReader("2.pdf"); FileOutputStream os = new FileOutputStream("1.pdf"); PdfStamper stamper = PdfStamper.createSignature(reader, os, '\0'); PdfSignatureAppearance appearance = stamper.getSignatureAppearance(); appearance.setCrypto(key, chain, null, PdfSignatureAppearance.SELF_SIGNED); appearance.setReason("personal"); appearance.setLocation("Foobar"); appearance.setVisibleSignature("yoursig"); stamper.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { Properties prop = new Properties(); prop.put("Chapter Count", "200"); prop.put("Tutorial Count", "15"); prop.put("tutorial", "java2s.com"); // create a output and input as a xml file FileOutputStream fos = new FileOutputStream("properties.xml"); FileInputStream fis = new FileInputStream("properties.xml"); prop.storeToXML(fos, "Properties Example", "ISO 8859"); while (fis.available() > 0) { System.out.print((char) fis.read()); }/*w w w. j a va2 s .c o m*/ }
From source file:Main.java
public static void main(String[] args) { String s = "from java2s.com!"; try {//from w w w .j av a 2 s.com OutputStream os = new FileOutputStream("test.txt"); OutputStreamWriter writer = new OutputStreamWriter(os, Charset.defaultCharset().newEncoder()); FileInputStream in = new FileInputStream("test.txt"); writer.write(s, 0, 5); writer.flush(); for (int i = 0; i < 5; i++) { System.out.print((char) in.read()); } writer.close(); in.close(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:TestEOF.java
public static void main(String[] args) throws IOException { DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream("TestEOF.java"))); while (in.available() != 0) System.out.print((char) in.readByte()); }
From source file:Main.java
public static void main(String[] args) throws Exception { Properties prop = new Properties(); prop.put("Chapter Count", "200"); prop.put("Tutorial Count", "15"); prop.put("tutorial", "java2s.com"); // create a output and input as a xml file FileOutputStream fos = new FileOutputStream("properties.xml"); FileInputStream fis = new FileInputStream("properties.xml"); // store the properties in the specific xml prop.storeToXML(fos, "Properties Example"); // print the xml while (fis.available() > 0) { System.out.print((char) fis.read()); }//from w w w .j a v a 2 s .c om }
From source file:Main.java
public static void main(String[] args) throws Exception { String inName = "a.pack.gz"; String outName = "a.unpacked"; 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 w w . j a v a 2 s .c om out.close(); }
From source file:MainClass.java
public static void main(String[] args) { File aFile = new File("data.dat"); FileInputStream inFile = null; try {/*from w ww. j av a 2s .co m*/ inFile = new FileInputStream(aFile); } catch (FileNotFoundException e) { e.printStackTrace(System.err); System.exit(1); } FileChannel inChannel = inFile.getChannel(); final int COUNT = 6; ByteBuffer buf = ByteBuffer.allocate(8 * COUNT); long[] data = new long[COUNT]; try { int pos = 0; while (inChannel.read(buf) != -1) { try { ((ByteBuffer) (buf.flip())).asLongBuffer().get(data); pos = data.length; } catch (BufferUnderflowException e) { LongBuffer longBuf = buf.asLongBuffer(); pos = longBuf.remaining(); longBuf.get(data, 0, pos); } System.out.println(); for (int i = 0; i < pos; i++) { System.out.printf("%10d", data[i]); } buf.clear(); } System.out.println("\nEOF reached."); inFile.close(); } catch (IOException e) { e.printStackTrace(System.err); System.exit(1); } }