Skip to content

Commit c2dd7d4

Browse files
iroquetaBeta Bot
authored andcommitted
Cherry pick branch 'genexuslabs:CreateFileFromStream' into beta
1 parent 6064830 commit c2dd7d4

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
@@ -68,7 +68,7 @@ public boolean createNewFile() throws IOException{
6868
return fileSource.createNewFile();
6969
}
7070
public boolean createNewFile(InputStream input) throws IOException{
71-
fromBytes(SpecificImplementation.GXutil.toByteArray(input));
71+
fromInputStream(input);
7272
return true;
7373
}
7474
public boolean delete(){
@@ -180,6 +180,16 @@ public void fromBytes(byte[] data) throws IOException
180180
destination.write(data, 0, data.length);
181181
}
182182
}
183+
private void fromInputStream(InputStream input) throws IOException
184+
{
185+
try (OutputStream output = new BufferedOutputStream(new FileOutputStream(fileSource))) {
186+
byte[] buffer = new byte[8192];
187+
int bytesRead;
188+
while ((bytesRead = input.read(buffer)) != -1) {
189+
output.write(buffer, 0, bytesRead);
190+
}
191+
}
192+
}
183193
public String readAllText(String encoding)throws IOException{
184194
return SpecificImplementation.FileUtils.readFileToString(fileSource, CommonUtil.normalizeEncodingName(encoding));
185195
}

0 commit comments

Comments
 (0)