当前位置: 首页>>代码示例>>Java>>正文


Java Stream.close方法代码示例

本文整理汇总了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;

	}
 
开发者ID:ASasseCreations,项目名称:Voxel_Game,代码行数:24,代码来源:AssetLoader.java

示例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();
    }
}
 
开发者ID:hmcts,项目名称:java-logging,代码行数:18,代码来源:ReformLoggingLayout.java

示例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]);
}
 
开发者ID:imagingbook,项目名称:imagingbook-common,代码行数:33,代码来源:ResourceUtils.java

示例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;
}
 
开发者ID:crazysnailboy,项目名称:VillagerTrades,代码行数:20,代码来源:FileUtils.java

示例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();
 }
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:10,代码来源:EmployeeFileStreamService.java

示例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;
  }
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:12,代码来源:EmployeeFileStreamService.java

示例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;
}
 
开发者ID:PacktPublishing,项目名称:Spring-5.0-Cookbook,代码行数:13,代码来源:EmployeeFileStreamService.java

示例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();
}
 
开发者ID:cn-s3bit,项目名称:TH902,代码行数:12,代码来源:JudgingSystem.java

示例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();
        }
    }
}
 
开发者ID:akarnokd,项目名称:Reactive4JavaFlow,代码行数:10,代码来源:FolyamStream.java

示例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();
    }
}
 
开发者ID:hongfuli,项目名称:elasticsearch-analysis-jieba,代码行数:34,代码来源:Tokenizer.java

示例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();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:41,代码来源:DependenciesTest.java

示例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;
}
 
开发者ID:HanSolo,项目名称:worldheatmap,代码行数:13,代码来源:Main.java

示例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;
}
 
开发者ID:HanSolo,项目名称:charts,代码行数:13,代码来源:WorldHeatMapTest.java


注:本文中的java.util.stream.Stream.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。