jodd.io.FileUtil.createTempFile()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(331)

本文整理了Java中jodd.io.FileUtil.createTempFile()方法的一些代码示例,展示了FileUtil.createTempFile()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtil.createTempFile()方法的具体详情如下:
包路径:jodd.io.FileUtil
类名称:FileUtil
方法名:createTempFile

FileUtil.createTempFile介绍

[英]Simple method that creates temp file.
[中]创建临时文件的简单方法。

代码示例

代码示例来源:origin: redisson/redisson

/**
 * Simple method that creates temp file.
 */
public static File createTempFile() throws IOException {
  return createTempFile(JoddCore.tempFilePrefix, null, null, true);
}

代码示例来源:origin: redisson/redisson

/**
 * Creates temporary directory.
 */
public static File createTempDirectory(String prefix, String suffix, File tempDir) throws IOException {
  File file = createTempFile(prefix, suffix, tempDir);
  file.delete();
  file.mkdir();
  return file;
}

代码示例来源:origin: redisson/redisson

/**
 * Creates temporary file.
 * If <code>create</code> is set to <code>true</code> file will be
 * physically created on the file system. Otherwise, it will be created and then
 * deleted - trick that will make temp file exist only if they are used.
 */
public static File createTempFile(String prefix, String suffix, File tempDir, boolean create) throws IOException {
  File file = createTempFile(prefix, suffix, tempDir);
  file.delete();
  if (create) {
    file.createNewFile();
  }
  return file;
}

代码示例来源:origin: oblac/jodd

/**
 * Creates temporary directory.
 *
 * @see #createTempFile(String, String, File)
 */
public static File createTempDirectory(final String prefix, final String suffix, final File tempDir) throws IOException {
  File file = createTempFile(prefix, suffix, tempDir);
  file.delete();
  file.mkdir();
  return file;
}

代码示例来源:origin: oblac/jodd

/**
 * @see #createTempFile(String, String, File, boolean)
 */
public static File createTempFile() throws IOException {
  return createTempFile(tempPrefix(), null, null, true);
}

代码示例来源:origin: oblac/jodd

/**
 * Creates temporary {@link File}.
 *
 * @param prefix  The prefix string to be used in generating the file's
 *                name; must be at least three characters long
 * @param suffix  The suffix string to be used in generating the file's
 *                name; may be {@code null}, in which case the
 *                suffix {@code ".tmp"} will be used
 * @param tempDir The directory in which the file is to be created, or
 *                {@code null} if the default temporary-file
 *                directory is to be used
 * @param create  If {@code create} is set to {@code true} {@link File} will be
 *                physically created on the file system. Otherwise, it will be created and then
 *                deleted - trick that will make temp {@link File} exist only if they are used.
 * @return File
 */
public static File createTempFile(final String prefix, final String suffix, final File tempDir, final boolean create) throws IOException {
  File file = createTempFile(prefix, suffix, tempDir);
  file.delete();
  if (create) {
    file.createNewFile();
  }
  return file;
}

代码示例来源:origin: redisson/redisson

