Skip to content

Commit 3e496be

Browse files
committed
Cherry pick branch 'genexuslabs:CreateFileFromStream' into beta
(cherry picked from commit c2dd7d4)
1 parent 8b07809 commit 3e496be

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

common/src/main/java/com/genexus/util/GXFileInfo.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public boolean createNewFile() throws IOException{
5454
return fileSource.createNewFile();
5555
}
5656
public boolean createNewFile(InputStream input) throws IOException{
57-
fromBytes(SpecificImplementation.GXutil.toByteArray(input));
57+
fromInputStream(input);
5858
return true;
5959
}
6060
public boolean delete(){
@@ -155,6 +155,16 @@ public void fromBytes(byte[] data) throws IOException
155155
destination.write(data, 0, data.length);
156156
}
157157
}
158+
private void fromInputStream(InputStream input) throws IOException
159+
{
160+
try (OutputStream output = new BufferedOutputStream(new FileOutputStream(fileSource))) {
161+
byte[] buffer = new byte[8192];
162+
int bytesRead;
163+
while ((bytesRead = input.read(buffer)) != -1) {
164+
output.write(buffer, 0, bytesRead);
165+
}
166+
}
167+
}
158168
public String readAllText(String encoding)throws IOException{
159169
return SpecificImplementation.FileUtils.readFileToString(fileSource, CommonUtil.normalizeEncodingName(encoding));
160170
}

0 commit comments

Comments
 (0)