bytebuffer

How to convert ByteBuffer into image in Android

泪湿孤枕 提交于 2019-12-22 09:50:07
问题 I am receiving jpg image through socket and it is sent as ByteBuffer what I am doing is: ByteBuffer receivedData ; // Image bytes byte[] imageBytes = new byte[0]; // fill in received data buffer with data receivedData= DecodeData.mReceivingBuffer; // Convert ByteByffer into bytes imageBytes = receivedData.array(); ////////////// // Show image ////////////// final Bitmap bitmap = BitmapFactory.decodeByteArray(imageBytes,0,imageBytes.length); showImage(bitmap1); But what is happening that it

How to put data from an OutputStream into a ByteBuffer?

泄露秘密 提交于 2019-12-22 01:33:51
问题 In Java I need to put content from an OutputStream (I fill data to that stream myself) into a ByteBuffer. How to do it in a simple way? 回答1: You can create a ByteArrayOutputStream and write to it, and extract the contents as a byte[] using toByteArray() . Then ByteBuffer.wrap(byte []) will create a ByteBuffer with the contents of the output byte array. 回答2: There is a more efficient variant of @DJClayworth's answer. As @seh correctly noticed, ByteArrayOutputStream.toByteArray() returns a copy

Equivalent of Java's “ByteBuffer.putType()” in C#

佐手、 提交于 2019-12-21 20:28:39
问题 I am trying to format a byte array in C#, by porting a code from Java. In Java, the methods "buf.putInt(value);", buf.putShort, buf.putDouble, (and so forth) are used. However I don't know how to port this to C#. I have tried the MemoryStream class, but there is no method to put a specific type at the end of the byte array. Question: What is the equivalent of Java's "ByteBuffer.putType(value)" in C#? Thanks! 回答1: You can use a BinaryWriter and your MemoryStream: MemoryStream stream = new

Is there an explanation for the behavior of this Java ByteBuffer?

青春壹個敷衍的年華 提交于 2019-12-21 05:22:39
问题 I need to convert numerical values into byte arrays. For example, to convert a long to a byte array, I have this method: public static byte[] longToBytes(long l) { ByteBuffer buff = ByteBuffer.allocate(8); buff.order(ByteOrder.BIG_ENDIAN); buff.putLong(l); return buff.array(); } It's pretty straightforward - take a long, allocate an array that can hold it, and throw it in there. Regardless of what the value of l is, I will get an 8 byte array back that I can then process and use as intended.

Determine number of Bytes in ByteBuffer

不打扰是莪最后的温柔 提交于 2019-12-21 03:33:28
问题 I have a ByteBuffer that can hold a maximum of (4 + size ) bytes (that is, an integer followed by size characters). However, the number of characters written to the ByteBuffer , may be smaller than size . So I was wondering, is there anyway to determine how many characters were written to the ByteBuffer and not just the total size of it? limit , position and such don't SEEM to be what I am after. Thanks for your help! 回答1: After you've written to the ByteBuffer, the number of bytes you've

BufferedReader for large ByteBuffer?

家住魔仙堡 提交于 2019-12-20 02:13:34
问题 Is there a way to read a ByteBuffer with a BufferedReader without having to turn it into a String first? I want to read through a fairly large ByteBuffer as lines of text and for performance reasons I want to avoid writing it to the disk. Calling toString on the ByteBuffer doesn't work because the resulting String is too large (it throws java.lang.OutOfMemoryError: Java heap space). I would have thought there would be something in the API to wrap a ByteBuffer in a suitable reader, but I can't

File Channel reads/adds wrong data

匆匆过客 提交于 2019-12-20 01:39:24
问题 I am using a filechannel with a byte buffer to send packets over the network. My problem is that when the filechannel reads the last few bytes it appends the last bit of data from previous bytes read even though I am clearing the byte buffer after I write. For example, Byte Buffer size = 512 For the last iteration, the remaining bytes to send is 372. It reads the last 372 but it also appends another 140 bytes (512-372) to the end of it, and appears that last 140 bytes is from the previous 512

record voice in a Queue<byte[]> and send it to the server

强颜欢笑 提交于 2019-12-19 09:44:01
问题 I am developing voice application. I need a buffer queue of some sort so that i record continuosly in a thread , place the buffers full of bytes into the queue and to transmit to the server, and i take the next buffer from the queue. Here is the recording code: Queue<byte[]> qArray = new LinkedList<byte[]>(); recordingThread = new Thread(new Runnable() { @Override public void run() { bData = new byte[BufferElements]; while (isRecording) { recorder.read(bData, 0, BufferElements); qArray.add

Get the pointer of a Java ByteBuffer though JNI

╄→尐↘猪︶ㄣ 提交于 2019-12-18 13:19:51
问题 How can I get a pointer to the inner array of a Java ByteBuffer? JNIEXPORT void JNICALL test(JNIEnv *env, jobject thiso) { jclass cls = env->FindClass("java/nio/ByteBuffer"); jmethodID aloc = env->GetStaticMethodID(cls, "allocateDirect", "(I)Ljava/nio/ByteBuffer;"); jobject obj = env->CallStaticObjectMethod(cls, aloc, 1000); } PS: I'm doing that to share the memory used by Java and C++. 回答1: void * data = env->GetDirectBufferAddress(obj); The ByteBuffer must be a direct one for this to work.

Compare Direct and Non-Direct ByteBuffer get/put operations

最后都变了- 提交于 2019-12-18 12:32:19
问题 Is get/put from a non-direct bytebuffer faster than get/put from direct bytebuffer ? If I have to read / write from direct bytebuffer , is it better to first read /write in to a thread local byte array and then update ( for writes ) the direct bytebuffer fully with the byte array ? 回答1: Is get/put from a non-direct bytebuffer faster than get/put from direct bytebuffer ? If you are comparing heap buffer with direct buffer which does not use native byte order (most systems are little endian and