@Override public InputStream create(String entry) throws IOException { return new TFileInputStream(entry); } });
public static ClassFile readFile(TFile file) { try { TFileInputStream tFileInputStream = new TFileInputStream(file); return readFromInputStream(tFileInputStream); } catch (FileNotFoundException e) { throw new IllegalArgumentException("Could not find file: " + file, e); } catch (IOException e) { throw new IllegalStateException("Could not read file: " + file, e); } }
@Override public void importProjects(File file) throws FileNotFoundException, IOException { Map<String, Map<String, GenericEntity<Long, ?>>> idsMapping = new HashMap<String, Map<String, GenericEntity<Long, ?>>>(); Workbook workbook = new HSSFWorkbook(new TFileInputStream(file)); doImportItem(idsMapping, workbook, Project.class); doImportItem(idsMapping, workbook, ProjectVersion.class); }
/** * Constructs a new {@code TFile} reader. * * @param file a file to read. * @param decoder a decoder for decoding bytes to characters. * @throws FileNotFoundException on any I/O failure. */ @CreatesObligation @edu.umd.cs.findbugs.annotations.SuppressWarnings("OBL_UNSATISFIED_OBLIGATION") public TFileReader(File file, CharsetDecoder decoder) throws FileNotFoundException { super(new TFileInputStream(file), decoder); }
/** * Constructs a new {@code TFile} reader. * <p> * TODO: Remove this redundant constructor in TrueZIP 8. * * @param file a file to read. * @param decoder a decoder for decoding bytes to characters. * @throws FileNotFoundException on any I/O failure. */ @CreatesObligation @edu.umd.cs.findbugs.annotations.SuppressWarnings("OBL_UNSATISFIED_OBLIGATION") public TFileReader(TFile file, CharsetDecoder decoder) throws FileNotFoundException { super(new TFileInputStream(file), decoder); }
/** * Constructs a new {@code TFile} reader. * * @param file a file to read. * @param charset a character set for decoding bytes to characters. * @throws FileNotFoundException on any I/O failure. * @since TrueZIP 7.5 */ @CreatesObligation @edu.umd.cs.findbugs.annotations.SuppressWarnings("OBL_UNSATISFIED_OBLIGATION") public TFileReader(File file, Charset charset) throws FileNotFoundException { super(new TFileInputStream(file), charset); }
/** * Constructs a new {@code TFile} reader. * This reader uses the default character set for decoding bytes to * characters. * * @param file a file to read. * @throws FileNotFoundException on any I/O failure. */ @CreatesObligation @edu.umd.cs.findbugs.annotations.SuppressWarnings({ "DM_DEFAULT_ENCODING", "OBL_UNSATISFIED_OBLIGATION" }) public TFileReader(File file) throws FileNotFoundException { super(new TFileInputStream(file)); }
/** * Constructs a new {@code TFile} reader. * This reader uses the default character set for decoding bytes to * characters. * <p> * TODO: Remove this redundant constructor in TrueZIP 8. * * @param file a file to read. * @throws FileNotFoundException on any I/O failure. */ @CreatesObligation @edu.umd.cs.findbugs.annotations.SuppressWarnings({ "DM_DEFAULT_ENCODING", "OBL_UNSATISFIED_OBLIGATION" }) public TFileReader(TFile file) throws FileNotFoundException { super(new TFileInputStream(file)); }
private void cat(final String[] args) throws IllegalUsageException, IOException { if (args.length < 1) throw new IllegalUsageException(); for (int i = 0; i < args.length; i++) { final InputStream in = new TFileInputStream(args[i]); try { TFile.cat(in, out); } finally { in.close(); } } }
/** * Finds a single attribute from a war manifest file. * @param war the war * @return Manifest * @throws ModuleManagementToolException */ @Override public Manifest findManifest(TFile war) throws ModuleManagementToolException { InputStream is = null; try { is = new TFileInputStream(war+MANIFEST_FILE); Manifest manifest = new Manifest(is); return manifest; } catch (IOException e) { throw new ModuleManagementToolException("Unabled to read a manifest for the war file: "+ war); } finally { if (is != null) { try { is.close(); } catch (Throwable e ) {} } } }
/** * Finds a single attribute from a war manifest file. * @param war the war * @return Manifest * @throws ModuleManagementToolException */ @Override public Manifest findManifest(TFile war) throws ModuleManagementToolException { InputStream is = null; try { is = new TFileInputStream(war+MANIFEST_FILE); Manifest manifest = new Manifest(is); return manifest; } catch (IOException e) { throw new ModuleManagementToolException("Unabled to read a manifest for the war file: "+ war); } finally { if (is != null) { try { is.close(); } catch (Throwable e ) {} } } }
@SuppressFBWarnings("OS_OPEN_STREAM") final byte[] read(final Node node) throws IOException { final File file = node.file(); final byte[] code; { final long l = file.length(); final int mb = ctx.maxBytes(); if (l > mb) throw new IOException( String.format("%s (%,d bytes exceeds max %,d bytes)", file, l, mb)); code = new byte[(int) l]; } { final InputStream in = new TFileInputStream(file); try { new DataInputStream(in).readFully(code); } finally { in.close(); } } return code; }
protected ScreenshotMeta loadMeta(final TFile file) throws IOException { ScreenshotMeta meta; TFileInputStream in = new TFileInputStream(file); try { meta = ScreenshotMeta.load(in); } finally { in.close(); } return meta; }
public InputStream getInputStream(final String filepath) throws IOException { return new TFileInputStream(new TFile(archive, filepath)); }
is = new TFileInputStream(propertiesFile); result = new Properties(); result.load(is);
void cat1(String path) throws IOException { // START SNIPPET: cat1 InputStream in = new TFileInputStream(path); try { TFile.cat(in, System.out); } finally { in.close(); // ALWAYS close the stream! } // END SNIPPET: cat1 }
void cat2(String path) { // START SNIPPET: cat2 try { InputStream in = new TFileInputStream(path); try { TFile.cat(in, System.out); } finally { in.close(); // ALWAYS close the stream! } } catch (IOException ouch) { ouch.printStackTrace(); } // END SNIPPET: cat2 }
private void checkContentsOfFile(String location, String expectedContents) throws IOException { File file = new TFile(location); assertTrue(file.exists()); BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(new TFileInputStream(file))); String line = reader.readLine(); assertNotNull(line); assertEquals(expectedContents, line.trim()); } finally { if (reader != null) { try { reader.close(); } catch (Throwable e ) {} } } } }
private void roundTrip() throws IOException { final TFile file = new TFile(archive, "entry"); final OutputStream os = new TFileOutputStream(file); try { os.write(data); } finally { os.close(); } final ByteArrayOutputStream baos = new ByteArrayOutputStream(data.length); final InputStream is = new TFileInputStream(file); try { TFile.cat(is, baos); } finally { is.close(); } Arrays.equals(data, baos.toByteArray()); } }
protected final void verifyTestFile(final TFile file) throws IOException { assertEquals(getDataLength(), file.length()); final byte[] array = new byte[getDataLength()]; final InputStream in = new TFileInputStream(file); try { new DataInputStream(in).readFully(array); } finally { in.close(); } assertArrayEquals(getData(), array); }