Example usage for java.io FileInputStream available

List of usage examples for java.io FileInputStream available

Introduction

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

Prototype

public int available() throws IOException 

Source Link

Document

Returns an estimate of the number of remaining bytes that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    try {//  w  ww . ja v a 2  s  .c  om
        String url = "jdbc:odbc:databaseName";
        String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
        String user = "guest";
        String password = "guest";
        FileInputStream fis = new FileInputStream("somefile.txt");
        Class.forName(driver);
        Connection connection = DriverManager.getConnection(url, user, password);
        Statement createTable = connection.createStatement();

        createTable.executeUpdate("CREATE TABLE source_code (name CHAR(20), source LONGTEXT)");

        String ins = "INSERT INTO source_code VALUES(?,?)";
        PreparedStatement statement = connection.prepareStatement(ins);

        statement.setString(1, "TryInputStream"); // Set first field
        statement.setAsciiStream(2, fis, fis.available()); // Stream is source

        int rowsUpdated = statement.executeUpdate();
        System.out.println("Rows affected: " + rowsUpdated);
        connection.close();
    } catch (Exception e) {
        System.err.println(e);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    try {//from   w w w .ja  v  a2s  .  co  m
        String url = "jdbc:odbc:yourdatabasename";
        String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
        String user = "guest";
        String password = "guest";

        FileInputStream fis = new FileInputStream("sometextfile.txt");

        Class.forName(driver);
        Connection connection = DriverManager.getConnection(url, user, password);
        Statement createTable = connection.createStatement();
        createTable.executeUpdate("CREATE TABLE source_code (name char(20), source LONGTEXT)");
        String ins = "INSERT INTO source_code VALUES(?,?)";
        PreparedStatement statement = connection.prepareStatement(ins);

        statement.setString(1, "TryInputStream2");
        statement.setAsciiStream(2, fis, fis.available());

        int rowsUpdated = statement.executeUpdate();
        System.out.println("Rows affected: " + rowsUpdated);
        Statement getCode = connection.createStatement();
        ResultSet theCode = getCode.executeQuery("SELECT name,source FROM source_code");
        BufferedReader reader = null;
        String input = null;

        while (theCode.next()) {
            reader = new BufferedReader(new InputStreamReader(theCode.getAsciiStream(2)));
            while ((input = reader.readLine()) != null) {
                System.out.println(input);
            }
        }
        connection.close();
    } catch (Exception e) {
        System.err.println(e);
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    try {/*w  w w.  j  a  v a  2s.c  o  m*/
        String url = "jdbc:odbc:yourdatabasename";
        String driver = "sun.jdbc.odbc.JdbcOdbcDriver";
        String user = "guest";
        String password = "guest";

        FileInputStream fis = new FileInputStream("sometextfile.txt");

        Class.forName(driver);
        Connection connection = DriverManager.getConnection(url, user, password);
        Statement createTable = connection.createStatement();
        createTable.executeUpdate("CREATE TABLE source_code (name char(20), source LONGTEXT)");
        String ins = "INSERT INTO source_code VALUES(?,?)";
        PreparedStatement statement = connection.prepareStatement(ins);

        statement.setString(1, "TryInputStream2");
        statement.setAsciiStream(2, fis, fis.available());

        int rowsUpdated = statement.executeUpdate();
        System.out.println("Rows affected: " + rowsUpdated);
        Statement getCode = connection.createStatement();
        ResultSet theCode = getCode.executeQuery("SELECT name,source FROM source_code");
        BufferedReader reader = null;
        String input = null;

        while (theCode.next()) {
            reader = new BufferedReader(new InputStreamReader(theCode.getAsciiStream("source")));
            while ((input = reader.readLine()) != null) {
                System.out.println(input);
            }
        }
        connection.close();
    } catch (Exception e) {
        System.err.println(e);
    }
}

From source file:io.nuclei.box.db.DbContext.java

public static void main(String[] args) throws IOException {
    FileInputStream input = new FileInputStream(args[0]);
    byte[] buf = new byte[input.available()];
    input.read(buf);/*from   w ww. j av a2 s.c o  m*/
    input.close();
    JSONObject model = new JSONObject(new String(buf, "UTF-8"));
    DbContext.newContext(model, new File(args[1]), null, null).render();
}

From source file:org.apache.nutch.parse.swf.SWFParser.java

/**
 * Arguments are: 0. Name of input SWF file.
 *//*from ww w .ja  va 2s .  co  m*/
public static void main(String[] args) throws IOException {
    FileInputStream in = new FileInputStream(args[0]);

    byte[] buf = new byte[in.available()];
    in.read(buf);
    SWFParser parser = new SWFParser();
    ParseResult parseResult = parser.getParse(new Content("file:" + args[0], "file:" + args[0], buf,
            "application/x-shockwave-flash", new Metadata(), NutchConfiguration.create()));
    Parse p = parseResult.get("file:" + args[0]);
    System.out.println("Parse Text:");
    System.out.println(p.getText());
    System.out.println("Parse Data:");
    System.out.println(p.getData());
}

From source file:org.eclipse.wst.wsi.internal.core.util.Utils.java

public static void main(String[] args) {
    try {//from  w w  w . j a v a 2  s.c o m
        FileInputStream inputStream = new FileInputStream("d:\\b.xml");
        int i = inputStream.available();
        byte[] buffer = new byte[i];
        inputStream.read(buffer);
        String message = new String(buffer);
        message = XMLUtils.xmlRemoveEscapedString(message);
        String headers = Utils.getHTTPHeaders(message);
        MimeParts parts = Utils.parseMultipartRelatedMessage(message, headers, Utils.JAVA_ENCODING_DEFAULT);
        System.out.println(Utils.toXMLString(parts));
    } catch (Exception e) {
    }
}

From source file:Main.java

public static String readSDFile(String fileName) throws IOException {

    File file = new File(fileName);

    FileInputStream fis = new FileInputStream(file);

    int length = fis.available();

    byte[] buffer = new byte[length];
    fis.read(buffer);/*  w  ww. ja  va2  s.c  om*/

    String res = EncodingUtils.getString(buffer, "UTF-8");

    fis.close();
    return res;
}

From source file:Main.java

public static byte[] getFileByte(File file) {
    if (!file.exists()) {
        return null;
    }/*ww  w .  ja  va 2 s.  c om*/
    try {
        FileInputStream fis = new FileInputStream(file);
        int len = fis.available();
        byte[] bytes = new byte[len];
        fis.read(bytes);
        fis.close();
        return bytes;
    } catch (Exception e) {

    }

    return null;
}

From source file:Main.java

public static int getFileSize(File file) {
    int size = 0;

    try {/*from   ww  w  .  ja v  a  2  s .  c  om*/
        FileInputStream fis = new FileInputStream(file);
        size = fis.available();
        fis.close();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return size;
}

From source file:Main.java

/**
 * @param fileName/*from w  w  w  . ja va2  s. c  o m*/
 */
public static String readFileByLines(String fileName) {
    String res = "";
    try {
        FileInputStream fin = new FileInputStream(fileName);
        int length = fin.available();
        byte[] buffer = new byte[length + 1024];
        fin.read(buffer);
        res = EncodingUtils.getString(buffer, "UTF-8");
        fin.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return res;
}