Does IOUtils.toByteArray(inputStream) method internally close inputStream object?
Here is my code flow for which file content is getting lost and I think may be IOUtils.toByteArray() line is problem, please guide what is actually going wrong here.
File content getting lost :
InputStream stream = someClient.downloadApi(fileId);
byte bytes = IOUtils.toByteArray(stream);
String mimeType = CommonUtils.fileTypeFromByteArray(bytes);
String fileExtension=FormatToExtensionMapping.getByFormat(mimeType).getExtension();
String filePath = configuration.getDownloadFolder() + "/" ;
String fileName = UUID.randomUUID() + fileExtension;
File file = new File(filePath+fileName);
file.createNewFile();
FileUtils.copyInputStreamToFile(stream,file);
int length = (int)file.length();
Now length value here is 0 basically no content. Let me tell you that inputStream received from downloadApi() has content for sure thats given. But if I try below modification in code then I'm getting length of file.
File content NOT getting lost:
InputStream stream = someClient.downloadApi(fileId);
byte bytes = IOUtils.toByteArray(stream);
String mimeType = CommonUtils.fileTypeFromByteArray(bytes);
String fileExtension=FormatToExtensionMapping.getByFormat(mimeType).getExtension();
String filePath = configuration.getDownloadFolder() + "/" ;
String fileName = UUID.randomUUID() + fileExtension;
stream = new ByteArrayInputStream(bytes); //Again converted bytes to stream
File file = new File(filePath+fileName);
file.createNewFile();
FileUtils.copyInputStreamToFile(stream,file);
int length = (int)file.length();
Now here I'm getting file content. Can some body tell what is technically wrong here in first code snippet ?
TIA
java inputstream bytearrayinputstream ioutils
add a comment |
Here is my code flow for which file content is getting lost and I think may be IOUtils.toByteArray() line is problem, please guide what is actually going wrong here.
File content getting lost :
InputStream stream = someClient.downloadApi(fileId);
byte bytes = IOUtils.toByteArray(stream);
String mimeType = CommonUtils.fileTypeFromByteArray(bytes);
String fileExtension=FormatToExtensionMapping.getByFormat(mimeType).getExtension();
String filePath = configuration.getDownloadFolder() + "/" ;
String fileName = UUID.randomUUID() + fileExtension;
File file = new File(filePath+fileName);
file.createNewFile();
FileUtils.copyInputStreamToFile(stream,file);
int length = (int)file.length();
Now length value here is 0 basically no content. Let me tell you that inputStream received from downloadApi() has content for sure thats given. But if I try below modification in code then I'm getting length of file.
File content NOT getting lost:
InputStream stream = someClient.downloadApi(fileId);
byte bytes = IOUtils.toByteArray(stream);
String mimeType = CommonUtils.fileTypeFromByteArray(bytes);
String fileExtension=FormatToExtensionMapping.getByFormat(mimeType).getExtension();
String filePath = configuration.getDownloadFolder() + "/" ;
String fileName = UUID.randomUUID() + fileExtension;
stream = new ByteArrayInputStream(bytes); //Again converted bytes to stream
File file = new File(filePath+fileName);
file.createNewFile();
FileUtils.copyInputStreamToFile(stream,file);
int length = (int)file.length();
Now here I'm getting file content. Can some body tell what is technically wrong here in first code snippet ?
TIA
java inputstream bytearrayinputstream ioutils
1
I would start by: dumping the result oftoByteArray()
. Your second example looks weird, it should actually not do anything. You can't "reset" a stream ... Dont go for "file length", check the content that gets written to disk.
– GhostCat
Nov 13 '18 at 13:08
1
Also, doesByteArrayInputStream
really takeInputStream
as input?
– CS_noob
Nov 13 '18 at 13:09
@GhostCat yes I've checked the downloaded file and it hasno content
for first snippet but has content for second snippet. Length is just example to tell it has no content.
– apandey846
Nov 13 '18 at 13:15
@CS_noob thanks! updated the code accordingly.
– apandey846
Nov 13 '18 at 13:24
add a comment |
Here is my code flow for which file content is getting lost and I think may be IOUtils.toByteArray() line is problem, please guide what is actually going wrong here.
File content getting lost :
InputStream stream = someClient.downloadApi(fileId);
byte bytes = IOUtils.toByteArray(stream);
String mimeType = CommonUtils.fileTypeFromByteArray(bytes);
String fileExtension=FormatToExtensionMapping.getByFormat(mimeType).getExtension();
String filePath = configuration.getDownloadFolder() + "/" ;
String fileName = UUID.randomUUID() + fileExtension;
File file = new File(filePath+fileName);
file.createNewFile();
FileUtils.copyInputStreamToFile(stream,file);
int length = (int)file.length();
Now length value here is 0 basically no content. Let me tell you that inputStream received from downloadApi() has content for sure thats given. But if I try below modification in code then I'm getting length of file.
File content NOT getting lost:
InputStream stream = someClient.downloadApi(fileId);
byte bytes = IOUtils.toByteArray(stream);
String mimeType = CommonUtils.fileTypeFromByteArray(bytes);
String fileExtension=FormatToExtensionMapping.getByFormat(mimeType).getExtension();
String filePath = configuration.getDownloadFolder() + "/" ;
String fileName = UUID.randomUUID() + fileExtension;
stream = new ByteArrayInputStream(bytes); //Again converted bytes to stream
File file = new File(filePath+fileName);
file.createNewFile();
FileUtils.copyInputStreamToFile(stream,file);
int length = (int)file.length();
Now here I'm getting file content. Can some body tell what is technically wrong here in first code snippet ?
TIA
java inputstream bytearrayinputstream ioutils
Here is my code flow for which file content is getting lost and I think may be IOUtils.toByteArray() line is problem, please guide what is actually going wrong here.
File content getting lost :
InputStream stream = someClient.downloadApi(fileId);
byte bytes = IOUtils.toByteArray(stream);
String mimeType = CommonUtils.fileTypeFromByteArray(bytes);
String fileExtension=FormatToExtensionMapping.getByFormat(mimeType).getExtension();
String filePath = configuration.getDownloadFolder() + "/" ;
String fileName = UUID.randomUUID() + fileExtension;
File file = new File(filePath+fileName);
file.createNewFile();
FileUtils.copyInputStreamToFile(stream,file);
int length = (int)file.length();
Now length value here is 0 basically no content. Let me tell you that inputStream received from downloadApi() has content for sure thats given. But if I try below modification in code then I'm getting length of file.
File content NOT getting lost:
InputStream stream = someClient.downloadApi(fileId);
byte bytes = IOUtils.toByteArray(stream);
String mimeType = CommonUtils.fileTypeFromByteArray(bytes);
String fileExtension=FormatToExtensionMapping.getByFormat(mimeType).getExtension();
String filePath = configuration.getDownloadFolder() + "/" ;
String fileName = UUID.randomUUID() + fileExtension;
stream = new ByteArrayInputStream(bytes); //Again converted bytes to stream
File file = new File(filePath+fileName);
file.createNewFile();
FileUtils.copyInputStreamToFile(stream,file);
int length = (int)file.length();
Now here I'm getting file content. Can some body tell what is technically wrong here in first code snippet ?
TIA
java inputstream bytearrayinputstream ioutils
java inputstream bytearrayinputstream ioutils
edited Nov 13 '18 at 13:32
apandey846
asked Nov 13 '18 at 13:01
apandey846apandey846
9431020
9431020
1
I would start by: dumping the result oftoByteArray()
. Your second example looks weird, it should actually not do anything. You can't "reset" a stream ... Dont go for "file length", check the content that gets written to disk.
– GhostCat
Nov 13 '18 at 13:08
1
Also, doesByteArrayInputStream
really takeInputStream
as input?
– CS_noob
Nov 13 '18 at 13:09
@GhostCat yes I've checked the downloaded file and it hasno content
for first snippet but has content for second snippet. Length is just example to tell it has no content.
– apandey846
Nov 13 '18 at 13:15
@CS_noob thanks! updated the code accordingly.
– apandey846
Nov 13 '18 at 13:24
add a comment |
1
I would start by: dumping the result oftoByteArray()
. Your second example looks weird, it should actually not do anything. You can't "reset" a stream ... Dont go for "file length", check the content that gets written to disk.
– GhostCat
Nov 13 '18 at 13:08
1
Also, doesByteArrayInputStream
really takeInputStream
as input?
– CS_noob
Nov 13 '18 at 13:09
@GhostCat yes I've checked the downloaded file and it hasno content
for first snippet but has content for second snippet. Length is just example to tell it has no content.
– apandey846
Nov 13 '18 at 13:15
@CS_noob thanks! updated the code accordingly.
– apandey846
Nov 13 '18 at 13:24
1
1
I would start by: dumping the result of
toByteArray()
. Your second example looks weird, it should actually not do anything. You can't "reset" a stream ... Dont go for "file length", check the content that gets written to disk.– GhostCat
Nov 13 '18 at 13:08
I would start by: dumping the result of
toByteArray()
. Your second example looks weird, it should actually not do anything. You can't "reset" a stream ... Dont go for "file length", check the content that gets written to disk.– GhostCat
Nov 13 '18 at 13:08
1
1
Also, does
ByteArrayInputStream
really take InputStream
as input?– CS_noob
Nov 13 '18 at 13:09
Also, does
ByteArrayInputStream
really take InputStream
as input?– CS_noob
Nov 13 '18 at 13:09
@GhostCat yes I've checked the downloaded file and it has
no content
for first snippet but has content for second snippet. Length is just example to tell it has no content.– apandey846
Nov 13 '18 at 13:15
@GhostCat yes I've checked the downloaded file and it has
no content
for first snippet but has content for second snippet. Length is just example to tell it has no content.– apandey846
Nov 13 '18 at 13:15
@CS_noob thanks! updated the code accordingly.
– apandey846
Nov 13 '18 at 13:24
@CS_noob thanks! updated the code accordingly.
– apandey846
Nov 13 '18 at 13:24
add a comment |
2 Answers
2
active
oldest
votes
No it doesn't.
The first version of your code (reproduced below with some added commentary) fails because you are reading from a stream that is already at the end of stream position.
InputStream stream = someClient.downloadApi(fileId);
// This reads the entire stream to the end of stream.
byte bytes = IOUtils.toByteArray(stream);
String mimeType = CommonUtils.fileTypeFromByteArray(bytes);
String fileExtension =
FormatToExtensionMapping.getByFormat(mimeType).getExtension();
String filePath = configuration.getDownloadFolder() + "/" ;
String fileName = UUID.randomUUID() + fileExtension;
File file = new File(filePath+fileName);
file.createNewFile();
// Now you attempt to read more data from the stream.
FileUtils.copyInputStreamToFile(stream,file);
int length = (int)file.length();
When you try to copy from a stream that is at the end of stream, you get ... zero bytes. And that means you get an empty output file.
Awesome! Thanks this really explains why I was getting zero bytes in first place. Also, it tells that if we are usingIOUtils.toByteArray(stream);
then after that stream object should not be used for any kind of modification on stream object as it has moved to EOF exceptstream.close()
.
– apandey846
Nov 13 '18 at 14:58
add a comment |
No, this stream should be closed.
This is target method of IOUtils:
public static long copyLarge(final InputStream input, final OutputStream output, final byte buffer)
throws IOException
long count = 0;
int n;
while (EOF != (n = input.read(buffer)))
output.write(buffer, 0, n);
count += n;
return count;
// create stream and use it
InputStream stream = someClient.downloadApi(fileId);
byte bytes = IOUtils.toByteArray(stream);
// then us it again
FileUtils.copyInputStreamToFile(stream,file);
// FIXED VERSION
FileUtils.copyInputStreamToFile(new ByteArrayInputStream(bytes),file);
Thanks for quick response! And I totally understand that stream should be closed here but above two codes behaving weird please review once and can explain whats going wrong there why content getting lost would be great.
– apandey846
Nov 13 '18 at 13:19
Yes your // FIXED VERSION code what I was doing in my second snippet. Thanks!
– apandey846
Nov 13 '18 at 15:01
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53281591%2fdoes-ioutils-tobytearrayinputstream-method-internally-close-inputstream-object%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
No it doesn't.
The first version of your code (reproduced below with some added commentary) fails because you are reading from a stream that is already at the end of stream position.
InputStream stream = someClient.downloadApi(fileId);
// This reads the entire stream to the end of stream.
byte bytes = IOUtils.toByteArray(stream);
String mimeType = CommonUtils.fileTypeFromByteArray(bytes);
String fileExtension =
FormatToExtensionMapping.getByFormat(mimeType).getExtension();
String filePath = configuration.getDownloadFolder() + "/" ;
String fileName = UUID.randomUUID() + fileExtension;
File file = new File(filePath+fileName);
file.createNewFile();
// Now you attempt to read more data from the stream.
FileUtils.copyInputStreamToFile(stream,file);
int length = (int)file.length();
When you try to copy from a stream that is at the end of stream, you get ... zero bytes. And that means you get an empty output file.
Awesome! Thanks this really explains why I was getting zero bytes in first place. Also, it tells that if we are usingIOUtils.toByteArray(stream);
then after that stream object should not be used for any kind of modification on stream object as it has moved to EOF exceptstream.close()
.
– apandey846
Nov 13 '18 at 14:58
add a comment |
No it doesn't.
The first version of your code (reproduced below with some added commentary) fails because you are reading from a stream that is already at the end of stream position.
InputStream stream = someClient.downloadApi(fileId);
// This reads the entire stream to the end of stream.
byte bytes = IOUtils.toByteArray(stream);
String mimeType = CommonUtils.fileTypeFromByteArray(bytes);
String fileExtension =
FormatToExtensionMapping.getByFormat(mimeType).getExtension();
String filePath = configuration.getDownloadFolder() + "/" ;
String fileName = UUID.randomUUID() + fileExtension;
File file = new File(filePath+fileName);
file.createNewFile();
// Now you attempt to read more data from the stream.
FileUtils.copyInputStreamToFile(stream,file);
int length = (int)file.length();
When you try to copy from a stream that is at the end of stream, you get ... zero bytes. And that means you get an empty output file.
Awesome! Thanks this really explains why I was getting zero bytes in first place. Also, it tells that if we are usingIOUtils.toByteArray(stream);
then after that stream object should not be used for any kind of modification on stream object as it has moved to EOF exceptstream.close()
.
– apandey846
Nov 13 '18 at 14:58
add a comment |
No it doesn't.
The first version of your code (reproduced below with some added commentary) fails because you are reading from a stream that is already at the end of stream position.
InputStream stream = someClient.downloadApi(fileId);
// This reads the entire stream to the end of stream.
byte bytes = IOUtils.toByteArray(stream);
String mimeType = CommonUtils.fileTypeFromByteArray(bytes);
String fileExtension =
FormatToExtensionMapping.getByFormat(mimeType).getExtension();
String filePath = configuration.getDownloadFolder() + "/" ;
String fileName = UUID.randomUUID() + fileExtension;
File file = new File(filePath+fileName);
file.createNewFile();
// Now you attempt to read more data from the stream.
FileUtils.copyInputStreamToFile(stream,file);
int length = (int)file.length();
When you try to copy from a stream that is at the end of stream, you get ... zero bytes. And that means you get an empty output file.
No it doesn't.
The first version of your code (reproduced below with some added commentary) fails because you are reading from a stream that is already at the end of stream position.
InputStream stream = someClient.downloadApi(fileId);
// This reads the entire stream to the end of stream.
byte bytes = IOUtils.toByteArray(stream);
String mimeType = CommonUtils.fileTypeFromByteArray(bytes);
String fileExtension =
FormatToExtensionMapping.getByFormat(mimeType).getExtension();
String filePath = configuration.getDownloadFolder() + "/" ;
String fileName = UUID.randomUUID() + fileExtension;
File file = new File(filePath+fileName);
file.createNewFile();
// Now you attempt to read more data from the stream.
FileUtils.copyInputStreamToFile(stream,file);
int length = (int)file.length();
When you try to copy from a stream that is at the end of stream, you get ... zero bytes. And that means you get an empty output file.
edited Nov 13 '18 at 14:14
answered Nov 13 '18 at 13:50
Stephen CStephen C
524k72585943
524k72585943
Awesome! Thanks this really explains why I was getting zero bytes in first place. Also, it tells that if we are usingIOUtils.toByteArray(stream);
then after that stream object should not be used for any kind of modification on stream object as it has moved to EOF exceptstream.close()
.
– apandey846
Nov 13 '18 at 14:58
add a comment |
Awesome! Thanks this really explains why I was getting zero bytes in first place. Also, it tells that if we are usingIOUtils.toByteArray(stream);
then after that stream object should not be used for any kind of modification on stream object as it has moved to EOF exceptstream.close()
.
– apandey846
Nov 13 '18 at 14:58
Awesome! Thanks this really explains why I was getting zero bytes in first place. Also, it tells that if we are using
IOUtils.toByteArray(stream);
then after that stream object should not be used for any kind of modification on stream object as it has moved to EOF except stream.close()
.– apandey846
Nov 13 '18 at 14:58
Awesome! Thanks this really explains why I was getting zero bytes in first place. Also, it tells that if we are using
IOUtils.toByteArray(stream);
then after that stream object should not be used for any kind of modification on stream object as it has moved to EOF except stream.close()
.– apandey846
Nov 13 '18 at 14:58
add a comment |
No, this stream should be closed.
This is target method of IOUtils:
public static long copyLarge(final InputStream input, final OutputStream output, final byte buffer)
throws IOException
long count = 0;
int n;
while (EOF != (n = input.read(buffer)))
output.write(buffer, 0, n);
count += n;
return count;
// create stream and use it
InputStream stream = someClient.downloadApi(fileId);
byte bytes = IOUtils.toByteArray(stream);
// then us it again
FileUtils.copyInputStreamToFile(stream,file);
// FIXED VERSION
FileUtils.copyInputStreamToFile(new ByteArrayInputStream(bytes),file);
Thanks for quick response! And I totally understand that stream should be closed here but above two codes behaving weird please review once and can explain whats going wrong there why content getting lost would be great.
– apandey846
Nov 13 '18 at 13:19
Yes your // FIXED VERSION code what I was doing in my second snippet. Thanks!
– apandey846
Nov 13 '18 at 15:01
add a comment |
No, this stream should be closed.
This is target method of IOUtils:
public static long copyLarge(final InputStream input, final OutputStream output, final byte buffer)
throws IOException
long count = 0;
int n;
while (EOF != (n = input.read(buffer)))
output.write(buffer, 0, n);
count += n;
return count;
// create stream and use it
InputStream stream = someClient.downloadApi(fileId);
byte bytes = IOUtils.toByteArray(stream);
// then us it again
FileUtils.copyInputStreamToFile(stream,file);
// FIXED VERSION
FileUtils.copyInputStreamToFile(new ByteArrayInputStream(bytes),file);
Thanks for quick response! And I totally understand that stream should be closed here but above two codes behaving weird please review once and can explain whats going wrong there why content getting lost would be great.
– apandey846
Nov 13 '18 at 13:19
Yes your // FIXED VERSION code what I was doing in my second snippet. Thanks!
– apandey846
Nov 13 '18 at 15:01
add a comment |
No, this stream should be closed.
This is target method of IOUtils:
public static long copyLarge(final InputStream input, final OutputStream output, final byte buffer)
throws IOException
long count = 0;
int n;
while (EOF != (n = input.read(buffer)))
output.write(buffer, 0, n);
count += n;
return count;
// create stream and use it
InputStream stream = someClient.downloadApi(fileId);
byte bytes = IOUtils.toByteArray(stream);
// then us it again
FileUtils.copyInputStreamToFile(stream,file);
// FIXED VERSION
FileUtils.copyInputStreamToFile(new ByteArrayInputStream(bytes),file);
No, this stream should be closed.
This is target method of IOUtils:
public static long copyLarge(final InputStream input, final OutputStream output, final byte buffer)
throws IOException
long count = 0;
int n;
while (EOF != (n = input.read(buffer)))
output.write(buffer, 0, n);
count += n;
return count;
// create stream and use it
InputStream stream = someClient.downloadApi(fileId);
byte bytes = IOUtils.toByteArray(stream);
// then us it again
FileUtils.copyInputStreamToFile(stream,file);
// FIXED VERSION
FileUtils.copyInputStreamToFile(new ByteArrayInputStream(bytes),file);
edited Nov 13 '18 at 14:13
answered Nov 13 '18 at 13:15
oleg.cherednikoleg.cherednik
7,19521219
7,19521219
Thanks for quick response! And I totally understand that stream should be closed here but above two codes behaving weird please review once and can explain whats going wrong there why content getting lost would be great.
– apandey846
Nov 13 '18 at 13:19
Yes your // FIXED VERSION code what I was doing in my second snippet. Thanks!
– apandey846
Nov 13 '18 at 15:01
add a comment |
Thanks for quick response! And I totally understand that stream should be closed here but above two codes behaving weird please review once and can explain whats going wrong there why content getting lost would be great.
– apandey846
Nov 13 '18 at 13:19
Yes your // FIXED VERSION code what I was doing in my second snippet. Thanks!
– apandey846
Nov 13 '18 at 15:01
Thanks for quick response! And I totally understand that stream should be closed here but above two codes behaving weird please review once and can explain whats going wrong there why content getting lost would be great.
– apandey846
Nov 13 '18 at 13:19
Thanks for quick response! And I totally understand that stream should be closed here but above two codes behaving weird please review once and can explain whats going wrong there why content getting lost would be great.
– apandey846
Nov 13 '18 at 13:19
Yes your // FIXED VERSION code what I was doing in my second snippet. Thanks!
– apandey846
Nov 13 '18 at 15:01
Yes your // FIXED VERSION code what I was doing in my second snippet. Thanks!
– apandey846
Nov 13 '18 at 15:01
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53281591%2fdoes-ioutils-tobytearrayinputstream-method-internally-close-inputstream-object%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
I would start by: dumping the result of
toByteArray()
. Your second example looks weird, it should actually not do anything. You can't "reset" a stream ... Dont go for "file length", check the content that gets written to disk.– GhostCat
Nov 13 '18 at 13:08
1
Also, does
ByteArrayInputStream
really takeInputStream
as input?– CS_noob
Nov 13 '18 at 13:09
@GhostCat yes I've checked the downloaded file and it has
no content
for first snippet but has content for second snippet. Length is just example to tell it has no content.– apandey846
Nov 13 '18 at 13:15
@CS_noob thanks! updated the code accordingly.
– apandey846
Nov 13 '18 at 13:24