List of usage examples for java.io FileInputStream read
public int read(byte b[], int off, int len) throws IOException
len
bytes of data from this input stream into an array of bytes. From source file:CreateJarFile.java
protected void createJarArchive(File archiveFile, File[] tobeJared) { try {/*from www . j a v a 2 s .c o m*/ byte buffer[] = new byte[BUFFER_SIZE]; // Open archive file FileOutputStream stream = new FileOutputStream(archiveFile); JarOutputStream out = new JarOutputStream(stream, new Manifest()); for (int i = 0; i < tobeJared.length; i++) { if (tobeJared[i] == null || !tobeJared[i].exists() || tobeJared[i].isDirectory()) continue; // Just in case... System.out.println("Adding " + tobeJared[i].getName()); // Add archive entry JarEntry jarAdd = new JarEntry(tobeJared[i].getName()); jarAdd.setTime(tobeJared[i].lastModified()); out.putNextEntry(jarAdd); // Write file to archive FileInputStream in = new FileInputStream(tobeJared[i]); while (true) { int nRead = in.read(buffer, 0, buffer.length); if (nRead <= 0) break; out.write(buffer, 0, nRead); } in.close(); } out.close(); stream.close(); System.out.println("Adding completed OK"); } catch (Exception ex) { ex.printStackTrace(); System.out.println("Error: " + ex.getMessage()); } }
From source file:com.onedrive.api.support.SerializatorAccessTokenListener.java
public AccessToken onAccessTokenRequired(OneDrive reference) { File file = new File(getApplicationFolder(), getFileName(reference)); if (file.exists()) { try {//from w ww . j ava 2 s .c o m FileInputStream fis = new FileInputStream(file); byte[] b = new byte[(int) file.length()]; fis.read(b, 0, b.length); fis.close(); AccessToken accessToken = (AccessToken) SerializationUtils.deserialize(b); tokens.put(file.getName(), accessToken.getAccessToken()); System.out.println("Access Token Retrieved: " + file.getName()); return accessToken; } catch (Exception e) { e.printStackTrace(); } } return null; }