if (type == byte[].class) {
  try {
    File tempFile = FileUtil.createTempFile();
    FileUtil.writeBytes(tempFile, (byte[])value);
    return tempFile;
    File tempFile = FileUtil.createTempFile();
    FileUtil.writeString(tempFile, value.toString());
    return tempFile;

代码示例来源:origin: oblac/jodd

try {
    in = fileUpload.getFileInputStream();
    File tempFile = FileUtil.createTempFile();
    FileUtil.writeStream(tempFile, in);
    return tempFile;
if (type == byte[].class) {
  try {
    File tempFile = FileUtil.createTempFile();
    FileUtil.writeBytes(tempFile, (byte[])value);
    return tempFile;
    File tempFile = FileUtil.createTempFile();
    FileUtil.writeString(tempFile, value.toString());
    return tempFile;

代码示例来源:origin: oblac/jodd

tempFile = FileUtil.createTempFile(JoddCore.tempFilePrefix, TMP_FILE_SUFFIX, uploadPath);
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(tempFile));
if (data != null) {

代码示例来源:origin: oblac/jodd

@Test
void file_not_exists() throws Exception {
  final File input = FileUtil.createTempFile("hello", ".jodd", new File(SystemUtil.info().getTempDir()), false);
  final boolean actual = FileUtil.isExistingFile(input);
  // asserts
  assertEquals(false, actual);
}

代码示例来源:origin: oblac/jodd

@Test
void check_against_created_text_file() throws Exception {
  final File input = FileUtil.createTempFile();
  FileUtil.writeString(input, "jodd makes fun!");
  final boolean actual = FileUtil.isBinary(input);
  // asserts
  assertEquals(false, actual);
}

代码示例来源:origin: oblac/jodd

@Test
void check_against_created_binary_file() throws Exception {
  final File input = FileUtil.createTempFile();
  // first bytes of a zip / jar file
  FileUtil.writeBytes(input, new byte[] {0x50, 0x4b, 0x03, 0x04, 0x14, 0x20, 0x08, 0x08, 0x08, 0x20, 0x09,
      0x76, 0x19, 0x45, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 });
  final boolean actual = FileUtil.isBinary(input);
  // asserts
  assertEquals(true, actual);
}

代码示例来源:origin: oblac/jodd

@Test
void testUpload() throws IOException {
  EchoTestServer echoTestServer = new EchoTestServer();
  File file = FileUtil.createTempFile();
  file.deleteOnExit();
  FileUtil.writeString(file, "upload тест");
  assertEquals("upload тест", FileUtil.readString(file));
  HttpResponse response = HttpRequest
      .post("http://localhost:8081/hello")
      .form("id", "12")
      .form("file", file)
      .send();
  assertEquals(200, response.statusCode());
  assertEquals("OK", response.statusPhrase());
  assertEquals("POST", echoTestServer.method);
  assertEquals("12", echoTestServer.params.get("id"));
  File uploadedFile = new File(echoTestServer.files.get("file").toString());
  assertNotNull(uploadedFile);
  assertEquals("upload тест", FileUtil.readString(uploadedFile));
  assertEquals("POST /hello", response.body());
  echoTestServer.stop();
  file.delete();
}

代码示例来源:origin: oblac/jodd

@Test
void testUploadWithMonitor() throws IOException {
  EchoTestServer echoTestServer = new EchoTestServer();
  File file = FileUtil.createTempFile();
  file.deleteOnExit();
  FileUtil.writeString(file, StringUtil.repeat('A', 1024));
  final StringBuilder sb = new StringBuilder();
  HttpResponse response = HttpRequest
      .post("http://localhost:8081/hello")
      .form("id", "12")
      .form("file", file)
      .monitor(new HttpProgressListener() {
        @Override
        public void transferred(int len) {
          sb.append(":" + len);
        }
      })
      .send();
  assertEquals(200, response.statusCode());
  assertEquals("OK", response.statusPhrase());
  echoTestServer.stop();
  file.delete();
  assertEquals(":0:512:1024:148", StringUtil.substring(sb.toString(), 0, -1));
}

代码示例来源:origin: oblac/jodd

@Test
void testFileUpload() throws IOException {
  HttpRequest request = HttpRequest.get("http://jodd.org/?id=173");
  request.header("User-Agent", "Scaly").form("one", "funny");
  File tempFile = FileUtil.createTempFile();
  tempFile.deleteOnExit();
  FileUtil.writeString(tempFile, "qwerty");
  request.form("two", tempFile);
  byte[] bytes = request.toByteArray();
  // read
  HttpRequest request2 = HttpRequest.readFrom(new ByteArrayInputStream(bytes));
  HttpMultiMap<?> httpParams2 = request2.form();
  assertEquals(request.method(), request2.method());
  assertEquals(request.path(), request2.path());
  assertEquals(request.queryString(), request2.queryString());
  assertEquals(request.header("User-Agent"), request2.header("User-Agent"));
  assertEquals(request.header("Content-Type"), request2.header("content-type"));
  assertEquals(request.header("Content-Length"), request2.header("content-length"));
  HttpMultiMap<?> params1 = request.form();
  HttpMultiMap<?> params2 = request2.form();
  assertEquals(params1.size(), params2.size());
  assertEquals(params2.get("one"), params2.get("one"));
  FileUpload fu = (FileUpload) httpParams2.get("two");
  assertEquals(6, fu.getSize());
  String str = new String(fu.getFileContent());
  assertEquals("qwerty", str);
  tempFile.delete();
}

代码示例来源:origin: org.jodd/jodd-core

/**
 * Creates temporary directory.
 *
 * @see #createTempFile(String, String, File)
 */
public static File createTempDirectory(final String prefix, final String suffix, final File tempDir) throws IOException {
  File file = createTempFile(prefix, suffix, tempDir);
  file.delete();
  file.mkdir();
  return file;
}

代码示例来源:origin: org.jodd/jodd-core

/**
 * Creates temporary {@link File}.
 *
 * @param prefix  The prefix string to be used in generating the file's
 *                name; must be at least three characters long
 * @param suffix  The suffix string to be used in generating the file's
 *                name; may be {@code null}, in which case the
 *                suffix {@code ".tmp"} will be used
 * @param tempDir The directory in which the file is to be created, or
 *                {@code null} if the default temporary-file
 *                directory is to be used
 * @param create  If {@code create} is set to {@code true} {@link File} will be
 *                physically created on the file system. Otherwise, it will be created and then
 *                deleted - trick that will make temp {@link File} exist only if they are used.
 * @return File
 */
public static File createTempFile(final String prefix, final String suffix, final File tempDir, final boolean create) throws IOException {
  File file = createTempFile(prefix, suffix, tempDir);
  file.delete();
  if (create) {
    file.createNewFile();
  }
  return file;
}

代码示例来源:origin: org.jodd/jodd-core

/**
 * @see #createTempFile(String, String, File, boolean)
 */
public static File createTempFile() throws IOException {
  return createTempFile(tempPrefix(), null, null, true);
}

代码示例来源:origin: ru.yandex.qatools.camelot/camelot-utils

/**
 * Create Temp Jar file with given classpath in manifest
 *
 * @param mainClassName main class name for manifest
 * @param classPath     classpath elements for manifest
 * @return {@link java.io.File} with created Jar
 * @throws IOException if can't create temp file
 */
public static File createJarWithClassPath(String mainClassName, String... classPath) throws IOException {
  return createJarWithClassPath(createTempFile(), mainClassName, classPath);
}

代码示例来源:origin: org.jodd/jodd-core

tempFile = FileUtil.createTempFile(JoddCore.tempFilePrefix, TMP_FILE_SUFFIX, uploadPath);
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(tempFile));
if (data != null) {

相关文章