本文整理汇总了Java中java.nio.file.Files.createTempDirectory方法的典型用法代码示例。如果您正苦于以下问题:Java Files.createTempDirectory方法的具体用法?Java Files.createTempDirectory怎么用?Java Files.createTempDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.file.Files
的用法示例。
在下文中一共展示了Files.createTempDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeModule
import java.nio.file.Files; //导入方法依赖的package包/类
/**
* Writes a module-info.class. If {@code targetPlatform} is not null then
* it includes the ModuleTarget class file attribute with the target platform.
*/
static Path writeModule(ModuleDescriptor descriptor, String targetPlatform)
throws IOException
{
ModuleTarget target;
if (targetPlatform != null) {
target = new ModuleTarget(targetPlatform);
} else {
target = null;
}
String name = descriptor.name();
Path dir = Files.createTempDirectory(Paths.get(""), name);
Path mi = dir.resolve("module-info.class");
try (OutputStream out = Files.newOutputStream(mi)) {
ModuleInfoWriter.write(descriptor, target, out);
}
return dir;
}
示例2: testBadProviderNames
import java.nio.file.Files; //导入方法依赖的package包/类
/**
* Test JAR file with META-INF/services configuration file with bad
* values or names.
*/
@Test(dataProvider = "badproviders", expectedExceptions = FindException.class)
public void testBadProviderNames(String service, String provider)
throws IOException
{
Path tmpdir = Files.createTempDirectory(USER_DIR, "tmp");
// provider class
Path providerClass = tmpdir.resolve(provider.replace('.', '/') + ".class");
Files.createDirectories(providerClass.getParent());
Files.createFile(providerClass);
// services configuration file
Path services = tmpdir.resolve("META-INF").resolve("services");
Files.createDirectories(services);
Files.write(services.resolve(service), Set.of(provider));
Path dir = Files.createTempDirectory(USER_DIR, "mods");
JarUtils.createJarFile(dir.resolve("m.jar"), tmpdir);
// should throw FindException
ModuleFinder.of(dir).findAll();
}
示例3: main
import java.nio.file.Files; //导入方法依赖的package包/类
public static void main(String args[]) throws Throwable {
startTime = System.currentTimeMillis();
Path clientTmpDir = Files.createTempDirectory("TempDirTest-client");
clientTmpDir.toFile().deleteOnExit();
Path targetTmpDir = Files.createTempDirectory("TempDirTest-target");
targetTmpDir.toFile().deleteOnExit();
// run the test with all possible combinations of setting java.io.tmpdir
runExperiment(null, null);
runExperiment(clientTmpDir, null);
runExperiment(clientTmpDir, targetTmpDir);
runExperiment(null, targetTmpDir);
}
示例4: main
import java.nio.file.Files; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
FileSystem fs = FileSystems.getDefault();
if (fs.getClass().getModule() == Object.class.getModule())
throw new RuntimeException("FileSystemProvider not overridden");
// exercise the file system
Path dir = Files.createTempDirectory("tmp");
if (dir.getFileSystem() != fs)
throw new RuntimeException("'dir' not in default file system");
System.out.println("created: " + dir);
Path foo = Files.createFile(dir.resolve("foo"));
if (foo.getFileSystem() != fs)
throw new RuntimeException("'foo' not in default file system");
System.out.println("created: " + foo);
// exercise interop with java.io.File
File file = foo.toFile();
Path path = file.toPath();
if (path.getFileSystem() != fs)
throw new RuntimeException("'path' not in default file system");
if (!path.equals(foo))
throw new RuntimeException(path + " not equal to " + foo);
}
示例5: start
import java.nio.file.Files; //导入方法依赖的package包/类
/**
* Starts the Kafka broker.
*
* @throws IOException if an error occurs during initialization
*/
public synchronized void start() throws IOException {
log.info("Starting Kafka broker on port {}", port);
logsDir = Files.createTempDirectory(LocalKafkaBroker.class.getSimpleName());
logsDir.toFile().deleteOnExit();
kafkaServer = new KafkaServerStartable(new KafkaConfig(ConfigUtils.keyValueToProperties(
"broker.id", TEST_BROKER_ID,
"log.dirs", logsDir.toAbsolutePath(),
"listeners", "PLAINTEXT://:" + port,
"zookeeper.connect", "localhost:" + zkPort,
// Above are for Kafka 0.8; following are for 0.9+
"message.max.bytes", 1 << 26,
"replica.fetch.max.bytes", 1 << 26
), false));
kafkaServer.startup();
}
示例6: generateJar
import java.nio.file.Files; //导入方法依赖的package包/类
/**
* Update Unnamed jars and include descriptor files.
*/
private static void generateJar(Path sjar, Path djar,
ModuleDescriptor mDesc, boolean metaDesc) throws Exception {
Files.copy(sjar, djar, StandardCopyOption.REPLACE_EXISTING);
Path dir = Files.createTempDirectory("tmp");
if (metaDesc) {
write(dir.resolve(Paths.get("META-INF", "services",
"java.security.Provider")), P_TYPE);
}
if (mDesc != null) {
Path mi = dir.resolve("module-info.class");
try (OutputStream out = Files.newOutputStream(mi)) {
ModuleInfoWriter.write(mDesc, out);
}
System.out.format("Added 'module-info.class' in '%s'%n", djar);
}
JarUtils.updateJarFile(djar, dir);
}
示例7: testExtractToNotEmptyDir
import java.nio.file.Files; //导入方法依赖的package包/类
public void testExtractToNotEmptyDir() throws IOException {
Path tmp = Files.createTempDirectory(Paths.get("."), getClass().getName());
Files.createFile(Paths.get(tmp.toString(), ".not_empty"));
jimage("extract", "--dir", tmp.toString(), getImagePath())
.assertFailure()
.assertShowsError();
}
示例8: testTwoProtectionDomains
import java.nio.file.Files; //导入方法依赖的package包/类
/**
* Test defineClass to define classes in a package containing classes with
* different protection domains.
*/
@Test
public void testTwoProtectionDomains() throws Exception {
Path here = Paths.get("");
// p.C1 in one exploded directory
Path dir1 = Files.createTempDirectory(here, "classes");
Path p = Files.createDirectory(dir1.resolve("p"));
Files.write(p.resolve("C1.class"), generateClass("p.C1"));
URL url1 = dir1.toUri().toURL();
// p.C2 in another exploded directory
Path dir2 = Files.createTempDirectory(here, "classes");
p = Files.createDirectory(dir2.resolve("p"));
Files.write(p.resolve("C2.class"), generateClass("p.C2"));
URL url2 = dir2.toUri().toURL();
// load p.C1 and p.C2
ClassLoader loader = new URLClassLoader(new URL[] { url1, url2 });
Class<?> target1 = Class.forName("p.C1", false, loader);
Class<?> target2 = Class.forName("p.C2", false, loader);
assertTrue(target1.getClassLoader() == loader);
assertTrue(target1.getClassLoader() == loader);
assertNotEquals(target1.getProtectionDomain(), target2.getProtectionDomain());
// protection domain 1
Lookup lookup1 = privateLookupIn(target1, lookup());
Class<?> clazz = lookup1.defineClass(generateClass("p.Foo"));
testSameAbode(clazz, lookup1.lookupClass());
testDiscoverable(clazz, lookup1);
// protection domain 2
Lookup lookup2 = privateLookupIn(target2, lookup());
clazz = lookup2.defineClass(generateClass("p.Bar"));
testSameAbode(clazz, lookup2.lookupClass());
testDiscoverable(clazz, lookup2);
}
示例9: returns_compiled_artifact_path
import java.nio.file.Files; //导入方法依赖的package包/类
@Test
public void returns_compiled_artifact_path() throws Exception {
final Path workspace = Files.createTempDirectory("workspace");
final JavaFileCompiler javaFileCompiler = Mockito.mock(JavaFileCompiler.class);
final ArtifactStore artifactStore = Mockito.mock(ArtifactStore.class);
final CompilingFunction compilingFunction = new CompilingFunction(
javaFileCompiler,
artifactStore,
workspace
);
final HttpServletResponse httpServletResponse = Mockito.mock(HttpServletResponse.class);
final Path compilerSpace = Files.createTempDirectory("compiler");
final CompilationResult compilerSuccess = CompilationResult.compilationSucceeded(compilerSpace);
Mockito.when(javaFileCompiler.compile(Mockito.any(), Mockito.any())).thenReturn(compilerSuccess);
Mockito.when(artifactStore.save(Mockito.any())).thenReturn(SimpleFuture.success(compilerSpace.toUri()));
final String json = compilingFunction.run(buildContext(httpServletResponse));
final CompilingFunctionResult result = readJsonResult(json);
assertTrue(result.isSuccess());
assertEquals(compilerSpace.toUri(), new URI(result.getUri()));
Mockito.verify(javaFileCompiler).compile(workspace.resolve(JAVA_FILE_NAME).toString(), Collections.emptyList());
Mockito.verify(artifactStore).save(compilerSpace.resolve(ARTIFACT_ZIP));
Mockito.verify(httpServletResponse).setStatus(200);
}
示例10: getTempDirectory
import java.nio.file.Files; //导入方法依赖的package包/类
public static Path getTempDirectory(String entryName) throws IOException {
String dirName = entryName;
if (dirName.endsWith(ARCHIVE_ENTRY_SEPARATOR)) {
dirName = dirName.substring(0, dirName.length() - 1);
}
dirName = dirName.replace('/', '-');
Path dirPath = Paths.get(dirName);
if (Files.exists(dirPath)) {
return dirPath;
}
return Files.createTempDirectory(dirName);
}
示例11: testComposeOfTwo
import java.nio.file.Files; //导入方法依赖的package包/类
/**
* Test ModuleFinder.compose with two module finders
*/
public void testComposeOfTwo() throws Exception {
Path dir1 = Files.createTempDirectory(USER_DIR, "mods1");
createModularJar(dir1.resolve("m1.jar"), "[email protected]");
createModularJar(dir1.resolve("m2.jar"), "[email protected]");
Path dir2 = Files.createTempDirectory(USER_DIR, "mods2");
createModularJar(dir2.resolve("m1.jar"), "[email protected]");
createModularJar(dir2.resolve("m2.jar"), "[email protected]");
createModularJar(dir2.resolve("m3.jar"), "m3");
createModularJar(dir2.resolve("m4.jar"), "m4");
ModuleFinder finder1 = ModuleFinder.of(dir1);
ModuleFinder finder2 = ModuleFinder.of(dir2);
ModuleFinder finder = ModuleFinder.compose(finder1, finder2);
assertTrue(finder.findAll().size() == 4);
assertTrue(finder.find("m1").isPresent());
assertTrue(finder.find("m2").isPresent());
assertTrue(finder.find("m3").isPresent());
assertTrue(finder.find("m4").isPresent());
assertFalse(finder.find("java.rhubarb").isPresent());
// check that [email protected] is found
ModuleDescriptor m1 = finder.find("m1").get().descriptor();
assertEquals(m1.version().get().toString(), "1.0");
// check that [email protected] is found
ModuleDescriptor m2 = finder.find("m2").get().descriptor();
assertEquals(m2.version().get().toString(), "1.0");
}
示例12: buildWithMavenProxyConf
import java.nio.file.Files; //导入方法依赖的package包/类
@Deprecated //Due to switch to BuildManager V2
public static XTFBuild buildWithMavenProxyConf(XTFBuild build) {
try {
// We hack the build path to be able to inject a custom settings.xml.
// So we first copy the build path (and its parent) to tmp, and modify the settings.xml...
IOUtils.TMP_DIRECTORY.toFile().mkdirs();
Path tmp = Files.createTempDirectory(IOUtils.TMP_DIRECTORY, build.getBuildDefinition().getAppName());
PathBuildDefinition buildDefinition = (PathBuildDefinition) build.getBuildDefinition();
IOUtils.copy(buildDefinition.getPathToProject(), tmp);
Path projectSource = tmp.resolve(buildDefinition.getPathToProject().getFileName());
createMavenProxyConf(projectSource);
// Now we wrap the original build, all is same except the getPathToProject
return new XTFBuild() {
@Override
public BuildDefinition getBuildDefinition() {
return build.getBuildDefinition();
}
};
} catch (IOException e) {
throw new RuntimeException(e);
}
}
示例13: createInfra
import java.nio.file.Files; //导入方法依赖的package包/类
String createInfra() throws IOException {
this.basePath = Files.createTempDirectory("java-build-pack");
this.wdPath = Files.createTempDirectory(basePath, "di_ws_");
this.workdir = Files.createTempDirectory(basePath, "workdir");
Path launcher = Files.createFile(new File(basePath.toString() + "/Launcher.sh").toPath());
// Return Log msg
return String.format("TEST Env:\nBasePath=%s\nWorkdir=%s\nLauncher script=%s\n ",
basePath.toString(), workdir.toString(), launcher.toString());
}
示例14: testOutputAdditionalOption
import java.nio.file.Files; //导入方法依赖的package包/类
@Test
public void testOutputAdditionalOption() throws Exception {
Path tempDir = Files.createTempDirectory("jaffree");
Path outputPath = tempDir.resolve("test.mp3");
FFmpegResult result = FFmpeg.atPath(BIN)
.addInput(UrlInput.fromPath(VIDEO_MP4))
.addOutput(UrlOutput
.toPath(outputPath)
.setCodec(StreamType.AUDIO, "mp3")
.disableStream(StreamType.VIDEO)
.addOption("-id3v2_version", "3")
)
.execute();
Assert.assertNotNull(result);
FFprobeResult probe = FFprobe.atPath(BIN)
.setInputPath(outputPath)
.setShowStreams(true)
.setShowError(true)
.execute();
Assert.assertNotNull(probe);
Assert.assertEquals(1, probe.getStreams().getStream().size());
Assert.assertEquals("audio", probe.getStreams().getStream().get(0).getCodecType());
}
示例15: testOfMixDirectoriesAndExplodedModules
import java.nio.file.Files; //导入方法依赖的package包/类
/**
* Test ModuleFinder.of with a mix of module directories and exploded
* modules.
*/
public void testOfMixDirectoriesAndExplodedModules() throws Exception {
// directory with [email protected] and [email protected]
Path dir1 = Files.createTempDirectory(USER_DIR, "mods1");
createExplodedModule(dir1.resolve("m1"), "[email protected]");
createModularJar(dir1.resolve("m2.jar"), "[email protected]");
// exploded modules: [email protected], [email protected], [email protected], [email protected]
Path dir2 = Files.createTempDirectory(USER_DIR, "mods2");
Path m1_dir = createExplodedModule(dir2.resolve("m1"), "[email protected]");
Path m2_dir = createExplodedModule(dir2.resolve("m2"), "[email protected]");
Path m3_dir = createExplodedModule(dir2.resolve("m3"), "[email protected]");
Path m4_dir = createExplodedModule(dir2.resolve("m4"), "[email protected]");
ModuleFinder finder = ModuleFinder.of(dir1, m1_dir, m2_dir, m3_dir, m4_dir);
assertTrue(finder.findAll().size() == 4);
assertTrue(finder.find("m1").isPresent());
assertTrue(finder.find("m2").isPresent());
assertTrue(finder.find("m3").isPresent());
assertTrue(finder.find("m4").isPresent());
assertFalse(finder.find("java.rhubarb").isPresent());
// m1 and m2 should be located in dir1
ModuleDescriptor m1 = finder.find("m1").get().descriptor();
assertEquals(m1.version().get().toString(), "1.0");
ModuleDescriptor m2 = finder.find("m2").get().descriptor();
assertEquals(m2.version().get().toString(), "1.0");
// m3 and m4 should be located in dir2
ModuleDescriptor m3 = finder.find("m3").get().descriptor();
assertEquals(m3.version().get().toString(), "2.0");
ModuleDescriptor m4 = finder.find("m4").get().descriptor();
assertEquals(m4.version().get().toString(), "2.0");
}