public class TempDirTest {
public static void main(String[] args) throws IOException {
File tmpDir = Files.createTempDir();
System.out.println(tmpDir);
}
}
public void demoTemporaryDirectoryCreation()
{
final File newTempDir = Files.createTempDir();
try
{
out.println(
"New temporary directory is '" + newTempDir.getCanonicalPath() + "'.");
}
catch (IOException ioEx)
{
err.println("ERROR: Unable to create temporary directory - " + ioEx.toString());
}
}
public void testCreateTempDir() {
File temp = Files.createTempDir();
assertTrue(temp.exists());
assertTrue(temp.isDirectory());
assertThat(temp.listFiles()).isEmpty();
assertTrue(temp.delete());
}
class M {
void foo(java.net.URL url, Charset charset, java.io.OutputStream stream, String resourceName, Class<?> contextClass,
LineProcessor<Object> callback, int fileThreshold, boolean resetOnFinalize) throws Exception {
Files.createTempDir(); // Questionable
Files.fileTreeTraverser(); // Questionable (removed from public API in Guava 25.0)
Files.fileTraverser(); // Questionable
MoreFiles.directoryTreeTraverser(); // Questionable (removed from public API in Guava 25.0)
MoreFiles.fileTraverser(); // Questionable
Resources.asByteSource(url); // Questionable
Resources.asCharSource(url, charset); // Questionable
Resources.copy(url, stream); // Questionable
Resources.getResource(contextClass, resourceName); // Questionable
Resources.getResource(resourceName); // Questionable
Resources.readLines(url, charset); // Questionable
Resources.readLines(url, charset, callback); // Questionable
Resources.toByteArray(url); // Questionable
Resources.toString(url, charset); // Questionable
// these OutputStreams creates files
new FileBackedOutputStream(fileThreshold); // Questionable
new FileBackedOutputStream(fileThreshold, resetOnFinalize); // Questionable
}
}
public static File createTempDir() {
File tempDir = Files.createTempDir();
tempDir.deleteOnExit();
return tempDir;
}
protected Configuration setupCommonConfig() {
tmpOivImgDir = Files.createTempDir();
Configuration conf = new Configuration();
conf.setInt(DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_CHECK_PERIOD_KEY, 1);
conf.setInt(DFSConfigKeys.DFS_NAMENODE_CHECKPOINT_TXNS_KEY, 5);
conf.setInt(DFSConfigKeys.DFS_HA_TAILEDITS_PERIOD_KEY, 1);
conf.set(DFSConfigKeys.DFS_NAMENODE_LEGACY_OIV_IMAGE_DIR_KEY,
tmpOivImgDir.getAbsolutePath());
conf.setBoolean(DFSConfigKeys.DFS_IMAGE_COMPRESS_KEY, true);
conf.set(DFSConfigKeys.DFS_IMAGE_COMPRESSION_CODEC_KEY,
SlowCodec.class.getCanonicalName());
CompressionCodecFactory.setCodecClasses(conf,
ImmutableList.<Class>of(SlowCodec.class));
return conf;
}
private BrokerService createBrokerService(final String name) {
final BrokerService broker = new BrokerService();
broker.setPersistent(persistent);
broker.setBrokerName(name);
broker.setStartAsync(false);
tempDir = Files.createTempDir();
broker.setDataDirectoryFile(tempDir);
try {
broker.addConnector(createVmTransportServer(createVmTransportUri(name)));
} catch (Exception e) {
throw new IllegalStateException("Could not create VM Transport URI", e);
}
broker.setUseJmx(false);
return broker;
}
public void testComponentFields() throws IOException {
File outputDir = Files.createTempDir();
System.out.println("Generating into " + outputDir.getAbsolutePath());
assertAbout(javaSources())
.that(Arrays.asList(componentClassBadField))
.processedWith(new VerifiedSpringConfiguration())
.failsToCompile()
.withErrorContaining("@Component classes my only have static final constant fields or final private fields")
.in(componentClassBadField)
.onLine(15)
.and()
.withErrorContaining("@Component classes my only have static final constant fields or final private fields")
.in(componentClassBadField)
.onLine(15);
}
public void setUp() {
javac = ToolProvider.getSystemJavaCompiler();
diagnosticCollector = new DiagnosticCollector<>();
fileManager = javac.getStandardFileManager(diagnosticCollector, null, null);
tmpDir = Files.createTempDir();
}
public void setup() throws Exception {
baseDir = Files.createTempDir();
keyStorePasswordFile = new File(baseDir, "keyStorePasswordFile");
Files.write("keyStorePassword", keyStorePasswordFile, Charsets.UTF_8);
keyAliasPassword = Maps.newHashMap();
keyStoreFile = new File(baseDir, "keyStoreFile");
Assert.assertTrue(keyStoreFile.createNewFile());
}