bytebuffer

Convert ByteBuffer to byte array java [duplicate]

可紊 提交于 2019-12-03 09:27:24
This question already has answers here : Gets byte array from a ByteBuffer in java (6 answers) Does anyone know how to convert ByteBuffer to byte[] array? I need to get byte array from my ByteBuffer . When I run bytebuffer.hasArrray() it returns no. Every question I looked so far is converting byte array to byteBuffer, but I need it other way around. Thank you. nomis ByteBuffer exposes the bulk get(byte[]) method which transfers bytes from the buffer into the array. You'll need to instantiate an array of length equal to the number of remaining bytes in the buffer. ByteBuffer buf = ... byte[]

media extractor show “failed to instantiate extractor”

匿名 (未验证) 提交于 2019-12-03 08:54:24
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am trying to work on media extractor for audio streaming of OGG file format on android. I have written some code with help of google documents. but it doesn't work at all. May be i have Written a wrong code or syntax As i am student. it show me failed to instantiate extractor public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); MediaExtractor extractor = new MediaExtractor(); extractor.setDataSource("http://examplelink.com/ogg");// I cant put real link so sorry for

Atomic read then write of part of a ByteBuffer in Java

匿名 (未验证) 提交于 2019-12-03 08:48:34
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've got a ByteBuffer in java, and want to read, then conditionally modify that byte, e.g. with a method like: public void updateByte(int index) { byte b = this.buffer.getByte(index); if (b == someByteValue) { this.buffer.setByte(index, someNewByte); } } How can I ensure that the reading then modifying of a byte happens atomically? I don't want to synchronize the entire ByteBuffer or updateByte method, since I want multiple threads to be able to read/write different bytes of the buffer at the same time (i.e. updateByte can be called

Attempt to get length of null array in google maps V2 android app

匿名 (未验证) 提交于 2019-12-03 08:41:19
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am currently developing an android application using google maps api and I sometimes get a weird crash (in my opinion) for no ovious reason. Here's the crash log : 12-02 16:38:57.071 20796-21137/com.appsolute.ParkYoo E/AndroidRuntime: FATAL EXCEPTION: GLThread 4623 Process: com.appsolute.ParkYoo, PID: 20796 java.lang.NullPointerException: Attempt to get length of null array at java.nio.DirectByteBuffer.put(DirectByteBuffer.java:399) at java.nio.ByteBufferAsShortBuffer.put(ByteBufferAsShortBuffer.java:159) at com.google.maps.api.android

基于NIO写的阻塞式和非阻塞式的客户端服务端

时光怂恿深爱的人放手 提交于 2019-12-03 04:58:29
由于功能太过简单,就不过多阐述了,直接上阻塞式代码: package com.lql.nio; import org.junit.Test; import java.io.IOException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; import java.nio.file.Paths; import java.nio.file.StandardOpenOption; /** * @author: lql * @date: 2019.11.01 * Description: 客户端发送一条数据给服务端,服务端接收后反馈一条信息 */ public class TestBlockingNIO2 { @Test public void client() { SocketChannel socketChannel = null; FileChannel inChannel = null; try { //获取通道 socketChannel =

Growing ByteBuffer

末鹿安然 提交于 2019-12-03 04:06:28
问题 Has anyone has ever seen an implementation of java.nio.ByteBuffer that will grow dynamically if a putX() call overruns the capacity? The reason I want to do it this way is twofold: I don't know how much space I need ahead of time. I'd rather not do a new ByteBuffer.allocate() then a bulk put() every time I run out of space. 回答1: In order for asynchronous I/O to work, you must have continuous memory. In C you can attempt to re-alloc an array, but in Java you must allocate new memory. You could

How to use ByteBuffer in the MediaCodec context in android

匿名 (未验证) 提交于 2019-12-03 02:48:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: So far I am able to setup a MediaCodec to encode a video stream. The aim is to save my user generated artwork into a video file. I use android Bitmap objects of the user artwork to push frames into the stream. See the code snippet I use at the bottom of this post (it is the full code nothing is trimmed): MediaCodec uses ByteBuffer to deal with video/audio streams. Bitmaps are based on int[] which if converted to byte[] will require x4 the size of the int[] I did some research to figure out what contracts are there in place for the ByteBuffer

Java - Heap vs Direct memory access

*爱你&永不变心* 提交于 2019-12-03 02:27:45
问题 I recenty came across sun.misc.Unsafe class, allowing user to allocate,deallocate and in general access memory in a similar fashion like in C. I read in a couple of blogs that tackle this issue e.g. Which is faster - heap or direct memory - test results claim heap Off-heap memory vs DirectByteBuffer vs Heap - Off-heap seems to be fastest Memory mapped files for time series data - MappedByteBuffer faster than heap objects Article 1) seems to be in contradiction with the other ones and I fail

RuntimeException: Buffer not large enough for pixels

匿名 (未验证) 提交于 2019-12-03 02:27:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm receiving a Bitmap in byte array through socket and I read it and then I want to set it os.toByteArray as ImageView in my application. The code I use is: try { //bmp = BitmapFactory.decodeByteArray(result, 0, result.length); bitmap_tmp = Bitmap.createBitmap(540, 719, Bitmap.Config.ARGB_8888); ByteBuffer buffer = ByteBuffer.wrap(os.toByteArray()); bitmap_tmp.copyPixelsFromBuffer(buffer); Log.d("Server",result+"Length:"+result.length); runOnUiThread(new Runnable() { @Override public void run() { imageView.setImageBitmap(bitmap_tmp); } });

Java InputStream to ByteBuffer

匿名 (未验证) 提交于 2019-12-03 02:24:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am reading dds textures, but since once built the jar I can't access those textures through url and file and have to use InputStream instead. So I would need to know how I can obtain a from an java.io.InputStream . Ps: no matter through 3rd part libraries, I just need it working 回答1: For me the best in this case is Apache commons-io to handle this and similar tasks. The IOUtils type has a static method to read an InputStream and return a byte[] . InputStream is; byte[] bytes = IOUtils.toByteArray(is); Internally this creates a