List of usage examples for java.io FileInputStream close
public void close() throws IOException
From source file:Main.java
public static void main(String[] args) throws Exception { Class.forName("oracle.jdbc.driver.OracleDriver").newInstance(); Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:ORCL", "yourName", "mypwd"); Statement stmt = conn.createStatement(); createBlobClobTables(stmt);//ww w . j av a2 s. c om PreparedStatement pstmt = conn.prepareStatement("INSERT INTO BlobClob VALUES(40,?,?)"); File file = new File("blob.txt"); FileInputStream fis = new FileInputStream(file); pstmt.setBinaryStream(1, fis, (int) file.length()); file = new File("clob.txt"); fis = new FileInputStream(file); pstmt.setAsciiStream(2, fis, (int) file.length()); fis.close(); pstmt.execute(); ResultSet rs = stmt.executeQuery("SELECT * FROM BlobClob WHERE id = 40"); rs.next(); java.sql.Blob blob = rs.getBlob(2); java.sql.Clob clob = rs.getClob("myClobColumn"); byte blobVal[] = new byte[(int) blob.length()]; InputStream blobIs = blob.getBinaryStream(); blobIs.read(blobVal); ByteArrayOutputStream bos = new ByteArrayOutputStream(); bos.write(blobVal); blobIs.close(); char clobVal[] = new char[(int) clob.length()]; Reader r = clob.getCharacterStream(); r.read(clobVal); StringWriter sw = new StringWriter(); sw.write(clobVal); r.close(); conn.close(); }
From source file:org.vuphone.vandyupon.test.ImagePostTester.java
public static void main(String[] args) { try {/*from w w w . ja v a2 s . c o m*/ File image = new File("2008-05-8 ChrisMikeNinaGrad.jpg"); byte[] bytes = new byte[(int) image.length()]; FileInputStream fis = new FileInputStream(image); int offset = 0; int numRead = 0; while (offset < bytes.length && (numRead = fis.read(bytes, offset, bytes.length - offset)) >= 0) { offset += numRead; } fis.close(); HttpClient c = new DefaultHttpClient(); HttpPost post = new HttpPost( "http://afrl-gift.dre.vanderbilt.edu:8080/vandyupon/events/?type=eventimagepost&eventid=2" + "&time=" + System.currentTimeMillis() + "&resp=xml"); post.addHeader("Content-Type", "image/jpeg"); ByteArrayEntity bae = new ByteArrayEntity(bytes); post.setEntity(bae); try { HttpResponse resp = c.execute(post); resp.getEntity().writeTo(System.out); } catch (IOException e) { e.printStackTrace(); } } catch (IOException e) { e.printStackTrace(); } }
From source file:BasApp.java
public static void main(String[] args) throws Exception { Options options = getOptions();//from w w w. j ava2 s.c o m CommandLineParser parser = new GnuParser(); CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("h")) { showHelp(options); return; // only show help and exit } final VOConfig cfg; if (cmd.hasOption("config")) { Serializer serializer = new Persister(); final String config = cmd.getOptionValue("config"); FileInputStream fis = new FileInputStream(config); cfg = serializer.read(VOConfig.class, fis); fis.close(); } else { cfg = new VOConfig(); } cfg.setCmd(cmd); CipherProvider dataCipherProvider = new CipherProvider(); dataCipherProvider.setPassword(cmd.getOptionValue("passwd", null)); CipherProvider metaCipherProvider = new CipherProvider(); metaCipherProvider.setPassword(cmd.getOptionValue("passwd-meta", null)); String repoPathStr = cfg.getRepository(); Repository repository = new Repository(repoPathStr, dataCipherProvider, metaCipherProvider); if (cmd.hasOption("dump-config")) { Serializer serializer = new Persister(); final FileOutputStream fos = new FileOutputStream(cmd.getOptionValue("dump-config")); serializer.write(cfg, fos); fos.close(); } if (cmd.hasOption("backup")) { BackupService backup = new BackupService(cfg, repository); backup.run(); } if (cmd.hasOption("restore")) { //noinspection unchecked String restoreTo = null; if (cmd.hasOption("restore-to")) { restoreTo = cmd.getOptionValue("restore-to"); } RestoreService restore = new RestoreService(cmd.getOptionValue("r"), repository, cmd.getArgList(), restoreTo); restore.run(); } if (cmd.hasOption("check")) { CheckService check = new CheckService(cmd.getOptionValue("check"), repository); check.run(); } }
From source file:com.yahoo.pulsar.admin.cli.PulsarAdminTool.java
public static void main(String[] args) throws Exception { String configFile = args[0];//from ww w .j a v a 2s.co m Properties properties = new Properties(); if (configFile != null) { FileInputStream fis = null; try { fis = new FileInputStream(configFile); properties.load(fis); } finally { if (fis != null) fis.close(); } } PulsarAdminTool tool = new PulsarAdminTool(properties); if (tool.run(Arrays.copyOfRange(args, 1, args.length))) { System.exit(0); } else { System.exit(1); } }
From source file:Main.java
public static void main(String[] args) throws Exception { CheckedOutputStream checksum = new CheckedOutputStream(new FileOutputStream("data.zip"), new Adler32()); ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(checksum)); int size = 0; byte[] buffer = new byte[1024]; File dir = new File("."); String[] files = dir.list();// w ww .j a v a 2 s. c o m for (int i = 0; i < files.length; i++) { System.out.println("Compressing: " + files[i]); FileInputStream fis = new FileInputStream(files[i]); ZipEntry zipEntry = new ZipEntry(files[i]); zos.putNextEntry(zipEntry); while ((size = fis.read(buffer, 0, buffer.length)) > 0) { zos.write(buffer, 0, size); } zos.closeEntry(); fis.close(); } zos.close(); System.out.println("Checksum : " + checksum.getChecksum().getValue()); }
From source file:Main.java
public static void main(String[] args) throws IOException { String outputFile = "new.zip"; int level = 9; int start = 1; FileOutputStream fout = new FileOutputStream(outputFile); ZipOutputStream zout = new ZipOutputStream(fout); zout.setLevel(level);//from ww w . j a va 2 s. c om for (int i = start; i < args.length; i++) { ZipEntry ze = new ZipEntry(args[i]); FileInputStream fin = new FileInputStream(args[i]); try { System.out.println("Compressing " + args[i]); zout.putNextEntry(ze); for (int c = fin.read(); c != -1; c = fin.read()) { zout.write(c); } } finally { fin.close(); } } zout.close(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { KeyGenerator keyGenerator = KeyGenerator.getInstance("Blowfish"); keyGenerator.init(128);/*w ww . ja va2s .c o m*/ Key secretKey = keyGenerator.generateKey(); Cipher cipherOut = Cipher.getInstance("Blowfish/CFB/NoPadding"); cipherOut.init(Cipher.ENCRYPT_MODE, secretKey); BASE64Encoder encoder = new BASE64Encoder(); byte iv[] = cipherOut.getIV(); if (iv != null) { System.out.println("Initialization Vector of the Cipher:\n" + encoder.encode(iv)); } FileInputStream fin = new FileInputStream("inputFile.txt"); FileOutputStream fout = new FileOutputStream("outputFile.txt"); CipherOutputStream cout = new CipherOutputStream(fout, cipherOut); int input = 0; while ((input = fin.read()) != -1) { cout.write(input); } fin.close(); cout.close(); }
From source file:MainClass.java
public static void main(String[] args) throws IOException { String outputFile = "new.zip"; // Default to maximum compression int level = 9; int start = 1; FileOutputStream fout = new FileOutputStream(outputFile); ZipOutputStream zout = new ZipOutputStream(fout); zout.setLevel(level);//from w w w .ja v a2 s . co m for (int i = start; i < args.length; i++) { ZipEntry ze = new ZipEntry(args[i]); FileInputStream fin = new FileInputStream(args[i]); try { System.out.println("Compressing " + args[i]); zout.putNextEntry(ze); for (int c = fin.read(); c != -1; c = fin.read()) { zout.write(c); } } finally { fin.close(); } } zout.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { FileInputStream fis = new FileInputStream("test.txt"); FileChannel fc = fis.getChannel(); long startRegion = 0; long endRegion = fc.size(); MappedByteBuffer mbb = fc.map(FileChannel.MapMode.READ_ONLY, startRegion, endRegion); while (mbb.hasRemaining()) { System.out.print((char) mbb.get()); }/*from ww w .j a v a2 s. c om*/ fis.close(); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { File aFile = new File("charData.xml"); FileInputStream inFile = null; inFile = new FileInputStream(aFile); FileChannel inChannel = inFile.getChannel(); ByteBuffer buf = ByteBuffer.allocate(48); while (inChannel.read(buf) != -1) { System.out.println("String read: " + ((ByteBuffer) (buf.flip())).asCharBuffer().get(0)); buf.clear();/* w ww . j a v a 2 s . co m*/ } inFile.close(); }