public static String readTxt(File file, String charsetName) throws IOException { FileInputStream is = new FileInputStream(file); byte[] targetArray = new byte[is.available()]; int len; int off = 0; while ((len = is.read(targetArray, off, targetArray.length - off)) != -1 && off < targetArray.length) { off += len; } is.close(); return new String(targetArray, charsetName); }
public static long getFileSizes(File f) { if (f == null) { return 0; } long size = 0; if (f.exists() && f.isFile()) { FileInputStream fis = null; try { fis = new FileInputStream(f); size = fis.available(); } catch (IOException e) { e.printStackTrace(); } finally { try { if (fis != null) { fis.close(); } } catch (IOException e) { e.printStackTrace(); } } } return size; }
FileInputStream is = new FileInputStream(new File(_serverCACertFile)); KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null); CertificateFactory certificateFactory = CertificateFactory.getInstance(CERTIFICATE_TYPE); int i = 0; while (is.available() > 0) { X509Certificate cert = (X509Certificate) certificateFactory.generateCertificate(is); LOGGER.info("Read certificate serial number {} by issuer {} ", cert.getSerialNumber().toString(16),
@Test public void testToString_InputStream() throws Exception { try (FileInputStream fin = new FileInputStream(m_testFile)) { final String out = IOUtils.toString(fin); assertNotNull(out); assertEquals("Not all bytes were read", 0, fin.available()); assertEquals("Wrong output size", FILE_SIZE, out.length()); } }
@Override public void run() { try { byte[] keychainBytes; FileInputStream is = null; try { is = new FileInputStream(CERTIFICATE_RESOURCE); keychainBytes = new byte[is.available()]; is.read(keychainBytes); } finally { IOUtils.closeQuietly(is); } Intent intent = KeyChain.createInstallIntent(); intent.putExtra(KeyChain.EXTRA_CERTIFICATE, keychainBytes); intent.putExtra(KeyChain.EXTRA_NAME, "NetworkDiagnosis CA Certificate"); startActivityForResult(intent, 3); } catch (Exception e) { e.printStackTrace(); } } };
vocabSize = 0; final File trainFile = new File(config.getInputFile()); try fileInputStream = new FileInputStream(trainFile); raf = new BufferedReader(new InputStreamReader(fileInputStream, encoding)); cacheFile = File.createTempFile(String.format("corpus_%d", System.currentTimeMillis()), ".bin"); (1.f - fileInputStream.available() / (float) trainFile.length()) * 100.f, trainWords / 1000); System.err.flush(); callback.corpusLoading((1.f - fileInputStream.available() / (float) trainFile.length()) * 100.f);
@Test public void testToByteArray_InputStream_Size() throws Exception { try (FileInputStream fin = new FileInputStream(m_testFile)) { final byte[] out = IOUtils.toByteArray(fin, m_testFile.length()); assertNotNull(out); assertEquals("Not all bytes were read", 0, fin.available()); assertEquals("Wrong output size: out.length=" + out.length + "!=" + FILE_SIZE, FILE_SIZE, out.length); TestUtils.assertEqualContent(out, m_testFile); } }
FileInputStream fis = new FileInputStream(infoFile); if (fis.available() == 0) { throw new GemFireIOException( String.format( fis.close(); return result; } catch (IOException io) {
@Override public void run() { try { byte[] keychainBytes; FileInputStream is = null; try { is = new FileInputStream(CERTIFICATE_RESOURCE); keychainBytes = new byte[is.available()]; is.read(keychainBytes); } finally { IOUtils.closeQuietly(is); } Intent intent = KeyChain.createInstallIntent(); intent.putExtra(KeyChain.EXTRA_CERTIFICATE, keychainBytes); intent.putExtra(KeyChain.EXTRA_NAME, "NetworkDiagnosis CA Certificate"); startActivityForResult(intent, 3); } catch (Exception e) { e.printStackTrace(); } } };
FileInputStream fileInputStream = new FileInputStream(new File(existingFileName)); URL url = new URL(urlString); conn = (HttpURLConnection) url.openConnection(); dos.writeBytes(lineEnd); bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); buffer = new byte[bufferSize]; bytesRead = fileInputStream.read(buffer, 0, bufferSize); bytesAvailable = fileInputStream.available(); bufferSize = Math.min(bytesAvailable, maxBufferSize); bytesRead = fileInputStream.read(buffer, 0, bufferSize); fileInputStream.close(); dos.flush(); dos.close();
File f = new File("your audio file.wav"); FileInputStream fis = new FileInputStream(f); AudioInputStream ais = AudioSystem.getAudioInputStream(f); // prints the number of bytes that are detected not to be audio data System.out.println(fis.available() - ais.available());
@Test public void testToByteArray_InputStream() throws Exception { try (FileInputStream fin = new FileInputStream(m_testFile)) { final byte[] out = IOUtils.toByteArray(fin); assertNotNull(out); assertEquals("Not all bytes were read", 0, fin.available()); assertEquals("Wrong output size", FILE_SIZE, out.length); TestUtils.assertEqualContent(out, m_testFile); } }
private long getLogFileSize() { long j = -1; if (this.mFile == null) { return -1; } try { FileInputStream fileInputStream = new FileInputStream(this.mFile); j = (long) fileInputStream.available(); fileInputStream.close(); return j; } catch (Exception e) { return j; } } }
printInfo(verbose, ""); FileInputStream fileInputStream = new FileInputStream(dataFile); byte[] currentNumberOfKeys = new byte[2], currentKeySize = new byte[ByteUtils.SIZE_OF_INT], valueSize; short numberOfKeys = 0; while (fileInputStream.available() > 0) { keysRead++; fileInputStream.read(currentNumberOfKeys); numberOfKeys = ByteBuffer.wrap(currentNumberOfKeys).getShort(); if (numberOfKeys > 1) { fileInputStream.read(currentKeySize); fileInputStream.read(currentValueSize);
private static String getLyricsMP4(File file) throws Exception{ FileInputStream in = new FileInputStream(file); in.read(head); int len = byteArrayToInt(head); in.read(head); if (!Arrays.equals(head, new byte[]{'f','t','y','p'})){ in.close(); return null; outter: for(byte[] atom: path){ while(in.available()>0){ byte buffer[] = new byte[4]; in.read(buffer); len = byteArrayToInt(buffer); if(len==0)continue; in.read(buffer); if(len>atom_size){ in.close(); return null; in.close(); return null;
@Override public void onInit(int size) { super.onInit(size); try { fis = new FileInputStream(new File(filePath)); } catch (FileNotFoundException e) { e.printStackTrace(); } try { fis.mark(fis.available()); } catch (IOException e) { } bgm = new byte[SIZE]; }
input = new FileInputStream(filename); } catch (FileNotFoundException e) { log.error("The file at {} does not exist", data.getFilename()); IoBuffer buf = IoBuffer.allocate(input.available()); try { ServletUtils.copy(input, buf.asOutputStream());