bytebuffer

How to convert YUV to bitmap in landscape orientation?

徘徊边缘 提交于 2019-12-11 16:07:35
问题 First Method When I set javasetRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); or java setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); Camera2 is running fine and save image from imageavailablelistener. Second Method When I set java setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); or java setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE); It will exit from the app and cannot save image Conversion Credit YUV Image to

Java: reading a variable number of bits and converting to an integer

China☆狼群 提交于 2019-12-11 09:04:14
问题 I need to write a method which reads a variable number of bits from a Byte Buffer and converts those bytes into a primitive int or long (if more than 32 bits). I am not very proficient at working with bits, but I did look at some code examples and answers to similar(ish) questions and here is the best that I could come up with ( bb refers to an internal ByteBuffer ): public int readBits(int number) { int initialPosition = bb.position(); int value = 0; int remaining = number; int position = bb

How to serialize String to an existed ByteBuffer efficiently?

橙三吉。 提交于 2019-12-11 06:28:14
问题 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 putString(ByteBuffer bb, String s) { byte[] arr = s.getBytes(StandardCharsets.UTF_8); bb.put(arr); } This piece of code will create a byte array, encode the string to this byte array, then copy the content of byte array to ByteBuffer. I think the byte array is not necessary, it will bring GC and

How to convert signed 16 bit integer to unsigned 16 bit integer in Java?

半城伤御伤魂 提交于 2019-12-11 04:19:38
问题 I have my below layout in which I need to represent my data and then finally I need to make one byte array out of that. I need to represent my data in the below format from Java code and then send the byte array to my C++ program which in turns c++ program unpacks the byte array and extract the relevant stuff from it - // below is my data layout - // // key type - 1 byte // key len - 1 byte // key (variable size = key_len) // timestamp (sizeof uint64_t) // data size (sizeof uint16_t), this is

Get IP packet data from ByteBuffer

江枫思渺然 提交于 2019-12-11 01:41:03
问题 I'm trying to get the source and destination address from a packet. This is how i am reading the packet: private void debugPacket(ByteBuffer packet) { int buffer = packet.get(); int ipVersion = buffer >> 4; int headerLength = buffer & 0x0F; headerLength *= 4; buffer = packet.get(); //DSCP + EN int totalLength = packet.getChar(); //Total Length buffer = packet.getChar(); //Identification buffer = packet.getChar(); //Flags + Fragment Offset buffer = packet.get(); //Time to Live int protocol =

Memory-mapping a file in Windows with SHARE attribute (so file is not locked against deletion)

爷,独闯天下 提交于 2019-12-10 19:51:24
问题 Is there any way to map a file's content into memory in Windows that does not hold a lock on the file (in particular, such that the file can be deleted while still mmap'd)? The Java NIO libraries mmap files in Windows in such a way that the mapped file cannot be deleted while there is any non garbage collected MappedByteBuffer reference left in the heap. The JDK team claim that this is a limitation of Windows, but only when files are mmap'd, not when they are opened as regular files: https:/

Java复习--IO(输入/输出){Java NIO}

本小妞迷上赌 提交于 2019-12-10 19:34:48
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> http://my.oschina.net/u/2263278/blog/508770 中介绍的BufferedReader时提到它的一个特征----当BufferedReader读取输入流中的数据时,如果没有读到有效数据,程序将在此处阻塞该线程的执行(使用InputStream的read()方法从流中读取数据时,如果数据源中没有数据,它也会阻塞该线程),也就是前面介绍的输入流、输出流都是阻塞式的输入、输出。传统的输入流、输出流都是通过字节的移动来处理的,即使我们不直接去处理字节流,但底层的实现还是依赖于字节处理,面向流的输入/输出系统一次只能处理一个字节,因此面向流的输入/输出系统通常效率不高。从JDK1.4开始,Java提供了一些新IO,这些类都放在java.nio包及其子包下。 一、Java新IO概述 Java的NIO采用了内存映射文件的方式来处理输入/输出,新IO将文件或文件的一段区域映射到内存中,这样就可以像访问内存一样来访问文件了(这种方式模拟了操作系统上的虚拟内存的概念),通过这种方式进行输入/输出比传统的输入/输出要快的多。 Channel和Buffer是NIO中两个核心对象,Channel是对传统的输入/输出系统的模拟,在NIO系统中所有的数据都需要通过通道Channel传输

A first chance exception of type 'System.ArgumentOutOfRangeException' occurred in mscorlib.dll

核能气质少年 提交于 2019-12-10 17:37:20
问题 Im new to c# client and server application, im working on a file upload client and server application. i can successfully upload my file name and file data to the server from the client application. but when i try to implement a new textbox that allow the file upload client to enter his/her name and send the information together with the file name and file data when he/her click the send button. client application. /* file name and file length */ byte[] fName = Encoding.UTF8.GetBytes(fileName

JAVA NIO Bytebuffer.allocateDirect() size limit over the int

帅比萌擦擦* 提交于 2019-12-10 10:34:15
问题 I am trying to make off-heap memory buffer. I want very big size(like 10GB) buffer. I heard that jvm heap sometimes freeze because full GC. So, I try to make buffer with java.nio.ByteBuffer. But, I met great difficulties! java.nio.ByteBuffer.allocateDirect(int size) function only support integer. but I want bigger size. what can I do? what should I do? please help me stack overflow gurus. my development environment is macbook pro, i7 2.4ghz, 16gb ddr3, 250ssd, osx 10.9, eclipse kepler x64. I

concatenate two byteBuffers to a single

我的梦境 提交于 2019-12-10 06:31:20
问题 Hi I've 2 byteBuffers and I want to concatenate them together to a single byteBuffer. I found a similar question here but none of the suggestions there worked for me. 回答1: You can do it like this ByteBuffer b3 = ByteBuffer.allocate(b1.limit() + b2.limit()); b3.put(b1); b3.put(b2); 来源: https://stackoverflow.com/questions/30734268/concatenate-two-bytebuffers-to-a-single