How to garbage collect a direct buffer in Java

I have a memory leak that I have isolated to incorrectly disposed direct byte buffers. ByteBuffer buff = ByteBuffer.allocateDirect(7777777); The GC collects the objects that harbor these buffers...

converting Java bitmap to byte array

Bitmap bmp = intent.getExtras().get("data"); int size = bmp.getRowBytes() * bmp.getHeight(); ByteBuffer b = ByteBuffer.allocate(size); bmp.copyPixelsToBuffer(b); byte[] bytes =...

Android: How can you get framebuffer (screenshot) on rooted device?

I tried : process = Runtime.getRuntime().exec("su -c cat /dev/graphics/fb0 > /sdcard/frame.raw"); process.waitFor(); but it doesn't work. My device is rooted. I see many answers that it requires...

Getting RSA private key from PEM BASE64 Encoded private key file

I have a private key file (PEM BASE64 encoded). I want to use it else where to decrypt some other data.Using Java i tried to read the file and decode the BASE64 encoded data in it... This is the...

Convert a Pdf page into Bitmap in Android Java

I need to convert PDFfile(PDF page) into a Bitmap(or Image file) in Android. 1.Used Pdfbox jar from Apache. But it uses some java classes that is not supported in android. 2. Tried Itext jar which...

How to append one ByteBuffer to other?

Suppose that I have 2 ByteBuffer containing some bytes in it... How would be the best way to append all the content of one ByteBuffer with other? I'm doing this but it throws a...

why client can not receive message from server (java)

I have just started learning java. I modified the client side code for a server/client communication program, by creating two threads for the client side, main thread for receiving user's input,...

JavaFX DragAndDrop with custom DataFormat

The Overview I am setting up drag & drop in a Java FX application. When I try to grab custom data from the Dragboard I am getting a java.nio.HeapByteBuffer instead of an Object as the JavaDoc...

Rotation issue in 3D Model in OpenGl

I want to rotate the object z axis so I am using the below code but its not rotating at particular position its rotation just go back and appear come near. I think there is wrong with the values...

Java - Heap vs Direct memory access

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...

Static Extension Function on a Java Class

Is it possible to add a static extension function similar to a adding an extension function to a companion object. I tried public fun ByteBuffer.Companion.invoke(capacity: Int): ByteBuffer but...

MediaMuxer video file size reducing (re-compress, decrease resolution)

I'm looking for efficient way to reduce some video weight (as a File, for upload) and obvious answer for that is: lets reduce resolution! (fullHD or 4K not needed, simple HD is sufficient for me)...

Android Camera2 Wrong Rotation

I'm trying to implement android.hardware.camera2, but I'm a little bit confused with it. The camera is rotating with the phone. BEFORE Taking the picture, If I rotated the phone the camera is...

How to serialize Java POJOs generated from Avro

I am trying to write a generic serializer for my Avro-generated Java objects. By begging, borrowing and stealing I came up with the following method: public byte[] serialize(T data)...

How Java GC Does Direct Byte Buffer Clean Up, Because IBM Docs says, It Does.

I assumed, I understood how Bytebuffer and DirectByteBuffer differs until i read a artical on IBM documentation, metioning : "Direct ByteBuffer objects clean up their native buffers automatically...

What is the purpose of a Buffer in Java?

Buffer is an abstract class having concrete subclasses such as ByteBuffer, IntBuffer, etc. It seems to be a container of data of a specific primitive type. What are the benefits of a Buffer? Why...

Converting Bitmap to ByteBuffer (float) in Tensorflow-lite Android

In tensorflow-lite android demo code for image classification, the images are first converted to ByteBuffer format for better performance.This conversion from bitmap to floating point format and...

Parsing files over 2.15 GB in Java using Kaitai Struct

I'm parsing large PCAP files in Java using Kaitai-Struct. Whenever the file size exceeds Integer.MAX_VALUE bytes I face an IllegalArgumentException caused by the size limit of the underlying...

OnImageAvailableListener is not being invoked for Camera2 API for taking a photo

I am trying to take a photo using the Camera2 API. The API is currently used to produce a preview on a SurfaceView on my screen which works fine, but when i try to capture image, the...

How to decrease frame rate of Android CameraX ImageAnalysis?

How to decrease the frame rate to 1 fps in image analysis so that I don't detect barcode multiple times. In my use-case, scanning the same barcode multiple times with a 1-second interval should...

Using MediaCodec in async mode, issue is, I am not getting MediaCodec.BUFFER_FLAG_END_OF_STREAM

I am building a streaming app. I am facing a problem, here is code I want to live stream camera feed to the server and I hope I will get ByteBuffer in onOutputBufferAvailable(). I am getting...

Cassandra Windows 10 Access Violation

EDIT: Although yukim's workaround does work, I found that by downgrading to JDK 8u251 vs 8u261, the sigar lib works correctly. Windows 10 x64 Pro Cassandra 3.11.7 NOTE: I have JDK 11.0.7 as my...

Ktor response streaming

I am trying to call a twitter endpoint that gives you a constant streams of json results back to the...

SocketChannel. invalid stream header: 00000000

I want to serialize 'Message' object, I can successfully transfer it as bytes array through socketChannel. After that, I change the object's properties (so that it may have larger size), and then...

Get ByteBuffer from Image for TensorFlow Lite Model

I am creating an android app to run on Google Glass Enterprise Edition 2 that does Real-time Face Recognition. I am using Camera X as my Camera API and TensorFlow Lite (TFLite) as my...

Android MediaExtractor: Slow Speed when reading mp3 file

So, I am trying to extract raw PCM data from compressed audio files "in one go", i.e. reading the entire file as fast as possible and outputting the result (no "streaming"). I've got a working...

The size of byte buffer and the shape do not match (previously not answered)

I am trying to create a app that uses tensorflow model. My app crashes when inputFeature0.loadBuffer(byteBuffer) gets executed. ( got to know by commenting the lines) var...

Java OpenAL - Source gain of zero after passing the max distance

(Sorry for my bad English) Hi, I'm learning LWJGL 3 OpenAL library. Playing around with the 3D audio attenuation, I noticed that you can't get a gain of zero for a source using a good realistic...

Android studio gives me a lot of hidden methods warning

i am working on an Android project and i am getting a lot of access hidden methods warning and i don't know what i am doing wrong. My application works fine so i really don't know what to do to...

Direct buffer memory OutOfMemoryError after updating to wildfly 18

After updating the environment from Wildfly 13 to Wildfly 18.0.1 we experienced an A channel event listener threw an exception: java.lang.OutOfMemoryError: Direct buffer memory at...