本文整理匯總了Java中java.util.stream.Stream.close方法的典型用法代碼示例。如果您正苦於以下問題:Java Stream.close方法的具體用法?Java Stream.close怎麽用?Java Stream.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.stream.Stream
的用法示例。
在下文中一共展示了Stream.close方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getItems
import java.util.stream.Stream; //導入方法依賴的package包/類
static final List<String> getItems(final String path, final String ext) throws URISyntaxException, IOException {
final List<String> itemFileNames = new ArrayList<>();
final URI uri = AssetLoader.class.getResource(path).toURI();
Path myPath;
if (uri.getScheme().equals("jar")) {
final FileSystem fileSystem = getFileSystem(uri);
myPath = fileSystem.getPath(path);
} else myPath = Paths.get(uri);
final Stream<Path> walk = Files.walk(myPath, 1);
for (final Iterator<Path> it = walk.iterator(); it.hasNext();) {
final String next = it.next().toString();
if (next.endsWith("." + ext)) itemFileNames.add(next);
}
walk.close();
return itemFileNames;
}
示例2: appendStackTrace
import java.util.stream.Stream; //導入方法依賴的package包/類
private void appendStackTrace(StringBuilder log, ThrowableProxy proxy) {
if (proxy != null) {
Stream<StackTraceElementProxy> trace = Arrays.stream(proxy.getStackTraceElementProxyArray());
trace.forEach(step -> {
String string = step.toString();
log.append(CoreConstants.TAB).append(string);
ThrowableProxyUtil.subjoinPackagingData(log, step);
log.append(CoreConstants.LINE_SEPARATOR);
});
trace.close();
}
}
示例3: listResources
import java.util.stream.Stream; //導入方法依賴的package包/類
/**
* Method to obtain the paths to all files in a directory specified
* by a path. This should work in an ordinary file system
* as well as a (possibly nested) JAR file.
*
* @param path path to a directory (may be contained in a JAR file)
* @return a sequence of paths or {@code null} if the specified path
* is not a directory
*/
public static Path[] listResources(Path path) {
// with help from http://stackoverflow.com/questions/1429172/how-do-i-list-the-files-inside-a-jar-file, #10
if (!Files.isDirectory(path)) {
throw new IllegalArgumentException("path is not a directory: " + path.toString());
}
List<Path> pathList = new ArrayList<Path>();
Stream<Path> walk = null;
try {
walk = Files.walk(path, 1);
} catch (IOException e) {
e.printStackTrace();
}
for (Iterator<Path> it = walk.iterator(); it.hasNext();){
Path p = it.next();
if (Files.isRegularFile(p) && Files.isReadable(p)) {
pathList.add(p);
}
}
walk.close();
return pathList.toArray(new Path[0]);
}
示例4: getFileNamesFromFolder
import java.util.stream.Stream; //導入方法依賴的package包/類
private static List<String> getFileNamesFromFolder(Path folderPath)
{
List<String> fileNames = new ArrayList<String>();
try
{
Stream<Path> walk = Files.walk(folderPath, 1);
for (Iterator<Path> it = walk.iterator(); it.hasNext();)
{
String fileName = it.next().getFileName().toString();
if (fileName.endsWith(".json")) fileNames.add(fileName);
}
walk.close();
}
catch (Exception ex)
{
VillagerTradesMod.LOGGER.catching(ex);
}
return fileNames;
}
示例5: viewFileContent
import java.util.stream.Stream; //導入方法依賴的package包/類
public void viewFileContent(String empFile) throws IOException{
Consumer<String> readStr = System.out::println;
Stream<String> content = null;
Path path = Paths.get(empFile);
content = Files.lines(path, Charset.defaultCharset());
content.map(String::toUpperCase)
.forEach(readStr);
content.close();
}
示例6: countRecsInFile
import java.util.stream.Stream; //導入方法依賴的package包/類
public long countRecsInFile(String empFile) throws IOException{
long numWords = 0;
Stream<String> content = null;
Path path = Paths.get(empFile);
content = Files.lines(path, Charset.defaultCharset());
numWords = content
.map(line -> Arrays.stream(line.split(" ")))
.count();
content.close();
return numWords;
}
示例7: searchFilesDir
import java.util.stream.Stream; //導入方法依賴的package包/類
public String searchFilesDir(String filePath, String extension) throws IOException{
Path root = Paths.get(filePath);
int depth = 3;
Stream<Path> searchStream = Files.find(root, depth, (path, attr) ->
String.valueOf(path).endsWith(extension));
String found = searchStream
.sorted()
.map(String::valueOf)
.collect(Collectors.joining(" / "));
searchStream.close();
return found;
}
示例8: playerCollision
import java.util.stream.Stream; //導入方法依賴的package包/類
public static PlayerCollisionData playerCollision() {
Stream<Entry<ImmutableWrapper<Circle>, PlayerCollisionData>> stream = enemyJudges.entrySet().parallelStream();
mJudgeEntry = null;
stream.forEach((entry) -> {
if (entry.getValue().judgeCallback.getDamage() > 0 && entry.getKey().getData().contains(playerJudge)) {
mJudgeEntry = entry;
}
});
stream.close();
return mJudgeEntry == null ? null : mJudgeEntry.getValue();
}
示例9: closeResource
import java.util.stream.Stream; //導入方法依賴的package包/類
void closeResource() {
Stream<?> a = (Stream<?>)RESOURCE.getAcquire(this);
if (a != null) {
a = (Stream<?>)RESOURCE.getAndSetAcquire(this, null);
if (a != null) {
a.close();
}
}
}
示例10: loadUserDict
import java.util.stream.Stream; //導入方法依賴的package包/類
private void loadUserDict(Stream<String> stream) throws IOException {
try {
stream.forEach(line -> {
Matcher matcher = RE_USERDICT.matcher(line.trim());
if (matcher.find()) {
String word = matcher.group(1).trim();
String freqStr = matcher.group(2);
int freq = 1;
if (freqStr != null) {
freq = Integer.parseInt(freqStr.trim());
} else {
double df = 1.;
for (String seg : this.cut(word, false, false)) {
df *= this.freq.getOrDefault(seg, 1) / total;
}
freq = Math.max((int) (df * total) + 1, this.freq.getOrDefault(word, 1));
}
this.freq.put(word, freq);
this.total += freq;
for (int i = 1; i <= word.length(); i++) {
String wfrag = word.substring(0, i);
if (!this.freq.containsKey(wfrag)) {
this.freq.put(wfrag, 0);
}
}
}
});
} finally {
stream.close();
}
}
示例11: runTest
import java.util.stream.Stream; //導入方法依賴的package包/類
void runTest(Stream<Path> inputs) {
JavacTool tool = JavacTool.create();
try (JavacFileManager fm = tool.getStandardFileManager(null, null, null)) {
Path classes = Paths.get(System.getProperty("test.classes"));
Iterable<? extends JavaFileObject> reconFiles =
fm.getJavaFileObjectsFromFiles(inputs.sorted().map(p -> p.toFile()) :: iterator);
List<String> options = Arrays.asList("-classpath", classes.toAbsolutePath().toString());
JavacTask reconTask = tool.getTask(null, fm, null, options, null, reconFiles);
Iterable<? extends CompilationUnitTree> reconUnits = reconTask.parse();
JavacTrees reconTrees = JavacTrees.instance(reconTask);
SearchAnnotations scanner = new SearchAnnotations(reconTrees,
reconTask.getElements());
List<JavaFileObject> validateFiles = new ArrayList<>();
reconTask.analyze();
scanner.scan(reconUnits, null);
for (CompilationUnitTree cut : reconUnits) {
validateFiles.add(ClearAnnotations.clearAnnotations(reconTrees, cut));
}
Context validateContext = new Context();
TestDependencies.preRegister(validateContext);
JavacTask validateTask =
tool.getTask(null, fm, null, options, null, validateFiles, validateContext);
validateTask.analyze();
TestDependencies deps = (TestDependencies) Dependencies.instance(validateContext);
if (!scanner.topLevel2Expected.equals(deps.topLevel2Completing)) {
throw new IllegalStateException( "expected=" + scanner.topLevel2Expected +
"; actual=" + deps.topLevel2Completing);
}
} catch (IOException ex) {
throw new IllegalStateException(ex);
} finally {
inputs.close();
}
}
示例12: readCitiesFromFile
import java.util.stream.Stream; //導入方法依賴的package包/類
private List<Point2D> readCitiesFromFile() throws IOException {
List<Point2D> cities = new ArrayList<>(8092);
String citiesFile = (Main.class.getResource("cities.txt").toExternalForm()).replace("file:", "");
Stream<String> lines = Files.lines(Paths.get(citiesFile));
lines.forEach(line -> {
String city[] = line.split(",");
double[] xy = World.latLonToXY(Double.parseDouble(city[1]), Double.parseDouble(city[2]));
cities.add(new Point2D(xy[0], xy[1]));
});
lines.close();
return cities;
}
示例13: readCitiesFromFile
import java.util.stream.Stream; //導入方法依賴的package包/類
private List<Point> readCitiesFromFile() throws IOException {
List<Point> cities = new ArrayList<>(8092);
String citiesFile = (WorldHeatMapTest.class.getResource("cities.txt").toExternalForm()).replace("file:", "");
Stream<String> lines = Files.lines(Paths.get(citiesFile));
lines.forEach(line -> {
String city[] = line.split(",");
double[] xy = World.latLonToXY(Double.parseDouble(city[1]), Double.parseDouble(city[2]));
cities.add(new Point(xy[0], xy[1]));
});
lines.close();
return cities;
}