Example usage for java.io FileInputStream close

List of usage examples for java.io FileInputStream close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closes this file input stream and releases any system resources associated with the stream.

Usage

From source file:ShowFile.java

public static void main(String args[]) throws IOException {
    int i;//  w  w  w.  j  a  v a2  s . c o m
    FileInputStream fin;

    try {
        fin = new FileInputStream(args[0]);
    } catch (FileNotFoundException e) {
        System.out.println("File Not Found");
        return;
    } catch (ArrayIndexOutOfBoundsException e) {
        System.out.println("Usage: ShowFile File");
        return;
    }
    do {
        i = fin.read();
        if (i != -1)
            System.out.print((char) i);
    } while (i != -1);

    fin.close();
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    CertificateFactory cf = CertificateFactory.getInstance("X.509");
    FileInputStream in = new FileInputStream(args[0]);
    X509CRL crl = (X509CRL) cf.generateCRL(in);
    System.out.println("type = " + crl.getType());
    System.out.println("version = " + crl.getVersion());
    System.out.println("issuer = " + crl.getIssuerDN().getName());
    System.out.println("signing algorithm = " + crl.getSigAlgName());
    System.out.println("this update = " + crl.getThisUpdate());
    System.out.println("next update = " + crl.getNextUpdate());
    in.close();
}

From source file:NIOCopy.java

public static void main(String args[]) throws Exception {
    FileInputStream fIn;
    FileOutputStream fOut;//w ww.j av a 2 s.c o m
    FileChannel fIChan, fOChan;
    long fSize;
    MappedByteBuffer mBuf;

    fIn = new FileInputStream(args[0]);
    fOut = new FileOutputStream(args[1]);

    fIChan = fIn.getChannel();
    fOChan = fOut.getChannel();
    fSize = fIChan.size();

    mBuf = fIChan.map(FileChannel.MapMode.READ_ONLY, 0, fSize);
    fOChan.write(mBuf); // this copies the file
    fIChan.close();
    fIn.close();

    fOChan.close();
    fOut.close();
}

From source file:com.estafeta.flujos.DemoMain.java

/**
 * Clase principal del proyecto//w w w.j a  v a 2  s  . c o m
 * @param args argumentos de linea de comandos
 */
