com.twelvemonkeys.io.FileUtil.copy()方法的使用及代码示例

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

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

FileUtil.copy介绍

[英]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.
[中]将FROM文件复制到toFile位置。如果toFile是一个目录,则会在该目录中创建一个名为fromFile的新文件。如果toFile存在,则不会复制该文件,除非owerWrite为true。

代码示例

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

copy(in, out);

代码示例来源: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 pFromFileName The name of the file to copy from
 * @param pToFileName   The name of 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(String pFromFileName, String pToFileName) throws IOException {
  return copy(new File(pFromFileName), new File(pToFileName), false);
}

代码示例来源: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 pFromFileName The name of the file to copy from
 * @param pToFileName   The name of the file to copy to
 * @param pOverWrite    Specifies if the toFile should be overwritten, if it
 *                      exists.
 * @return true if the file was copied successfully,
 *         false if the output file exists, and the owerWrite parameter is
 *         false. 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(String pFromFileName, String pToFileName, boolean pOverWrite) throws IOException {
  return copy(new File(pFromFileName), new File(pToFileName), pOverWrite);
}

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

private static File dumpToFile(final ImageInputStream stream) throws IOException {
  File tempFile = File.createTempFile("imageio-icns-", ".png");
  tempFile.deleteOnExit();
  FileOutputStream out = new FileOutputStream(tempFile);
  try {
    FileUtil.copy(IIOUtil.createStreamAdapter(stream), out);
  }
  finally {
    out.close();
  }
  return tempFile;
}

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

/**
 * Reads all data from the input stream to a byte array.
 *
 * @param pInput The input stream to read from
 * @return The content of the stream as a byte array.
 * @throws IOException if an i/o error occurs during read.
 */
public static byte[] read(InputStream pInput) throws IOException {
  // Create byte array
  ByteArrayOutputStream bytes = new FastByteArrayOutputStream(BUF_SIZE);
  // Copy from stream to byte array
  copy(pInput, bytes);
  return bytes.toByteArray();
}

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

/**
 * Copies a directory recursively. If the destination folder does not exist,
 * it is created
 *
 * @param pFrom the source directory
 * @param pTo the destination directory
 * @param pOverWrite {@code true} if we should allow overwrting existing files
 * @return {@code true} if all files were copied sucessfully
 * @throws IOException if {@code pTo} exists, and it not a directory,
 *          or if copying of any of the files in the folder fails
 */
private static boolean copyDir(File pFrom, File pTo, boolean pOverWrite) throws IOException {
  if (pTo.exists() && !pTo.isDirectory()) {
    throw new IOException("A directory may only be copied to another directory, not to a file");
  }
  pTo.mkdirs();  // mkdir?
  boolean allOkay = true;
  File[] files = pFrom.listFiles();
  for (File file : files) {
    if (!copy(file, new File(pTo, file.getName()), pOverWrite)) {
      allOkay = false;
    }
  }
  return allOkay;
}

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

FileUtil.copy(in, response.getOutputStream());

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

private File createFileWithContent(final InputStream pStream) throws IOException {
  File temp = File.createTempFile("tm-io-junit", null);
  temp.deleteOnExit();
  OutputStream os = new FileOutputStream(temp);
  try {
    FileUtil.copy(pStream, os);
  }
  finally {
    os.close();
    pStream.close();
  }
  return temp;
}

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

fromClient = pRequest.getInputStream();
toRemote = pRemoteConnection.getOutputStream();
FileUtil.copy(fromClient, toRemote);

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

FileUtil.copy(fromRemote, toClient);

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

public Void answer(InvocationOnMock invocation) throws Throwable {
    HttpServletResponse response = (HttpServletResponse) invocation.getArguments()[1];
    response.setContentType("image/png");
    response.setContentLength(104417);
    InputStream stream = getClass().getResourceAsStream("/com/twelvemonkeys/servlet/image/12monkeys-splash.png");
    assertNotNull("Missing test resource", stream);
    FileUtil.copy(stream, response.getOutputStream());
    return null;
  }
}).when(chain).doFilter(any(ServletRequest.class), any(ServletResponse.class));

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

