2022-02-09 15:12:23 +01:00
|
|
|
// SPDX-FileCopyrightText: 2022 Paul Schaub <vanitasvitae@fsfe.org>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
|
|
|
package sop.cli.picocli;
|
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.io.FileOutputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
|
|
|
|
public class TestFileUtil {
|
|
|
|
|
2022-06-20 19:50:50 +02:00
|
|
|
public static File createTempDir() throws IOException {
|
|
|
|
File tempDir = Files.createTempDirectory("tmpFir").toFile();
|
2022-02-09 15:12:23 +01:00
|
|
|
tempDir.deleteOnExit();
|
|
|
|
tempDir.mkdirs();
|
2022-06-20 19:50:50 +02:00
|
|
|
return tempDir;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static File writeTempStringFile(String string) throws IOException {
|
|
|
|
File tempDir = createTempDir();
|
2022-02-09 15:12:23 +01:00
|
|
|
|
|
|
|
File passwordFile = new File(tempDir, "file");
|
|
|
|
passwordFile.createNewFile();
|
|
|
|
|
|
|
|
FileOutputStream fileOut = new FileOutputStream(passwordFile);
|
|
|
|
fileOut.write(string.getBytes(StandardCharsets.UTF_8));
|
|
|
|
fileOut.close();
|
|
|
|
|
|
|
|
return passwordFile;
|
|
|
|
}
|
|
|
|
}
|