public static void main(String[] args) {
    // init spring context
    ApplicationContext ctx = new ClassPathXmlApplicationContext(APPLOCATION_CONTEXT_FILE);
    // get bean from context
    JmsMessageSender jmsMessageSender = (JmsMessageSender) ctx.getBean(JMS_MESSAGE_SENDER_BEAN_NAME);
    // send to a code specified destination
    Queue queue = new ActiveMQQueue(JMS_DESTINATION_NAME);
    try {
        ClassLoader classLoader = DemoMain.class.getClassLoader();
        FileInputStream fileInputStream = new FileInputStream(
                classLoader.getResource(MOCK_INPUT_FILE).getFile());
        BufferedReader bufferedReader = new BufferedReader(
                new InputStreamReader(fileInputStream, Charset.forName(UTF_8_CHARSET)));
        String line;
        while ((line = bufferedReader.readLine()) != null) {
            jmsMessageSender.send(queue, line);
        }
        fileInputStream.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    // close spring application context
    ((ClassPathXmlApplicationContext) ctx).close();
}

From source file:MainClass.java

public static void main(String args[]) {
    FileInputStream fIn;
    FileChannel fChan;/*ww w  . j  av  a  2  s .c o m*/
    long fSize;
    ByteBuffer mBuf;

    try {
        fIn = new FileInputStream("test.txt");

        fChan = fIn.getChannel();

        fSize = fChan.size();

        mBuf = ByteBuffer.allocate((int) fSize);

        fChan.read(mBuf);

        mBuf.rewind();

        for (int i = 0; i < fSize; i++)
            System.out.print((char) mBuf.get());
        fChan.close();
        fIn.close();
    } catch (IOException exc) {
        System.out.println(exc);
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    FileInputStream is = new FileInputStream("yourfile" + ".keystore");
    KeyStore keystore = KeyStore.getInstance(KeyStore.getDefaultType());
    String password = "my-keystore-password";
    keystore.load(is, password.toCharArray());

    Enumeration e = keystore.aliases();
    for (; e.hasMoreElements();) {
        String alias = (String) e.nextElement();

        boolean b = keystore.isKeyEntry(alias);

        b = keystore.isCertificateEntry(alias);
    }//from w w w .  jav a 2s .  co m
    is.close();
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    File aFile = new File("C:/test.bin");
    FileInputStream inFile = new FileInputStream(aFile);
    FileChannel inChannel = inFile.getChannel();
    final int PRIMECOUNT = 6;
    ByteBuffer buf = ByteBuffer.allocate(8 * PRIMECOUNT);
    long[] primes = new long[PRIMECOUNT];
    while (inChannel.read(buf) != -1) {
        ((ByteBuffer) (buf.flip())).asLongBuffer().get(primes);
        for (long prime : primes) {
            System.out.printf("%10d", prime);
        }/*from   w  ww .  ja  v  a  2  s .c  o m*/
        buf.clear();
    }
    inFile.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    FileInputStream fileIn = new FileInputStream("data.txt");
    DataInputStream dataIn = new DataInputStream(fileIn);
    System.out.println(dataIn.readUTF());
    int counter = dataIn.readInt();
    double sum = 0.0;
    for (int i = 0; i < counter; i++) {
        double current = dataIn.readDouble();
        System.out.println("Just read " + current);
        sum += current;//from  w  w  w.  j av  a  2  s  . c om
    }
    System.out.println("\nAverage = " + sum / counter);
    dataIn.close();
    fileIn.close();
}

From source file:com.opengamma.batch.BatchJobRunner.java

/**
 * Creates an runs a batch job based on a properties file and configuration.
 *//* ww w  .  j a  va 2s  .  c o  m*/
public static void main(String[] args) throws Exception { // CSIGNORE
    if (args.length == 0) {
        usage();
        System.exit(-1);
    }

    CommandLine line = null;
    Properties configProperties = null;

    final String propertyFile = "batchJob.properties";

    String configPropertyFile = null;

    if (System.getProperty(propertyFile) != null) {
        configPropertyFile = System.getProperty(propertyFile);
        try {
            FileInputStream fis = new FileInputStream(configPropertyFile);
            configProperties = new Properties();
            configProperties.load(fis);
            fis.close();
        } catch (FileNotFoundException e) {
            s_logger.error("The system cannot find " + configPropertyFile);
            System.exit(-1);
        }
    } else {
        try {
            FileInputStream fis = new FileInputStream(propertyFile);
            configProperties = new Properties();
            configProperties.load(fis);
            fis.close();
            configPropertyFile = propertyFile;
        } catch (FileNotFoundException e) {
            // there is no config file so we expect command line arguments
            try {
                CommandLineParser parser = new PosixParser();
                line = parser.parse(getOptions(), args);
            } catch (ParseException e2) {
                usage();
                System.exit(-1);
            }
        }
    }

    RunCreationMode runCreationMode = getRunCreationMode(line, configProperties, configPropertyFile);
    if (runCreationMode == null) {
        // default
        runCreationMode = RunCreationMode.AUTO;
    }

    String engineURI = getProperty("engineURI", line, configProperties, configPropertyFile);

    String brokerURL = getProperty("brokerURL", line, configProperties, configPropertyFile);

    Instant valuationTime = getValuationTime(line, configProperties, configPropertyFile);
    LocalDate observationDate = getObservationDate(line, configProperties, configPropertyFile);

    UniqueId viewDefinitionUniqueId = getViewDefinitionUniqueId(line, configProperties);

    URI vpBase;
    try {
        vpBase = new URI(engineURI);
    } catch (URISyntaxException ex) {
        throw new OpenGammaRuntimeException("Invalid URI", ex);
    }

    ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(brokerURL);
    activeMQConnectionFactory.setWatchTopicAdvisories(false);

    JmsConnectorFactoryBean jmsConnectorFactoryBean = new JmsConnectorFactoryBean();
    jmsConnectorFactoryBean.setConnectionFactory(activeMQConnectionFactory);
    jmsConnectorFactoryBean.setName("Masters");

    JmsConnector jmsConnector = jmsConnectorFactoryBean.getObjectCreating();
    ScheduledExecutorService heartbeatScheduler = Executors.newSingleThreadScheduledExecutor();
    try {
        ViewProcessor vp = new RemoteViewProcessor(vpBase, jmsConnector, heartbeatScheduler);
        ViewClient vc = vp.createViewClient(UserPrincipal.getLocalUser());

        HistoricalMarketDataSpecification marketDataSpecification = MarketData.historical(observationDate,
                null);

        ViewExecutionOptions executionOptions = ExecutionOptions.batch(valuationTime, marketDataSpecification,
                null);

        vc.attachToViewProcess(viewDefinitionUniqueId, executionOptions);
        vc.waitForCompletion();
    } finally {
        heartbeatScheduler.shutdown();
    }
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    File file = new File("myimage.gif");
    FileInputStream fis = new FileInputStream(file);
    Class.forName("oracle.jdbc.driver.OracleDriver");
    Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@//server.local:1521/prod", "scott",
            "tiger");
    conn.setAutoCommit(false);//from   ww w.ja  v a2  s  .com
    PreparedStatement ps = conn.prepareStatement("insert into images values (?,?)");
    ps.setString(1, file.getName());
    ps.setBinaryStream(2, fis, (int) file.length());
    ps.executeUpdate();
    ps.close();
    fis.close();

}