bytearray

How to read a bytearray in JNI?

大城市里の小女人 提交于 2019-12-22 07:24:12
问题 Is it possible to just reference a entire bytearray in JNI but not invoking any copy ? In native C code, I have a bytearray passing from Java, and I just want to compare some data to this bytearray so I do not want to do any memory copy. Is it possible ? I know I could get the pointer of a bytearray in native by using GetPrimitiveArrayCritical something like that JNIEXPORT jbyteArray JNICALL Java_nfore_android_bt_pro_nfhfp_dsp (JNIEnv *env, jobject jobj, jbyteArray jbIn, jbyteArray jbBase){

Reading an ASCII file with FileChannel and ByteArrays

我只是一个虾纸丫 提交于 2019-12-22 06:17:11
问题 I have the following code: String inputFile = "somefile.txt"; FileInputStream in = new FileInputStream(inputFile); FileChannel ch = in.getChannel(); ByteBuffer buf = ByteBuffer.allocateDirect(BUFSIZE); // BUFSIZE = 256 /* read the file into a buffer, 256 bytes at a time */ int rd; while ( (rd = ch.read( buf )) != -1 ) { buf.rewind(); for ( int i = 0; i < rd/2; i++ ) { /* print each character */ System.out.print(buf.getChar()); } buf.clear(); } But the characters get displayed at ?'s. Does

Reading an ASCII file with FileChannel and ByteArrays

别说谁变了你拦得住时间么 提交于 2019-12-22 06:17:10
问题 I have the following code: String inputFile = "somefile.txt"; FileInputStream in = new FileInputStream(inputFile); FileChannel ch = in.getChannel(); ByteBuffer buf = ByteBuffer.allocateDirect(BUFSIZE); // BUFSIZE = 256 /* read the file into a buffer, 256 bytes at a time */ int rd; while ( (rd = ch.read( buf )) != -1 ) { buf.rewind(); for ( int i = 0; i < rd/2; i++ ) { /* print each character */ System.out.print(buf.getChar()); } buf.clear(); } But the characters get displayed at ?'s. Does

Java byte[] to/from String conversion

不羁的心 提交于 2019-12-22 05:53:31
问题 Why does this junit test fail? import org.junit.Assert; import org.junit.Test; import java.io.UnsupportedEncodingException; public class TestBytes { @Test public void testBytes() throws UnsupportedEncodingException { byte[] bytes = new byte[]{0, -121, -80, 116, -62}; String string = new String(bytes, "UTF-8"); byte[] bytes2 = string.getBytes("UTF-8"); System.out.print("bytes2: ["); for (byte b : bytes2) System.out.print(b + ", "); System.out.print("]\n"); Assert.assertArrayEquals(bytes,

Java byte[] to/from String conversion

你。 提交于 2019-12-22 05:53:11
问题 Why does this junit test fail? import org.junit.Assert; import org.junit.Test; import java.io.UnsupportedEncodingException; public class TestBytes { @Test public void testBytes() throws UnsupportedEncodingException { byte[] bytes = new byte[]{0, -121, -80, 116, -62}; String string = new String(bytes, "UTF-8"); byte[] bytes2 = string.getBytes("UTF-8"); System.out.print("bytes2: ["); for (byte b : bytes2) System.out.print(b + ", "); System.out.print("]\n"); Assert.assertArrayEquals(bytes,

Decode byte array to bitmap that has been compressed in Java

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-22 05:47:24
问题 I am compressing a bitmap in the following way Bitmap bmpSig = getMyBitMap(); int size = bmpSig.getWidth() * bmpSig.getHeight(); ByteArrayOutputStream out = new ByteArrayOutputStream(size); bmpSig.compress(Bitmap.CompressFormat.JPEG, 100, out); byte[] bytSig = out.toByteArray(); I am then trying to display the image in an Android ImageView from the byte array. When I do this I get an image that is completely black image. ImageView myImg = (ImageView) findViewById(R.id.img_view); myImg

Can I get a byte[] from a BitmapImage in Silverlight?

a 夏天 提交于 2019-12-22 05:32:02
问题 I'm trying to pass some representation of an image back and forth between Silverlight and a WCF service. If possible I'd like to pass a System.Windows.Media.Imaging.BitmapImage , since that would mean the client doesn't have to do any conversion. However, at some point I need to store this image in a database, meaning the image representation must be able to convert to and from byte[] . I can create a BitmapImage from a byte[] by reading the array into a MemoryStream and using BitmapImage

Can I get a byte[] from a BitmapImage in Silverlight?

偶尔善良 提交于 2019-12-22 05:31:39
问题 I'm trying to pass some representation of an image back and forth between Silverlight and a WCF service. If possible I'd like to pass a System.Windows.Media.Imaging.BitmapImage , since that would mean the client doesn't have to do any conversion. However, at some point I need to store this image in a database, meaning the image representation must be able to convert to and from byte[] . I can create a BitmapImage from a byte[] by reading the array into a MemoryStream and using BitmapImage

Java and C# - byte array to long conversion difference

China☆狼群 提交于 2019-12-22 04:53:08
问题 This is strange to me: when I run in Java byte[] data = new byte[] { 50, -106, 40, -22, -94, -119, -52, 8 }; ByteBuffer bb = ByteBuffer.wrap( data ); System.out.println( bb.getLong() ); result is 3645145936617393160 when I run in C# //unsigned values (signed&0xff) byte[] bytes = new byte[] { 50, 150, 40, 234, 162, 137, 204, 8 }; long l = BitConverter.ToInt64(bytes, 0); System.Console.Write(String.Format("{0}\n", l)); System.Console.ReadKey(); result is 634032980358633010 Can you help me to

Simplest way to copy int to byte[]

别说谁变了你拦得住时间么 提交于 2019-12-22 04:49:16
问题 I have a byte[] and i am iterating through a list of ints(and other data) and i want to copy the int to my byteArray[index*4] How do i do this? 回答1: BitConverter is quite possibly your friend. However, that generally returns you a new byte array. It also doesn't let you specify endianness. I have the EndianBitConverter class in MiscUtil which has methods to convert primitive types by copying the data directly into an existing byte array. For instance: // Copy the bytes from the integer "value