jodd.io.FileUtil类的使用及代码示例

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

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

FileUtil介绍

[英]File utilities.
[中]文件实用程序。

代码示例

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

public static String readString(File source) throws IOException {
  return readString(source, fileUtilParams.encoding);
}

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

/**
   * Checks the start of the file for ASCII control characters
   */
  public static boolean isBinary(final File file) throws IOException {
    byte[] bytes = readBytes(file, 128);

    for (byte b : bytes) {
      if (b < 32) {
        return true;
      }
    }

    return false;
  }
}

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

/**
 * @see #writeString(File, String, String)
 */
public static void writeString(final String dest, final String data) throws IOException {
  writeString(file(dest), data, encoding());
}

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

/**
 * @see #copyFileToDir(java.io.File, java.io.File, FileUtilParams)
 */
public static File copyFileToDir(String src, String destDir, FileUtilParams params) throws IOException {
  return copyFileToDir(file(src), file(destDir), params);
}
/**

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

public static void deleteDir(String dest) throws IOException {
  deleteDir(file(dest), fileUtilParams);
}
public static void deleteDir(String dest, FileUtilParams params) throws IOException {

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

public static void copy(String src, String dest) throws IOException {
  copy(file(src), file(dest), fileUtilParams);
}

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

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

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

FileUtil.copyFile(root + "a.txt", root + "w.txt");
  FileUtil.copyFile(root + "a.png", root + "w.png");
  FileUtil.copyFile(root + "a.txt", root + "w.txt");
} catch (IOException ioex) {
  fail(ioex.toString());
  FileUtil.mkdir(tmp);
  FileUtil.mkdirs(tmp + "x/");
  FileUtil.copyFileToDir(root + "a.txt", tmp);
  FileUtil.copyFileToDir(root + "a.png", tmp);
} catch (IOException ioex) {
  fail(ioex.toString());
  FileUtil.moveFile(root + "w.txt", tmp + "w.txt");
  FileUtil.moveFileToDir(root + "w.png", tmp);
} catch (IOException ioex) {
  fail(ioex.toString());
  FileUtil.deleteFile(tmp + "a.txt");
  FileUtil.deleteFile(tmp + "a.png");
  FileUtil.deleteFile(tmp + "w.txt");
  FileUtil.deleteFile(tmp + "w.png");
} catch (IOException ioex) {
  fail(ioex.toString());
  FileUtil.deleteFile(tmp + "a.txt");
  fail("delete file strict delete");
} catch (IOException e) {

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

FileUtil.writeBytes(zipFile, bytes);
assertTrue(new File(dataRoot, "folder2").isDirectory());
assertTrue(new File(new File(dataRoot, "folder"), "txt").exists());
assertEquals("text", FileUtil.readString(new File(new File(dataRoot, "folder"), "txt")));
assertTrue(new File(new File(dataRoot, "folder2"), "txt2").exists());
assertEquals("txet", FileUtil.readString(new File(new File(dataRoot, "folder2"), "txt2")));
FileUtil.delete(new File(dataRoot, "sbdata"));
FileUtil.deleteDir(new File(dataRoot, "folder"));
FileUtil.deleteDir(new File(dataRoot, "folder2"));
FileUtil.delete(zipFile);

代码示例来源: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 testGetResource() throws IOException {
  File tempRoot = FileUtil.createTempDirectory("jodd", "tmp");
  File temp = new File(tempRoot, "pckg");
  FileUtil.mkdir(temp);
  FileUtil.writeString(resourceFile, "RESOURCE CONTENT");
  resourceFile.deleteOnExit();
  URL[] urls = new URL[] {FileUtil.toURL(tempRoot)};
  assertEquals(res, FileUtil.toURL(resourceFile));
  assertEquals(res, FileUtil.toURL(resourceFile));
  ecl.addLoaderOnlyRules("pckg.data");
  res = ecl.getResource("pckg/data");
  assertEquals(res, FileUtil.toURL(resourceFile));
  ecl.addParentOnlyRules("pckg.data");
  res = ecl.getResource("pckg/data");
  ecl.addLoaderOnlyRules("pckg/data");
  res = ecl.getResource("pckg/data");
  assertEquals(res, FileUtil.toURL(resourceFile));
  ecl.addParentOnlyRules("pckg.data");
  res = ecl.getResource("pckg/data");
  assertNull(res);
  FileUtil.deleteDir(tempRoot);

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

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

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

@Test
void testCompareWithInputStreams_ExpectedNoSuccessfulCompare(TestInfo testInfo) throws Exception {
  final String text = "jodd makes fun!";
  final File file = new File(StreamUtilTest.BASE_DIR, testInfo.getTestMethod().get().getName() + ".txt");
  FileUtil.writeString(file, " " + text, "UTF-8");
  boolean actual;
  try (ByteArrayInputStream in1 = new ByteArrayInputStream(text.getBytes());
     FileInputStream in2 = new FileInputStream(file)) {
    actual = StreamUtil.compare(in1, in2);
  }
  // asserts
  assertFalse(actual);
}

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

final File attFolder = FileUtil.createTempDirectory("jodd", "tt");
File[] allFiles = attFolder.listFiles();
for (File f : allFiles) {
  byte[] bytes = FileUtil.readBytes(f);
  assertArrayEquals(new byte[] {'X', 'Z', 'X'}, bytes);
FileUtil.deleteDir(attFolder);

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

public static String readString(String source) throws IOException {
  return readString(file(source), fileUtilParams.encoding);
}

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

public void start() throws Exception {
  webRoot = FileUtil.createTempDirectory("jodd-http", "test");
  webRoot.deleteOnExit();
  File webXmlFile = FileUtil.toFile(webXmlUrl);
  FileUtil.copy(webXmlFile, webInfFolder);
  File echoServletFile = FileUtil.toFile(echoServletUrl);
  FileUtil.copyFileToDir(echoServletFile, classes);
  echoServletFile = FileUtil.toFile(echoServletUrl);
  FileUtil.copyFileToDir(echoServletFile, classes);
  echoServletFile = FileUtil.toFile(echoServletUrl);
  FileUtil.copyFileToDir(echoServletFile, classes);
  File redirectServletFile = FileUtil.toFile(redirectServletUrl);
  FileUtil.copyFileToDir(redirectServletFile, classes);
  File targetServletFile = FileUtil.toFile(targetServletUrl);
  FileUtil.copyFileToDir(targetServletFile, classes);

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

/**
 * @see #readString(File, String)
 */
public static String readString(final File source) throws IOException {
  return readString(source, encoding());
}

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

/**
 * Smart copy. If source is a directory, copy it to destination.
 * Otherwise, if destination is directory, copy source file to it.
 * Otherwise, try to copy source file to destination file.
 */
public static void copy(File src, File dest, FileUtilParams params) throws IOException {
  if (src.isDirectory()) {
    copyDir(src, dest, params);
    return;
  }
  if (dest.isDirectory()) {
    copyFileToDir(src, dest, params);
    return;
  }
  copyFile(src, dest, params);
}

代码示例来源: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);
}

相关文章