You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2020/12/16 23:11:12 UTC
[commons-vfs] branch master updated: Simplify copying.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git
The following commit(s) were added to refs/heads/master by this push:
new c175407 Simplify copying.
c175407 is described below
commit c175407e3707a998ef2d59f6480feb67645db763
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Dec 16 18:11:07 2020 -0500
Simplify copying.
---
.../commons/vfs2/provider/ram/RamFileSystem.java | 24 +++++-----------------
1 file changed, 5 insertions(+), 19 deletions(-)
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileSystem.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileSystem.java
index 8011e33..12f2deb 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileSystem.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ram/RamFileSystem.java
@@ -28,6 +28,7 @@ import java.util.HashMap;
import java.util.Map;
import org.apache.commons.vfs2.Capability;
+import org.apache.commons.vfs2.FileContent;
import org.apache.commons.vfs2.FileName;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemException;
@@ -204,7 +205,7 @@ public class RamFileSystem extends AbstractFileSystem implements Serializable {
* @param root
* @throws FileSystemException
*/
- void toRamFileObject(final FileObject fo, final FileObject root) throws FileSystemException {
+ private void toRamFileObject(final FileObject fo, final FileObject root) throws FileSystemException {
final RamFileObject memFo = (RamFileObject) this
.resolveFile(fo.getName().getPath().substring(root.getName().getPath().length()));
if (fo.getType().hasChildren()) {
@@ -216,24 +217,9 @@ public class RamFileSystem extends AbstractFileSystem implements Serializable {
this.toRamFileObject(child, root);
}
} else if (fo.isFile()) {
- // Read bytes
- try {
- final InputStream is = fo.getContent().getInputStream();
- try {
- final OutputStream os = new BufferedOutputStream(memFo.getOutputStream(), BUFFER_SIZE);
- int i;
- while ((i = is.read()) != -1) {
- os.write(i);
- }
- os.close();
- } finally {
- try {
- is.close();
- } catch (final IOException ignored) {
- /* ignore on close exception. */
- }
- // TODO: close os
- }
+ // Copy bytes
+ try (final FileContent content = fo.getContent()) {
+ content.write(memFo);
} catch (final IOException e) {
throw new FileSystemException(e.getClass().getName() + " " + e.getMessage());
}