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

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

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

FileUtil介绍

[英]A utility class with some useful file and i/o related methods.

Versions exists take Input and OutputStreams as parameters, to allow for copying streams (URL's etc.).
[中]具有一些有用的文件和i/o相关方法的实用程序类。
现有版本将输入和输出流作为参数,以允许复制流(URL等)。

代码示例

代码示例来源:origin: haraldk/TwelveMonkeys

/**
 * Copies the fromFile to the toFile location. If toFile is a directory, a
 * new file is created in that directory, with the name of the fromFile.
 * If the toFile exists, the file will not be copied, unless owerWrite is
 * true.
 *
 * @param pFromFile The file to copy from
 * @param pToFile   The file to copy to
 * @return true if the file was copied successfully,
 *         false if the output file exists. In all other cases, an
 *         IOException is thrown, and the method does not return a value.
 * @throws IOException if an i/o error occurs during copy
 */
public static boolean copy(File pFromFile, File pToFile) throws IOException {
  return copy(pFromFile, pToFile, false);
}

代码示例来源:origin: haraldk/TwelveMonkeys

/**
 * Gets the contents of the given file, as a byte array.
 *
 * @param pFilename the name of the file to get content from
 * @return the content of the file as a byte array.
 * @throws IOException if the read operation fails
 */
public static byte[] read(String pFilename) throws IOException {
  return read(new File(pFilename));
}

代码示例来源:origin: haraldk/TwelveMonkeys

public boolean accept(File pFile) {
  // Directories are always supported
  if (pFile.isDirectory()) {
    return true;
  }
  // Test if we have an ImageWriter for this suffix
  String suffix = FileUtil.getExtension(pFile);
  return !StringUtil.isEmpty(suffix) && hasWriterForSuffix(suffix);
}

代码示例来源:origin: haraldk/TwelveMonkeys

public static void main(String[] pArgs) throws IOException {
  File file;
  if (pArgs[0].startsWith("file:")) {
    file = toFile(new URL(pArgs[0]));
    System.out.println(file);
  }
  else {
    file = new File(pArgs[0]);
    System.out.println(file.toURL());
  }
  System.out.println("Free space: " + getFreeSpace(file) + "/" + getTotalSpace(file) + " bytes");
}

代码示例来源:origin: haraldk/TwelveMonkeys

/**
 * Writes the contents from a byte array to a file.
 *
 * @param pFile The file to write to
 * @param pData The byte array to write
 * @return {@code true}, otherwise an IOException is thrown.
 * @throws IOException if an i/o error occurs during write.
 */
public static boolean write(File pFile, byte[] pData) throws IOException {
  boolean success = false;
  OutputStream out = null;
  try {
    out = new BufferedOutputStream(new FileOutputStream(pFile));
    success = write(out, pData);
  }
  finally {
    close(out);
  }
  return success;
}

代码示例来源:origin: haraldk/TwelveMonkeys

return copyDir(pFromFile, pToFile, pOverWrite);
copy(in, out);
close(in);
close(out);

代码示例来源:origin: haraldk/TwelveMonkeys

data = FileUtil.read(stream1);
FileUtil.write(file1, data);
stream1.close();
data = FileUtil.read(stream2);
FileUtil.write(file2, data);
stream2.close();
data = FileUtil.read(stream3);
FileUtil.write(file3, data);
stream3.close();

代码示例来源:origin: haraldk/TwelveMonkeys

private void runStreamTest(int pLength) throws Exception {
  byte[] data = createData(pLength);
  ByteArrayOutputStream outBytes = new ByteArrayOutputStream();
  OutputStream out = new EncoderStream(outBytes, createCompatibleEncoder(), true);
  out.write(data);
  out.close();
  byte[] encoded = outBytes.toByteArray();
  byte[] decoded = FileUtil.read(new DecoderStream(new ByteArrayInputStream(encoded), createDecoder()));
  assertArrayEquals(String.format("Data %d", pLength), data, decoded);
  InputStream in = new DecoderStream(new ByteArrayInputStream(encoded), createDecoder());
  outBytes = new ByteArrayOutputStream();
  FileUtil.copy(in, outBytes);
  outBytes.close();
  in.close();
  decoded = outBytes.toByteArray();
  assertArrayEquals(String.format("Data %d", pLength), data, decoded);
}

代码示例来源:origin: haraldk/TwelveMonkeys

if (content != null && content.exists()) {
  byte[] contents = FileUtil.read(content);
  contentCache.put(pCacheURI + '.' + FileUtil.getExtension(content), response);

代码示例来源:origin: haraldk/TwelveMonkeys

format = FileUtil.getExtension(out);
String baseName = FileUtil.getBasename(in);

代码示例来源:origin: haraldk/TwelveMonkeys

@SuppressWarnings("SameParameterValue")
private static ICC_Profile readProfileFromClasspathResource(final String profilePath) {
  InputStream stream = ColorSpaces.class.getResourceAsStream(profilePath);
  if (stream != null) {
    if (DEBUG) {
      System.out.println("Loading profile from classpath resource: " + profilePath);
    }
    try {
      return ICC_Profile.getInstance(stream);
    }
    catch (IOException ignore) {
      if (DEBUG) {
        ignore.printStackTrace();
      }
    }
    finally {
      FileUtil.close(stream);
    }
  }
  return null;
}

代码示例来源:origin: haraldk/TwelveMonkeys

/**
 * Deletes the specified file.
 *
 * @param pFile The file to delete
 * @return {@code true}, if the file existed and was deleted.
 * @throws java.io.IOException if deletion fails
 */
public static boolean delete(File pFile) throws IOException {
  return delete(pFile, false);
}

代码示例来源:origin: haraldk/TwelveMonkeys

/**
 * Writes the contents from a byte array to a file.
 *
 * @param pFilename The name of the file to write to
 * @param pData     The byte array to write
 * @return {@code true}, otherwise an IOException is thrown.
 * @throws IOException if an i/o error occurs during write.
 */
public static boolean write(String pFilename, byte[] pData) throws IOException {
  return write(new File(pFilename), pData);
}

代码示例来源:origin: haraldk/TwelveMonkeys

/**
 * This method is called by the server before the filter goes into service,
 * and here it determines the file upload directory.
 *
 * @throws ServletException
 */
public void init() throws ServletException {
  // Get the name of the upload directory.
  String uploadDirParam = getInitParameter("uploadDir");
  if (!StringUtil.isEmpty(uploadDirParam)) {
    try {
      URL uploadDirURL = getServletContext().getResource(uploadDirParam);
      uploadDir = FileUtil.toFile(uploadDirURL);
    }
    catch (MalformedURLException e) {
      throw new ServletException(e.getMessage(), e);
    }
  }
  if (uploadDir == null) {
    uploadDir = ServletUtil.getTempDir(getServletContext());
  }
}

代码示例来源:origin: haraldk/TwelveMonkeys

/**
 * Deletes the specified file.
 *
 * @param pFile  The file to delete
 * @param pForce Forces delete, even if the parameter is a directory, and
 *               is not empty. Be careful!
 * @return {@code true}, if the file existed and was deleted.
 * @throws IOException if an i/o error occurs during delete.
 */
public static boolean delete(final File pFile, final boolean pForce) throws IOException {
  if (pForce && pFile.isDirectory()) {
    return deleteDir(pFile);
  }
  return pFile.exists() && pFile.delete();
}

代码示例来源:origin: haraldk/TwelveMonkeys

@Test
public void testSplit() throws IOException {
  InputStream inputStream = getClassLoaderResource("/contrib/tiff/multipage.tif").openStream();
  File inputFile = File.createTempFile("imageiotest", "tif");
  byte[] data = FileUtil.read(inputStream);
  FileUtil.write(inputFile, data);
  inputStream.close();
  File outputDirectory = Files.createTempDirectory("imageio").toFile();
  TIFFUtilities.split(inputFile, outputDirectory);
  ImageReader reader = ImageIO.getImageReadersByFormatName("TIF").next();
  File[] outputFiles = outputDirectory.listFiles();
  Assert.assertEquals(3, outputFiles.length);
  for (File outputFile : outputFiles) {
    ImageInputStream iis = ImageIO.createImageInputStream(outputFile);
    reader.setInput(iis);
    Assert.assertEquals(1, reader.getNumImages(true));
    iis.close();
    outputFile.delete();
  }
  outputDirectory.delete();
  inputFile.delete();
}

代码示例来源:origin: com.twelvemonkeys/twelvemonkeys-core

return copyDir(pFromFile, pToFile, pOverWrite);
copy(in, out);
close(in);
close(out);

代码示例来源:origin: haraldk/TwelveMonkeys

byte[] decoded = FileUtil.read(new DecoderStream(new ByteArrayInputStream(encoded), createCompatibleDecoder()));
assertTrue(Arrays.equals(data, decoded));
  FileUtil.copy(in, outBytes);

代码示例来源:origin: com.github.lafa.twelvemonkeyspurejava.common/common-image

format = FileUtil.getExtension(out);
String baseName = FileUtil.getBasename(in);

代码示例来源:origin: com.github.lafa.twelvemonkeyspurejava.common/common-io

public static void main(String[] pArgs) throws IOException {
  File file;
  if (pArgs[0].startsWith("file:")) {
    file = toFile(new URL(pArgs[0]));
    System.out.println(file);
  }
  else {
    file = new File(pArgs[0]);
    System.out.println(file.toURL());
  }
  System.out.println("Free space: " + getFreeSpace(file) + "/" + getTotalSpace(file) + " bytes");
}

相关文章