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 IOException { byte b = 66;/*from www . j a v a 2 s . c o m*/ int i = 0; FileOutputStream fos = new FileOutputStream(FileDescriptor.out); fos.write(b); fos.flush(); FileInputStream fis = new FileInputStream("C://test.txt"); // read till the end of the file while ((i = fis.read()) != -1) { // convert integer to character char c = (char) i; System.out.print(c); } fos.close(); fis.close(); }
From source file:LauncherBootstrap.java
/** * The main method./*from ww w .j a v a 2 s .c o m*/ * * @param args command line arguments */ public static void main(String[] args) { try { // Try to find the LAUNCHER_JAR_FILE_NAME file in the class // loader's and JVM's classpath. URL coreURL = LauncherBootstrap.class.getResource("/" + LauncherBootstrap.LAUNCHER_JAR_FILE_NAME); if (coreURL == null) throw new FileNotFoundException(LauncherBootstrap.LAUNCHER_JAR_FILE_NAME); // Coerce the coreURL's directory into a file File coreDir = new File(URLDecoder.decode(coreURL.getFile())).getCanonicalFile().getParentFile(); // Try to find the LAUNCHER_PROPS_FILE_NAME file in the same // directory as this class File propsFile = new File(coreDir, LauncherBootstrap.LAUNCHER_PROPS_FILE_NAME); if (!propsFile.canRead()) throw new FileNotFoundException(propsFile.getPath()); // Load the properties in the LAUNCHER_PROPS_FILE_NAME Properties props = new Properties(); FileInputStream fis = new FileInputStream(propsFile); props.load(fis); fis.close(); // Create a class loader that contains the Launcher, Ant, and // JAXP classes. URL[] antURLs = LauncherBootstrap .fileListToURLs((String) props.get(LauncherBootstrap.ANT_CLASSPATH_PROP_NAME)); URL[] urls = new URL[1 + antURLs.length]; urls[0] = coreURL; for (int i = 0; i < antURLs.length; i++) urls[i + 1] = antURLs[i]; ClassLoader parentLoader = Thread.currentThread().getContextClassLoader(); URLClassLoader loader = null; if (parentLoader != null) loader = new URLClassLoader(urls, parentLoader); else loader = new URLClassLoader(urls); // Load the LAUNCHER_MAIN_CLASS_NAME class launcherClass = loader.loadClass(LAUNCHER_MAIN_CLASS_NAME); // Get the LAUNCHER_MAIN_CLASS_NAME class' getLocalizedString() // method as we need it for printing the usage statement Method getLocalizedStringMethod = launcherClass.getDeclaredMethod("getLocalizedString", new Class[] { String.class }); // Invoke the LAUNCHER_MAIN_CLASS_NAME class' start() method. // If the ant.class.path property is not set correctly in the // LAUNCHER_PROPS_FILE_NAME, this will throw an exception. Method startMethod = launcherClass.getDeclaredMethod("start", new Class[] { String[].class }); int returnValue = ((Integer) startMethod.invoke(null, new Object[] { args })).intValue(); // Always exit cleanly after invoking the start() method System.exit(returnValue); } catch (Throwable t) { t.printStackTrace(); System.exit(1); } }
From source file:Main.java
public static void main(String args[]) throws IOException { SequenceInputStream inStream; FileInputStream f1 = new FileInputStream("ByteArrayIOApp.java"); FileInputStream f2 = new FileInputStream("FileIOApp.java"); inStream = new SequenceInputStream(f1, f2); byte[] arrayBytes = new byte[100]; int c = inStream.read(arrayBytes, 10, 10); inStream.close();/* w ww .j av a2s. c om*/ f1.close(); f2.close(); }
From source file:com.cisco.dvbu.ps.common.adapters.core.CisWsClient.java
public static void main(String[] args) throws Exception { if (args.length < 8) { System.err.println(/* w ww . jav a 2s. c om*/ "usage: java com.cisco.dvbu.ps.common.adapters.core.CisWsClient endpointName endpointMethod configXml requestXml host port user password <domain>"); System.exit(1); } org.apache.log4j.BasicConfigurator.configure(); // DEBUG, INFO, ERROR org.apache.log4j.Logger.getRootLogger().setLevel(org.apache.log4j.Level.DEBUG); String endpointName = args[0]; // "server" String endpointMethod = args[1]; // "getServerAttributes" String adapterConfigPath = args[2]; // E:\dev\Workspaces\PDToolGitTest\PDTool_poc\resources\config\6.2.0\cis_adapter_config.xml String requestXMLPath = args[3]; // path to request xml Properties props = new Properties(); props.setProperty(AdapterConstants.ADAPTER_HOST, args[4]); props.setProperty(AdapterConstants.ADAPTER_PORT, args[5]); props.setProperty(AdapterConstants.ADAPTER_USER, args[6]); props.setProperty(AdapterConstants.ADAPTER_PSWD, args[7]); if (args.length == 9) props.setProperty(AdapterConstants.ADAPTER_DOMAIN, args[8]); // Read the request xml file FileInputStream input = new FileInputStream(requestXMLPath); byte[] fileData = new byte[input.available()]; input.read(fileData); input.close(); String requestXml = new String(fileData, "UTF-8"); // Execute the CIS Web Service Client for an adapter configuration CisWsClient cisclient = new CisWsClient(props, adapterConfigPath); System.out.println("Request: " + requestXml); // String requestXml = "<?xml version=\"1.0\"?> <p1:ServerAttributeModule xmlns:p1=\"http://www.dvbu.cisco.com/ps/deploytool/modules\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.dvbu.cisco.com/ps/deploytool/modules file:///e:/dev/Workspaces/PDToolGitTest/PDToolModules/schema/PDToolModules.xsd\"> <!--Element serverAttribute, maxOccurs=unbounded--> <serverAttribute> <id>sa1</id> <name>/server/event/generation/sessions/sessionLoginFail</name> <type>UNKNOWN</type> <!--Element value is optional--> <value>string</value> <!--Element valueArray is optional--> <valueArray> <!--Element item is optional, maxOccurs=unbounded--> <item>string</item> <item>string</item> <item>string</item> </valueArray> <!--Element valueList is optional--> <valueList> <!--Element item is optional, maxOccurs=unbounded--> <item> <!--Element type is optional--> <type>UNKNOWN</type> <!--Element value is optional--> <value>string</value> </item> <item> <!--Element type is optional--> <type>UNKNOWN</type> <!--Element value is optional--> <value>string</value> </item> <item> <!--Element type is optional--> <type>UNKNOWN</type> <!--Element value is optional--> <value>string</value> </item> </valueList> <!--Element valueMap is optional--> <valueMap> <!--Element entry is optional, maxOccurs=unbounded--> <entry> <!--Element key is optional--> <key> <!--Element type is optional--> <type>UNKNOWN</type> <!--Element value is optional--> <value>string</value> </key> <!--Element value is optional--> <value> <!--Element type is optional--> <type>UNKNOWN</type> <!--Element value is optional--> <value>string</value> </value> </entry> <entry> <!--Element key is optional--> <key> <!--Element type is optional--> <type>UNKNOWN</type> <!--Element value is optional--> <value>string</value> </key> <!--Element value is optional--> <value> <!--Element type is optional--> <type>UNKNOWN</type> <!--Element value is optional--> <value>string</value> </value> </entry> <entry> <!--Element key is optional--> <key> <!--Element type is optional--> <type>UNKNOWN</type> <!--Element value is optional--> <value>string</value> </key> <!--Element value is optional--> <value> <!--Element type is optional--> <type>UNKNOWN</type> <!--Element value is optional--> <value>string</value> </value> </entry> </valueMap> </serverAttribute> </p1:ServerAttributeModule>"; String response = cisclient.sendRequest(endpointName, endpointMethod, requestXml); System.out.println("Response: " + response); }
From source file:com.dlmu.heipacker.crawler.client.ClientCustomSSL.java
public final static void main(String[] args) throws Exception { DefaultHttpClient httpclient = new DefaultHttpClient(); try {/*from w w w. ja v a 2 s . co m*/ KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); FileInputStream instream = new FileInputStream(new File("my.keystore")); try { trustStore.load(instream, "nopassword".toCharArray()); } finally { try { instream.close(); } catch (Exception ignore) { } } SSLSocketFactory socketFactory = new SSLSocketFactory(trustStore); Scheme sch = new Scheme("https", 443, socketFactory); httpclient.getConnectionManager().getSchemeRegistry().register(sch); HttpGet httpget = new HttpGet("https://localhost/"); System.out.println("executing request" + httpget.getRequestLine()); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); if (entity != null) { System.out.println("Response content length: " + entity.getContentLength()); } EntityUtils.consume(entity); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpclient.getConnectionManager().shutdown(); } }
From source file:Main.java
public static void main(String[] args) throws Exception { Connection conn = null;/*from w w w. j a v a2s . co m*/ PreparedStatement pstmt = null; Statement stmt = null; ResultSet rs = null; Class.forName(JDBC_DRIVER); conn = DriverManager.getConnection(DB_URL, USER, PASS); stmt = conn.createStatement(); createXMLTable(stmt); File f = new File("build.xml"); long fileLength = f.length(); FileInputStream fis = new FileInputStream(f); String SQL = "INSERT INTO XML_Data VALUES (?,?)"; pstmt = conn.prepareStatement(SQL); pstmt.setInt(1, 100); pstmt.setAsciiStream(2, fis, (int) fileLength); pstmt.execute(); fis.close(); SQL = "SELECT Data FROM XML_Data WHERE id=100"; rs = stmt.executeQuery(SQL); if (rs.next()) { InputStream xmlInputStream = rs.getAsciiStream(1); int c; ByteArrayOutputStream bos = new ByteArrayOutputStream(); while ((c = xmlInputStream.read()) != -1) bos.write(c); System.out.println(bos.toString()); } rs.close(); stmt.close(); pstmt.close(); conn.close(); }
From source file:MainClass.java
public static void main(String[] args) { File originFile = new File("c:\\file1.txt"); File destinationFile = new File("c:\\file1.txt"); if (!originFile.exists() || destinationFile.exists()) { return;/*from w ww . ja v a2 s .c om*/ } try { byte[] readData = new byte[1024]; FileInputStream fis = new FileInputStream(originFile); FileOutputStream fos = new FileOutputStream(destinationFile); int i = fis.read(readData); while (i != -1) { fos.write(readData, 0, i); i = fis.read(readData); } fis.close(); fos.close(); } catch (IOException e) { System.out.println(e); } }
From source file:MainClass.java
public static void main(String[] args) throws IOException { if (args.length != 3) { System.out.println("Usage: java TeeCopier infile outfile1 outfile2"); return;//www. j a v a 2s. com } FileInputStream fin = new FileInputStream(args[0]); FileOutputStream fout1 = new FileOutputStream(args[1]); FileOutputStream fout2 = new FileOutputStream(args[2]); MyOutputStream tout = new MyOutputStream(fout1, fout2); copy(fin, tout); fin.close(); tout.close(); }
From source file:ddu.core.httpclient.ClientCustomSSL.java
public final static void main(String[] args) throws Exception { // Trust own CA and all self-signed certs KeyStore trustKeyStore = KeyStore.getInstance("JKS"); // get user password and file input stream char[] password = "123456".toCharArray(); java.io.FileInputStream fis = null; try {//from ww w . j av a2 s . co m fis = new java.io.FileInputStream("keyStoreName"); trustKeyStore.load(fis, password); } finally { if (fis != null) { fis.close(); } } SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(trustKeyStore, new TrustSelfSignedStrategy()) .build(); // Allow TLSv1 protocol only SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build(); try { HttpGet httpget = new HttpGet("https://httpbin.org/"); System.out.println("Executing request " + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { HttpEntity entity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); EntityUtils.consume(entity); } finally { response.close(); } } finally { httpclient.close(); } }
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);//from w ww . j a v a 2 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(3); 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(); }