byte

Insert Java byte[] object into an H2 table and then retrieve it again

给你一囗甜甜゛ 提交于 2019-12-10 10:42:54
问题 I'm trying to insert a Java byte[] into an H2 database table and then retrieve it again, but i am not achieving success. According to this page, the BINARY data type maps directly to a byte[]. So my understanding is i can write the byte[] variable directly to the column, but it is resulting in an exception when i try to retrieve it again. Here is a SSCCE that illustrates my problem. What am i doing wrong here? PS: You need to have an H2 database installed to run this code. package coza.modh

Java (J2ME) Convert Image to byte[], then back to Image

别说谁变了你拦得住时间么 提交于 2019-12-10 10:24:20
问题 I'm trying to convert an Image object to a byte array then back to an Image (so that I can store the image in a blob object in an Apache Derby Database). I can convert an Image to a byte array (code below) but I cann't convert the bytes back to an image. As a further complication I'm using J2ME, so I can't use javax.image.*. Can you help? Thanks package six.util; import java.awt.Image; import java.awt.image.BufferedImage; import java.awt.image.ImageObserver; import java.awt.Component; import

Converting raw byte data to float[]

别等时光非礼了梦想. 提交于 2019-12-10 09:55:36
问题 I have this code for converting a byte[] to float[] . public float[] ConvertByteToFloat(byte[] array) { float[] floatArr = new float[array.Length / sizeof(float)]; int index = 0; for (int i = 0; i < floatArr.Length; i++) { floatArr[i] = BitConverter.ToSingle(array, index); index += sizeof(float); } return floatArr; } Problem is, I usually get a NaN result! Why should this be? I checked if there is data in the byte[] and the data seems to be fine. If it helps, an example of the values are: new

Converting short array to byte array in JAVA

时光总嘲笑我的痴心妄想 提交于 2019-12-10 09:51:46
问题 I am confused on how to convert short array to byte array. E.g. I have the follwoing short array short[] shrt_array = new short[]{ 0x4 , 0xd7 , 0x86, 0x8c, 0xb2, 0x14, 0xc, 0x8b, 0x2d, 0x39, 0x2d, 0x2d, 0x27, 0xcb, 0x2e, 0x79, 0x46, 0x36, 0x9d , 0x62, 0x2c }; By using this link Converting short array to byte array the two methods of conversion, I get the following two different byte arrays: expectedByteArray = new byte[] { (byte) 0x4, (byte) 0xd7, (byte) 0x86, (byte) 0x8c, (byte) 0xb2, (byte)

Calculating the maximum size of a signed integer

江枫思渺然 提交于 2019-12-10 09:46:26
问题 I wanted to know what the maximum value my time_t can hold was, so I wrote a little program helping me. It needs one argument: the amount of bytes (1 byte = 8 bits). So I wrote it and tested it. It goes well by all values from 1 untill 4, but at 5 and higher it also edits the "signed"-bit (I don't know how it's called). Can someone explain: #include <stdio.h> int main(int argc, const char **argv) { if(argc != 2) { fprintf(stderr, "Usage: %s bits/8\n", argv[0]); return -1; } unsigned int bytes

Encode byte[] as String

北战南征 提交于 2019-12-10 04:35:03
问题 Heyho, I want to convert byte data, which can be anything, to a String. My question is, whether it is "secure" to encode the byte data with UTF-8 for example: String s1 = new String(data, "UTF-8"); or by using base64: String s2 = Base64.encodeToString(data, false); //migbase64 I'm just afraid that using the first method has negative side effects. I mean both variants work p̶e̶r̶f̶e̶c̶t̶l̶y̶ , but s1 can contain any character of the UTF-8 charset, s2 only uses "readable" characters. I'm just

Processing Huge Files In C#

吃可爱长大的小学妹 提交于 2019-12-10 03:49:10
问题 I have a 4Gb file that I want to perform a byte based find and replace on. I have written a simple program to do it but it takes far too long (90 minutes+) to do just one find and replace. A few hex editors I have tried can perform the task in under 3 minutes and don't load the entire target file into memory. Does anyone know a method where I can accomplish the same thing? Here is my current code: public int ReplaceBytes(string File, byte[] Find, byte[] Replace) { var Stream = new FileStream

How to remove those “\x00\x00”

喜你入骨 提交于 2019-12-10 02:34:00
问题 How to remove those "\x00\x00" in a string ? I have many of those strings (example shown below). I can use re.sub to replace those "\x00". But I am wondering whether there is a better way to do that ? Converting between unicode, bytes and string is always confusing. 'Hello\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'. 回答1: Use rstrip >>> text = 'Hello\x00\x00\x00\x00' >>> text.rstrip('\x00'

Count bit/byte size of array

人走茶凉 提交于 2019-12-10 01:54:43
问题 I have an array in Javascript that has lot of sub arrays. What would be the best/simplest way to count how many bits/bytes the array holds? I'm gonna send the array to my PHP server, and it can only be 5kB big. Is there a native method for this? I'm not so very well acquainted with bits. If I understood it correctly 1 character fits in 8b/1B (although it depends on the encoding obviously). Would the best way be to loop through all arrays and count the characters? 回答1: First you have to

How to convert Byte array to ByteArrayOutputStream

蹲街弑〆低调 提交于 2019-12-10 01:04:54
问题 I need to convert a byte array to ByteArrayOutputStream so that I can display it on screen. 回答1: byte[] bytes = ....; ByteArrayOutputStream baos = new ByteArrayOutputStream(bytes.length); baos.write(bytes, 0, bytes.length); Method description: Writes len bytes from the specified byte array starting at offset off to this byte array output stream. 回答2: You can't display a ByteArrayOutputStream. What I suspect you are trying to do is byte[] bytes = ... String text = new String(bytes, "UTF-8"); /