@Test
public void testEmptyDecode2() throws IOException {
  String data = "";
  InputStream in = new DecoderStream(new ByteArrayInputStream(data.getBytes()), createDecoder());
  ByteArrayOutputStream bytes = new ByteArrayOutputStream();
  FileUtil.copy(in, bytes);
  assertEquals("Strings does not match", "", new String(bytes.toByteArray()));
}

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

@Test
public void testShortDecode() throws IOException {
  String data = "dGVzdA==";
  InputStream in = new DecoderStream(new ByteArrayInputStream(data.getBytes()), createDecoder());
  ByteArrayOutputStream bytes = new ByteArrayOutputStream();
  FileUtil.copy(in, bytes);
  assertEquals("Strings does not match", "test", new String(bytes.toByteArray()));
}

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

public Void answer(InvocationOnMock invocation) throws Throwable {
    HttpServletRequest request = (HttpServletRequest) invocation.getArguments()[0];
    HttpServletResponse response = (HttpServletResponse) invocation.getArguments()[1];
    // Fake chaining here..
    if (first.compareAndSet(false, true)) {
      barFilter.doFilter(request, response, (FilterChain) invocation.getMock());
      return null;
    }
    // Otherwise, fake servlet/file response
    response.setContentType("image/gif");
    InputStream stream = getClass().getResourceAsStream("/com/twelvemonkeys/servlet/image/tux.gif");
    assertNotNull("Missing test resource", stream);
    FileUtil.copy(stream, response.getOutputStream());
    return null;
  }
}).when(chain).doFilter(any(ServletRequest.class), any(ServletResponse.class));

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

@Test
  public void testLongDecode() throws IOException {
    String data = "TG9yZW0gaXBzdW0gZG9sb3Igc2l0IGFtZXQsIGNvbnNlY3RldHVlciBhZGlwaXNjaW5nIGVsaXQuIEZ1" +
        "c2NlIGVzdC4gTW9yYmkgbHVjdHVzIGNvbnNlY3RldHVlciBqdXN0by4gVml2YW11cyBkYXBpYnVzIGxh" +
        "b3JlZXQgcHVydXMuIE51bmMgdml2ZXJyYSBkaWN0dW0gbmlzbC4gSW50ZWdlciB1bGxhbWNvcnBlciwg" +
        "bmlzaSBpbiBkaWN0dW0gYW1ldC4=";

    InputStream in = new DecoderStream(new ByteArrayInputStream(data.getBytes()), createDecoder());
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();

    FileUtil.copy(in, bytes);

    assertEquals("Strings does not match",
           "Lorem ipsum dolor sit amet, consectetuer adipiscing " +
           "elit. Fusce est. Morbi luctus consectetuer justo. Vivamus " +
           "dapibus laoreet purus. Nunc viverra dictum nisl. Integer " +
           "ullamcorper, nisi in dictum amet.",
           new String(bytes.toByteArray()));
  }
}

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

private void fakeResponse(HttpServletRequest pRequest, ImageServletResponseImpl pImageResponse) throws IOException {
  String uri = pRequest.getRequestURI();
  int index = uri.lastIndexOf('/');
  assertTrue(uri, index >= 0);
  String name = uri.substring(index + 1);
  InputStream in = getClass().getResourceAsStream(name);
  if (in == null) {
    pImageResponse.sendError(HttpServletResponse.SC_NOT_FOUND, uri + " not found");
  }
  else {
    String ext = name.substring(name.lastIndexOf("."));
    pImageResponse.setContentType(context.getMimeType("file" + ext));
    pImageResponse.setContentLength(234);
    try {
      ServletOutputStream out = pImageResponse.getOutputStream();
      try {
        FileUtil.copy(in, out);
      }
      finally {
        out.close();
      }
    }
    finally {
      in.close();
    }
  }
}

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

FileUtil.copy(in, outBytes);

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

public static byte[] decode(String pData) throws IOException {
  InputStream in = new DecoderStream(new ByteArrayInputStream(pData.getBytes()), new Base64Decoder());
  ByteArrayOutputStream bytes = new FastByteArrayOutputStream(pData.length() * 3);
  FileUtil.copy(in, bytes);
  return bytes.toByteArray();
}

相关文章