Read data from ByteArrayOutputStream
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I have decrypted data in bytearrayoutputstream. I want to read the data in each line(not sure if that is possible).Could any one guide how I can do that.
The main requirement is to read a encrypted file , decrypt and read the data without writing into the disk. I have already covered encrypt and decrypt part but unable to read the data without writing into disk.Some suggested to use bytearrayoutputStream so stuck now.
ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream(inputBytes.length);
byteArrayOutputStream.write(outputBytes);
if i simply print the variable it give me all the data at once as below.
SQlServer,"connection string","user name","password"
Oracle,"connection string","user name","password"
I am trying to read the data line wise so i can match the servername and fetch the user name and other details.
java arrays bytearrayoutputstream
|
show 2 more comments
I have decrypted data in bytearrayoutputstream. I want to read the data in each line(not sure if that is possible).Could any one guide how I can do that.
The main requirement is to read a encrypted file , decrypt and read the data without writing into the disk. I have already covered encrypt and decrypt part but unable to read the data without writing into disk.Some suggested to use bytearrayoutputStream so stuck now.
ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream(inputBytes.length);
byteArrayOutputStream.write(outputBytes);
if i simply print the variable it give me all the data at once as below.
SQlServer,"connection string","user name","password"
Oracle,"connection string","user name","password"
I am trying to read the data line wise so i can match the servername and fetch the user name and other details.
java arrays bytearrayoutputstream
2
Possible duplicate of How to read a large text file line by line using Java?
– Alex Shesterov
Jan 4 at 12:00
have you tried to usetoByteArray?
– Leonardo Alves Machado
Jan 4 at 12:03
@LeonardoAlvesMachado yes not working...could you suggest if you have a way to use it.
– Shubham Sahay
Jan 4 at 12:26
The proper way would be to not have theByteArrayOutputStreamat all, but instead wrap the file input stream in aCipherInputStreamor otherwise a customFilterInputStream, so it is decrypted while being read. There should be no need to read and decrypt the entire file to a byte array and then read it back.
– Mark Rotteveel
Jan 4 at 12:37
@ShubhamSahay I didn't quite understand why you are using an output class (used to write to streams, in your case) in order to read stuff. When I said to usetoByteArray, I meant to give you the data that it contains, so you could use it in an input class (used to read data) of your choice... If you couldn't get the data from it, you might be able to get it from the variableoutputBytesin your code.
– Leonardo Alves Machado
Jan 4 at 12:57
|
show 2 more comments
I have decrypted data in bytearrayoutputstream. I want to read the data in each line(not sure if that is possible).Could any one guide how I can do that.
The main requirement is to read a encrypted file , decrypt and read the data without writing into the disk. I have already covered encrypt and decrypt part but unable to read the data without writing into disk.Some suggested to use bytearrayoutputStream so stuck now.
ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream(inputBytes.length);
byteArrayOutputStream.write(outputBytes);
if i simply print the variable it give me all the data at once as below.
SQlServer,"connection string","user name","password"
Oracle,"connection string","user name","password"
I am trying to read the data line wise so i can match the servername and fetch the user name and other details.
java arrays bytearrayoutputstream
I have decrypted data in bytearrayoutputstream. I want to read the data in each line(not sure if that is possible).Could any one guide how I can do that.
The main requirement is to read a encrypted file , decrypt and read the data without writing into the disk. I have already covered encrypt and decrypt part but unable to read the data without writing into disk.Some suggested to use bytearrayoutputStream so stuck now.
ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream(inputBytes.length);
byteArrayOutputStream.write(outputBytes);
if i simply print the variable it give me all the data at once as below.
SQlServer,"connection string","user name","password"
Oracle,"connection string","user name","password"
I am trying to read the data line wise so i can match the servername and fetch the user name and other details.
java arrays bytearrayoutputstream
java arrays bytearrayoutputstream
edited Jan 4 at 12:00
Alex Shesterov
15.8k94771
15.8k94771
asked Jan 4 at 11:53
Shubham SahayShubham Sahay
507
507
2
Possible duplicate of How to read a large text file line by line using Java?
– Alex Shesterov
Jan 4 at 12:00
have you tried to usetoByteArray?
– Leonardo Alves Machado
Jan 4 at 12:03
@LeonardoAlvesMachado yes not working...could you suggest if you have a way to use it.
– Shubham Sahay
Jan 4 at 12:26
The proper way would be to not have theByteArrayOutputStreamat all, but instead wrap the file input stream in aCipherInputStreamor otherwise a customFilterInputStream, so it is decrypted while being read. There should be no need to read and decrypt the entire file to a byte array and then read it back.
– Mark Rotteveel
Jan 4 at 12:37
@ShubhamSahay I didn't quite understand why you are using an output class (used to write to streams, in your case) in order to read stuff. When I said to usetoByteArray, I meant to give you the data that it contains, so you could use it in an input class (used to read data) of your choice... If you couldn't get the data from it, you might be able to get it from the variableoutputBytesin your code.
– Leonardo Alves Machado
Jan 4 at 12:57
|
show 2 more comments
2
Possible duplicate of How to read a large text file line by line using Java?
– Alex Shesterov
Jan 4 at 12:00
have you tried to usetoByteArray?
– Leonardo Alves Machado
Jan 4 at 12:03
@LeonardoAlvesMachado yes not working...could you suggest if you have a way to use it.
– Shubham Sahay
Jan 4 at 12:26
The proper way would be to not have theByteArrayOutputStreamat all, but instead wrap the file input stream in aCipherInputStreamor otherwise a customFilterInputStream, so it is decrypted while being read. There should be no need to read and decrypt the entire file to a byte array and then read it back.
– Mark Rotteveel
Jan 4 at 12:37
@ShubhamSahay I didn't quite understand why you are using an output class (used to write to streams, in your case) in order to read stuff. When I said to usetoByteArray, I meant to give you the data that it contains, so you could use it in an input class (used to read data) of your choice... If you couldn't get the data from it, you might be able to get it from the variableoutputBytesin your code.
– Leonardo Alves Machado
Jan 4 at 12:57
2
2
Possible duplicate of How to read a large text file line by line using Java?
– Alex Shesterov
Jan 4 at 12:00
Possible duplicate of How to read a large text file line by line using Java?
– Alex Shesterov
Jan 4 at 12:00
have you tried to use
toByteArray?– Leonardo Alves Machado
Jan 4 at 12:03
have you tried to use
toByteArray?– Leonardo Alves Machado
Jan 4 at 12:03
@LeonardoAlvesMachado yes not working...could you suggest if you have a way to use it.
– Shubham Sahay
Jan 4 at 12:26
@LeonardoAlvesMachado yes not working...could you suggest if you have a way to use it.
– Shubham Sahay
Jan 4 at 12:26
The proper way would be to not have the
ByteArrayOutputStream at all, but instead wrap the file input stream in a CipherInputStream or otherwise a custom FilterInputStream, so it is decrypted while being read. There should be no need to read and decrypt the entire file to a byte array and then read it back.– Mark Rotteveel
Jan 4 at 12:37
The proper way would be to not have the
ByteArrayOutputStream at all, but instead wrap the file input stream in a CipherInputStream or otherwise a custom FilterInputStream, so it is decrypted while being read. There should be no need to read and decrypt the entire file to a byte array and then read it back.– Mark Rotteveel
Jan 4 at 12:37
@ShubhamSahay I didn't quite understand why you are using an output class (used to write to streams, in your case) in order to read stuff. When I said to use
toByteArray, I meant to give you the data that it contains, so you could use it in an input class (used to read data) of your choice... If you couldn't get the data from it, you might be able to get it from the variable outputBytes in your code.– Leonardo Alves Machado
Jan 4 at 12:57
@ShubhamSahay I didn't quite understand why you are using an output class (used to write to streams, in your case) in order to read stuff. When I said to use
toByteArray, I meant to give you the data that it contains, so you could use it in an input class (used to read data) of your choice... If you couldn't get the data from it, you might be able to get it from the variable outputBytes in your code.– Leonardo Alves Machado
Jan 4 at 12:57
|
show 2 more comments
1 Answer
1
active
oldest
votes
To read a byte you can use
ByteArrayInputStream in = new ByteArrayInputStream(outputBytes);
and to read this as lines of text you can use
BufferedReader br = new BufferedReader(new InputStreamReader(in));
for (String line; (line = br.readLine()) != null; ) {
// do something with the line
}
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%2f54038483%2fread-data-from-bytearrayoutputstream%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
To read a byte you can use
ByteArrayInputStream in = new ByteArrayInputStream(outputBytes);
and to read this as lines of text you can use
BufferedReader br = new BufferedReader(new InputStreamReader(in));
for (String line; (line = br.readLine()) != null; ) {
// do something with the line
}
add a comment |
To read a byte you can use
ByteArrayInputStream in = new ByteArrayInputStream(outputBytes);
and to read this as lines of text you can use
BufferedReader br = new BufferedReader(new InputStreamReader(in));
for (String line; (line = br.readLine()) != null; ) {
// do something with the line
}
add a comment |
To read a byte you can use
ByteArrayInputStream in = new ByteArrayInputStream(outputBytes);
and to read this as lines of text you can use
BufferedReader br = new BufferedReader(new InputStreamReader(in));
for (String line; (line = br.readLine()) != null; ) {
// do something with the line
}
To read a byte you can use
ByteArrayInputStream in = new ByteArrayInputStream(outputBytes);
and to read this as lines of text you can use
BufferedReader br = new BufferedReader(new InputStreamReader(in));
for (String line; (line = br.readLine()) != null; ) {
// do something with the line
}
answered Jan 4 at 12:35
Peter LawreyPeter Lawrey
450k56576980
450k56576980
add a comment |
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%2f54038483%2fread-data-from-bytearrayoutputstream%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
2
Possible duplicate of How to read a large text file line by line using Java?
– Alex Shesterov
Jan 4 at 12:00
have you tried to use
toByteArray?– Leonardo Alves Machado
Jan 4 at 12:03
@LeonardoAlvesMachado yes not working...could you suggest if you have a way to use it.
– Shubham Sahay
Jan 4 at 12:26
The proper way would be to not have the
ByteArrayOutputStreamat all, but instead wrap the file input stream in aCipherInputStreamor otherwise a customFilterInputStream, so it is decrypted while being read. There should be no need to read and decrypt the entire file to a byte array and then read it back.– Mark Rotteveel
Jan 4 at 12:37
@ShubhamSahay I didn't quite understand why you are using an output class (used to write to streams, in your case) in order to read stuff. When I said to use
toByteArray, I meant to give you the data that it contains, so you could use it in an input class (used to read data) of your choice... If you couldn't get the data from it, you might be able to get it from the variableoutputBytesin your code.– Leonardo Alves Machado
Jan 4 at 12:57