List of usage examples for java.nio.file StandardOpenOption READ
StandardOpenOption READ
To view the source code for java.nio.file StandardOpenOption READ.
Click Source Link
From source file:de.dentrassi.pm.rpm.internal.RpmExtractor.java
@Override public void extractMetaData(final Context context, final Map<String, String> metadata) throws Exception { final Path path = context.getPath(); try (RpmInputStream in = new RpmInputStream( new BufferedInputStream(Files.newInputStream(path, StandardOpenOption.READ)))) { final RpmInformation info = makeInformation(in); if (info == null) { return; }//from w w w . j a va 2 s . c o m metadata.put("artifactLabel", "RPM Package"); metadata.put("name", asString(in.getPayloadHeader().getTag(RpmTag.NAME))); metadata.put("version", asString(in.getPayloadHeader().getTag(RpmTag.VERSION))); metadata.put("os", asString(in.getPayloadHeader().getTag(RpmTag.OS))); metadata.put("arch", asString(in.getPayloadHeader().getTag(RpmTag.ARCH))); metadata.put(Constants.KEY_INFO.getKey(), info.toJson()); } }
From source file:com.ignorelist.kassandra.steam.scraper.PathResolver.java
public Set<Path> findAllLibraryDirectories() throws IOException, RecognitionException { Path steamApps = findSteamApps(); Set<Path> libraryDirectories = new LinkedHashSet<>(); libraryDirectories.add(steamApps);// ww w. j a va 2 s. co m Path directoryDescriptor = steamApps.resolve("libraryfolders.vdf"); if (Files.exists(directoryDescriptor)) { InputStream vdfStream = Files.newInputStream(directoryDescriptor, StandardOpenOption.READ); VdfRoot vdfRoot = VdfParser.parse(vdfStream); IOUtils.closeQuietly(vdfStream); final VdfNode nodeLibrary = Iterables.getFirst(vdfRoot.getChildren(), null); if (null != nodeLibrary) { for (VdfAttribute va : nodeLibrary.getAttributes()) { //System.err.println(va); try { Integer.parseInt(va.getName()); Path libraryDirectory = Paths.get(va.getValue()); libraryDirectories.add(resolveAppsDirectory(libraryDirectory)); } catch (NumberFormatException nfe) { } catch (IllegalStateException ise) { System.err.println(ise); } } } } return libraryDirectories; }
From source file:org.eclipse.packagedrone.repo.adapter.rpm.internal.RpmExtractor.java
@Override public void extractMetaData(final Context context, final Map<String, String> metadata) { final Path path = context.getPath(); try (RpmInputStream in = new RpmInputStream( new BufferedInputStream(Files.newInputStream(path, StandardOpenOption.READ)))) { final RpmInformation info = makeInformation(in); if (info == null) { return; }// w w w. j a v a2s. c o m metadata.put("artifactLabel", "RPM Package"); metadata.put("name", asString(in.getPayloadHeader().getTag(RpmTag.NAME))); metadata.put("version", asString(in.getPayloadHeader().getTag(RpmTag.VERSION))); metadata.put("os", asString(in.getPayloadHeader().getTag(RpmTag.OS))); metadata.put("arch", asString(in.getPayloadHeader().getTag(RpmTag.ARCH))); metadata.put(Constants.KEY_INFO.getKey(), info.toJson()); } catch (final Exception e) { // ignore ... not an RPM file } }
From source file:onl.area51.httpd.util.PathEntity.java
@Override public InputStream getContent() throws IOException { return Files.newInputStream(file, StandardOpenOption.READ); }
From source file:hrytsenko.csv.IO.java
/** * Gets records from file.//from w ww . j a v a 2 s . c o m * * <p> * If closure is given, then it will be applied to each record. * * @param args * the named arguments {@link IO}. * @param closure * the closure to be applied to each record. * * @return the loaded records. * * @throws IOException * if file could not be read. */ public static List<Record> load(Map<String, ?> args, Closure<?> closure) throws IOException { Path path = getPath(args); LOGGER.info("Load: {}.", path.getFileName()); try (InputStream dataStream = newInputStream(path, StandardOpenOption.READ); InputStream bomStream = new BOMInputStream(dataStream); Reader dataReader = new InputStreamReader(bomStream, getCharset(args))) { CsvSchema csvSchema = getSchema(args).setUseHeader(true).build(); CsvMapper csvMapper = new CsvMapper(); ObjectReader csvReader = csvMapper.reader(Map.class).with(csvSchema); Iterator<Map<String, String>> rows = csvReader.readValues(dataReader); List<Record> records = new ArrayList<>(); while (rows.hasNext()) { Map<String, String> row = rows.next(); Record record = new Record(); record.putAll(row); records.add(record); if (closure != null) { closure.call(record); } } return records; } }
From source file:com.reactive.hzdfs.io.MemoryMappedChunkHandler.java
/** * Read mode.//from ww w .java 2 s . com * @param f * @param chunkSize * @throws IOException */ public MemoryMappedChunkHandler(File f, int chunkSize) throws IOException { super(f); iStream = FileChannel.open(file.toPath(), StandardOpenOption.READ); readSize = chunkSize; chunks = fileSize % readSize == 0 ? (int) ((fileSize / readSize)) : (int) ((fileSize / readSize) + 1); mapBuff = iStream.map(MapMode.READ_ONLY, 0, getFileSize()); if (log.isDebugEnabled()) { debugInitialParams(); log.debug("Reading source file. Expected chunks to send- " + chunks); } }
From source file:com.ignorelist.kassandra.steam.scraper.SharedConfig.java
public synchronized VdfRoot getRootNode() throws IOException, RecognitionException { if (null == rootNode) { InputStream inputStream = Files.newInputStream(path, StandardOpenOption.READ); try {//from w w w .j a va2 s .c o m rootNode = VdfParser.parse(inputStream); } finally { IOUtils.closeQuietly(inputStream); } } return rootNode; }
From source file:org.cloudfoundry.dependency.resource.InAction.java
private String getSha256(Path artifact) throws IOException { try (InputStream in = Files.newInputStream(artifact, StandardOpenOption.READ)) { return DigestUtils.sha256Hex(in); }//from w ww .j ava2s. c o m }
From source file:org.kalypso.kalypsosimulationmodel.core.wind.BinaryGeoGridWrapperForPairsModel.java
/** * Opens an existing grid.<br>//from w w w.j a v a 2 s . c o m * Dispose the grid after it is no more needed in order to release the given resource. * * @param writeable * If <code>true</code>, the grid is opened for writing and a {@link IWriteableGeoGrid} is returned. */ public static BinaryGeoGridWrapperForPairsModel openGrid(final URL url, final Coordinate origin, final Coordinate offsetX, final Coordinate offsetY, final String sourceCRS, final boolean writeable) throws IOException { /* Tries to find a file from the given url. */ File fileFromUrl = ResourceUtilities.findJavaFileFromURL(url); File binFile = null; if (fileFromUrl == null) fileFromUrl = FileUtils.toFile(url); if (fileFromUrl == null) { /* * If url cannot be converted to a file, write its contents to a temporary file which will be deleted after the * grid gets disposed. */ fileFromUrl = File.createTempFile("local", ".bin"); //$NON-NLS-1$ //$NON-NLS-2$ fileFromUrl.deleteOnExit(); FileUtils.copyURLToFile(url, fileFromUrl); binFile = fileFromUrl; // set in order to delete on dispose } FileChannel channel; if (writeable) channel = FileChannel.open(fileFromUrl.toPath(), StandardOpenOption.WRITE, StandardOpenOption.READ); else channel = FileChannel.open(fileFromUrl.toPath(), StandardOpenOption.READ); return new BinaryGeoGridWrapperForPairsModel(channel, binFile, origin, offsetX, offsetY, sourceCRS); }
From source file:sf.net.experimaestro.fs.XPMFileSystemProvider.java
@Override public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException { final Path hostPathObject = resolvePath((XPMPath) path); SeekableByteChannel channel = Files.newByteChannel(hostPathObject, StandardOpenOption.READ); if (channel == null) { throw new IOException(format("Could not find a valid mount point for %s", path)); }//from w w w . ja v a2s . c om return channel; }