All Questions
Tagged with bytebuffer string
26 questions
-1
votes
1
answer
65
views
First byte is suddenly zeroed while converting to CString
I want to do FFI call. To do so i need to convert a Rust string into C-zero-terminated-string in a proper encoding. I wrote this code but somehow it replaces first byte with zero. Why this happen? How ...
2
votes
0
answers
177
views
How can I undo this Base64 encoding? (Scala)
I have a piece of code which does some encoding like so:
def byteBufferToString(b: ByteBuffer): String = java.util.Base64.getEncoder.encodeToString(bb.array)
I'd also like another method which does ...
1
vote
1
answer
921
views
Read byte represented file in python as utf-8 characters
I have a .txt file generated by a built-in tool in Windows OS that I need to parse in a python script (on a Linux machine if it is relevant).
I open the file as such:
with open(path, 'r') as spec_file:...
1
vote
2
answers
1k
views
strings.Builder memory usage
Using this file (data file):
package main
import (
"io/ioutil"
"time"
)
func main() {
ioutil.ReadFile("100mb.file")
time.Sleep(time.Duration(time.Minute))
}
...
-1
votes
1
answer
372
views
ByteBuffer discards trailing newline [closed]
Here is how I put a string to ByteBuffer
String message="Hello\n\n";
ByteBuffer bresult = ByteBuffer.allocate(message.getBytes().length);
bresult.put(message.getBytes());
bresult.flip();
...
3
votes
1
answer
4k
views
Converting a String to ByteBuffer in Java
I want to convert an ASCII string to a ByteBuffer and I came across these two approaches:
ByteBuffer.wrap(str.getBytes(StandardCharsets.US_ASCII));
and
StandardCharsets.US_ASCII.encode(str);
What is ...
0
votes
1
answer
837
views
Java: Convert bit string to byte[]
I want to write a bit string into a byte array such that the byte array literally contains the bitstring
I have a String with value "10000110" and I want to convert this into a byte array with ...
0
votes
1
answer
144
views
ByteBuffer Missing Data When decoded As string
I'm reading and writing to a ByteBuffer
import org.assertj.core.api.Assertions;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
...
1
vote
2
answers
1k
views
Java - '\' not being used to escape double quotes " in string
I have some JSON content in bytebuffer as : {\"ID\":101}"}
This content is being returned from a service invocation. I get result from that microservice in a bytebuffer. (This means - I cannot get ...
0
votes
4
answers
4k
views
std::string vs. byte buffer (difference in c++)
I have a project where I transfer data between client and server using boost.asio sockets. Once one side of the connection receives data, it converts it into a std::vector of std::strings which gets ...
2
votes
4
answers
985
views
How to serialize String to an existed ByteBuffer efficiently?
It seems that String.getBytes() will create a new byte array, so there is an extra memory copy. Can I encode a String directly to a ByteBuffer without an intermediate byte array?
for example:
void ...
2
votes
2
answers
2k
views
Problems Converting Between ByteBuffer and String in Java
I'm currently developing an application where users can edit a ByteBuffer via a hex editor interface and also edit the corresponding text through a JTextPane. My current issue is because the JTextPane ...
3
votes
1
answer
974
views
Java: String.getBytes(Charset) Vs. Charset.encode(String) for use with OutputStream
I am in the situation that my algorithm has the 2 inputs of:
1 utf8 String object that will be encoded
1 Charset object which indicates what I need to encode the string into
In the end, the ...
0
votes
1
answer
93
views
How can I get byteSize of String Array other than traversing the Array
I want to optimize my code by using ByteBuffer in place of String. What I am getting is String[]. I am doing formatting on each element of it.
e.g. String strAry[] = {"Help", "I", "am", "trapped", "...
0
votes
1
answer
1k
views
Append bytes to string in python
I have bytes array as str and want to send it (if I look at it through a debugger, it shows me that File.body is str). For that reason I have to create message to send.
request_text += '\n'.join([
...
0
votes
1
answer
165
views
Byte Conversion From Hex String Keeps Failing With Alphabet characters "G" and upwards in C#
I'm trying to build a simple XOR function that decrypts a hex key from a single character. It works with multiple characters and individual characters... but only from "A" through to "F". From "G" ...
0
votes
1
answer
113
views
How to process sequence of bytes in java?
I have stream of bytes and I need to form these bytes as a frame when I get particular Header.
Example:
Header: ABC
Source: DFDFDFDF'ABC'IEJENFAREABCOEKRERIERE
If ABC is detected, rest of ...
0
votes
1
answer
3k
views
ByteBuffer to String
I have developed an application for Http Request and Response in Tizen. I am successfully able to post and get the response.(Checked Body length).
The response which I got is in ByteBuffer.
...
2
votes
3
answers
802
views
Byte buffer exception for strings of length less than 4
I am trying to convert Strings to their integer equivalents for faster comparison using ByteBuffer (java.nio.ByteBuffer).
I got a very peculiar exception using ByteBuffer.
public class LargeCompare {...
3
votes
2
answers
10k
views
Convert a part of ByteBuffer back to String
I have a big String that was once converted to a ByteBuffer & then while reading later several times, only a portion of the String(overview of the text) needs to be presented, so I want to convert ...
4
votes
5
answers
7k
views
Find a string inside a bytebuffer
I'm switching from C to Java. I'm wondering about how to find a string inside a bytebuffer, is there something like memchr in java? The bytebuffer is only partly a string, the rest is raw bytes so any ...
3
votes
1
answer
12k
views
How to convert from ByteBuffer to Integer and String?
I converted an int to a byte array using ByteBuffer's putInt() method. How do I do the opposite? So convert those bytes to an int?
Furthermore, I converted a string to an array of bytes using the ...
0
votes
2
answers
2k
views
Handle byte[] with ByteBuffer
I try to access a byte[] via a ByteBuffer in order to represent a file-type I defined. The first positions within the byte[] contain some Metadata and get treated with bit-manipulations. So they do ...
1
vote
1
answer
1k
views
Converting part of a ByteBuffer to a String
I have a ByteBuffer containing bytes that were derived by String.getBytes(charsetName), where "containing" means that the string comprises the entire sequence of bytes between the ByteBuffer's ...
99
votes
3
answers
177k
views
Java: Converting String to and from ByteBuffer and associated problems
I am using Java NIO for my socket connections, and my protocol is text based, so I need to be able to convert Strings to ByteBuffers before writing them to the SocketChannel, and convert the incoming ...
1
vote
4
answers
3k
views
Reading a UTF-8 String from a ByteBuffer where the length is an unsigned int
I am trying to read a UTF8 string via a java.nio.ByteBuffer. The size is an unsinged int, which, of course, Java doesn't have. I have read the value into a long so that I have the value.
The next ...