Skip to content

Commit b5450c7

Browse files
committed
Fix to file copy
Signed-off-by: Matteo Franci a.k.a. Fugerit <m@fugerit.org>
1 parent 7adc08e commit b5450c7

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

fj-core-jvfs/src/main/java/org/fugerit/java/core/jvfs/helpers/AbstractJFile.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.io.IOException;
44
import java.io.InputStream;
55
import java.io.InputStreamReader;
6+
import java.io.OutputStream;
67
import java.io.OutputStreamWriter;
78
import java.io.Reader;
89
import java.io.Writer;
@@ -74,12 +75,22 @@ public String[] list() throws IOException {
7475

7576
@Override
7677
public Reader getReader() throws IOException {
77-
return (new InputStreamReader(this.getInputStream()));
78+
Reader reader = null;
79+
InputStream is = this.getInputStream();
80+
if ( is != null ) {
81+
reader = (new InputStreamReader(this.getInputStream()));
82+
}
83+
return reader;
7884
}
7985

8086
@Override
8187
public Writer getWriter() throws IOException {
82-
return (new OutputStreamWriter(this.getOutputStream()));
88+
Writer writer = null;
89+
OutputStream os = this.getOutputStream();
90+
if ( os != null ) {
91+
writer = (new OutputStreamWriter(this.getOutputStream()));
92+
}
93+
return writer;
8394
}
8495

8596
@Override

fj-core-jvfs/src/main/java/org/fugerit/java/core/jvfs/util/JFileUtilCP.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package org.fugerit.java.core.jvfs.util;
22

3+
import java.io.ByteArrayInputStream;
34
import java.io.IOException;
4-
import java.io.InputStream;
55

66
import org.fugerit.java.core.io.StreamIO;
77
import org.fugerit.java.core.jvfs.JFile;
8+
import org.fugerit.java.core.util.ObjectUtils;
89
import org.slf4j.Logger;
910
import org.slf4j.LoggerFactory;
1011

@@ -56,14 +57,11 @@ public static int copyFile( JFile from, JFile to, boolean recurse, boolean force
5657
throw new IOException( "Directories can only be copied recursively, from:("+from+") to:("+to+")" );
5758
}
5859
} else {
59-
InputStream fromIS = from.getInputStream();
60-
if ( fromIS != null ) {
61-
StreamIO.pipeStream( fromIS , to.getOutputStream(), StreamIO.MODE_CLOSE_BOTH );
62-
} else {
63-
if ( verbose ) {
64-
logger.info( "Input file empty (getInputStream() == null) : {}", from.describe() );
65-
}
66-
}
60+
// We want to create a blank file if the from input stream is null
61+
StreamIO.pipeStream(
62+
ObjectUtils.objectWithDefault( from.getInputStream() , new ByteArrayInputStream( "".getBytes() ) ) ,
63+
to.getOutputStream(),
64+
StreamIO.MODE_CLOSE_BOTH );
6765
}
6866
}
6967
return res;

0 commit comments

Comments
 (0)