Search Results

Search found 215 results on 9 pages for 'bytearray'.

Page 3/9 | < Previous Page | 1 2 3 4 5 6 7 8 9  | Next Page >

  • OutOfMemoryException when I read FileStream 500 MB

    - by Alhambra Eidos
    Hi all, I'm using Filestream for read big file ( 500 MB) and I get the OutOfMemoryException. Any solutions about it. My Code is: using (var fs3 = new FileStream(filePath2, FileMode.Open, FileAccess.Read)) { byte[] b2 = ReadFully(fs3, 1024); } public static byte[] ReadFully(Stream stream, int initialLength) { // If we've been passed an unhelpful initial length, just // use 32K. if (initialLength < 1) { initialLength = 32768; } byte[] buffer = new byte[initialLength]; int read = 0; int chunk; while ((chunk = stream.Read(buffer, read, buffer.Length - read)) > 0) { read += chunk; // If we've reached the end of our buffer, check to see if there's // any more information if (read == buffer.Length) { int nextByte = stream.ReadByte(); // End of stream? If so, we're done if (nextByte == -1) { return buffer; } // Nope. Resize the buffer, put in the byte we've just // read, and continue byte[] newBuffer = new byte[buffer.Length * 2]; Array.Copy(buffer, newBuffer, buffer.Length); newBuffer[read] = (byte)nextByte; buffer = newBuffer; read++; } } // Buffer is now too big. Shrink it. byte[] ret = new byte[read]; Array.Copy(buffer, ret, read); return ret; } thanks in advanced,

    Read the article

  • JNI unsigned char to byte array

    - by Jeff Storey
    I'm working with a C++ library that stores image byte data in an array of unsigned characters. My jni function returns a jByteArray (which then gets converted to a BufferedImage on the java side), but I'm not sure how to fill the jByteArray from the unsigned character array (if it is possible). Can anyone provide a snippet for this last part to basically do this: // size is the size of the unsigned char array const int size = 100; unsigned char* buf = new unsigned char[size]; // buf gets passed to another library here to be populated jbyteArray bArray = env->NewByteArray(size); // now how do I get the data from buf to bArray? Thanks, Jeff

    Read the article

  • ArgumentOutOfRangeException when reading bytes from stream

    - by user345194
    I'm trying to read the response stream from an HttpWebResponse object. I know the length of the stream (_response.ContentLength) however I keep getting the following exception: Specified argument was out of the range of valid values. Parameter name: size While debugging, I noticed that at the time of the error, the values were as such: length = 15032 //the length of the stream as defined by _response.ContentLength bytesToRead = 7680 //the number of bytes in the stream that still need to be read bytesRead = 7680 //the number of bytes that have been read (offset) body.length = 15032 //the size of the byte[] the stream is being copied to The peculiar thing is that the bytesToRead and bytesRead variables are ALWAYS 7680, regardless of the size of the stream (contained in the length variable). Any ideas? Code: int length = (int)_response.ContentLength; byte[] body = null; if (length 0) { int bytesToRead = length; int bytesRead = 0; try { body = new byte[length]; using (Stream stream = _response.GetResponseStream()) { while (bytesToRead > 0) { // Read may return anything from 0 to length. int n = stream.Read(body, bytesRead, length); // The end of the file is reached. if (n == 0) break; bytesRead += n; bytesToRead -= n; } stream.Close(); } } catch (Exception exception) { throw; } } else { body = new byte[0]; } _responseBody = body;

    Read the article

  • PHP Convert C# Hex Blob Hexadecimal String back to Byte Array prior to decryption

    - by PolishHurricane
    I have a piece of data that I am receiving in hexadecimal string format, example: "65E0C8DEB69EA114567954". It was made this way in C# by converting a byte array to a hexadecimal string. However, I am using PHP to read this string and need to temporarily convert this back to the byte array. If it matters, I will be decrypting this byte array, then reconverting it to unencrypted hexadecimal and or plaintext, but I will figure that out later. So the question is, how do I convert a string like the above back to an encoded byte array/ blob in PHP? Thanks!

    Read the article

  • How do I read text from a serial port?

    - by user2164
    I am trying to read data off of a Windows serial port through Java. I have the javax.comm libraries and am able to get some data but not correct data. When I read the port into a byte array and convert it to text I get a series of characters but no real text string. I have tried to specify the byte array as being both "UTF-8" and "US-ASCII". Does anyone know how to get real text out of this? Here is my code: while (inputStream.available() > 0) { int numBytes = inputStream.read(readBuffer); System.out.println("Reading from " + portId.getName() + ": "); System.out.println("Read " + numBytes + " bytes"); } System.out.println(new String(readBuffer)); System.out.println(new String(readBuffer, "UTF-8")); System.out.println(new String(readBuffer, "US-ASCII")); the output of the first three lines will not let me copy and paste (I assume because they are not normal characters). Here is the output of the Hex: 78786000e67e9e60061e8606781e66e0869e98e086f89898861878809e1e9880 I am reading from a Hollux GPS device which does output in string format. I know this for sure because I did it through C#. The settings that I am using for communication which I know are right from the work in the C# app are: Baud Rate: 9600 Databits: 8 Stop bit: 1 parity: none

    Read the article

  • Silverlight 4.0: How to convert byte[] to image?

    - by xscape
    public Image Base64ToImage(string base64String) { // Convert Base64 String to byte[] byte[] imageBytes = Convert.FromBase64String(base64String); MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length); // Convert byte[] to Image ms.Write(imageBytes, 0, imageBytes.Length); System.Drawing.Image image = System.Drawing.Image.FromStream(ms, true); return image; } I want to convert byte[] to image, however System.Drawing.Image is not supported in Silverlight. Any alternative?

    Read the article

  • Is there a less painful way to GetBytes for a buffer not starting at 0?

    - by Earlz
    I am having to deal with raw bites in a project and I need to basically do something like this byte[] ToBytes(){ byte[] buffer=new byte[somelength]; byte[] tmp=new byte[2]; tmp=BitConverter.GetBytes(SomeShort); buffer[0]=tmp[0]; buffer[1]=tmp[1]; tmp=BitConverter.GetBytes(SomeOtherShort); buffer[2]=tmp[0]; buffer[3]=tmp[1]; } I feel like this is so wrong yet I can't find any better way of doing it. Is there an easier way?

    Read the article

  • Passing an ActionScript JPG Byte Array to Javscript (and eventually to PHP)

    - by Gus
    Our web application has a feature which uses Flash (AS3) to take photos using the user's web cam, then passes the resulting byte array to PHP where it is reconstructed and saved on the server. However, we need to be able to take this web application offline, and we have chosen Gears to do so. The user takes the app offline, performs his tasks, then when he's reconnected to the server, we "sync" the data back with our central database. We don't have PHP to interact with Flash anymore, but we still need to allow users to take and save photos. We don't know how to save a JPG that Flash creates in a local database. Our hope was that we could save the byte array, a serialized string, or somehow actually persist the object itself, then pass it back to either PHP or Flash (and then PHP) to recreate the JPG. We have tried: - passing the byte array to Javascript instead of PHP, but javascript doesn't seem to be able to do anything with it (the object seems to be stripped of its methods) - stringifying the byte array in Flash, and then passing it to Javascript, but we always get the same string: ÿØÿà Now we are thinking of serializing the string in Flash, passing it to Javascript, then on the return route, passing that string back to Flash which will then pass it to PHP to be reconstructed as a JPG. (whew). Since no one on our team has extensive Flash background, we're a bit lost. Is serialization the way to go? Is there a more realistic way to do this? Does anyone have any experience with this sort of thing? Perhaps we can build a javascript class that is the same as the byte array class in AS?

    Read the article

  • Array Searching code challenge

    - by RCIX
    Here's my (code golf) challenge: Take two arrays of bytes and determine if the second array is a substring of the first. If it is, output the index at which the contents of the second array appear in the first. If you do not find the second array in the first, then output -1. Example Input: { 63, 101, 245, 215, 0 } { 245, 215 } Expected Output: 2 Example Input 2: { 24, 55, 74, 3, 1 } { 24, 56, 74 } Expected Output 2: -1 Edit: Someone has pointed out that the bool is redundant, so all your function has to do is return an int representing the index of the value or -1 if not found.

    Read the article

  • Is there a simpler way to convert a byte array to a 2-byte-size hexadecimal string?

    - by Tom Brito
    Is there a simpler way of implement this? Or a implemented method in JDK or other lib? /** * Convert a byte array to 2-byte-size hexadecimal String. */ public static String to2DigitsHex(byte[] bytes) { String hexData = ""; for (int i = 0; i < bytes.length; i++) { int intV = bytes[i] & 0xFF; // positive int String hexV = Integer.toHexString(intV); if (hexV.length() < 2) { hexV = "0" + hexV; } hexData += hexV; } return hexData; } public static void main(String[] args) { System.out.println(to2DigitsHex(new byte[] {8, 10, 12})); } the output is: "08 0A 0C" (without the spaces)

    Read the article

  • Filling a byte array in Java

    - by Corleone
    Hey all! For part of a project I'm working on I am implementing a RTPpacket where I have to fill the header array of byte with RTP header fields. //size of the RTP header: static int HEADER_SIZE = 12; // bytes //Fields that compose the RTP header public int Version; // 2 bits public int Padding; // 1 bit public int Extension; // 1 bit public int CC; // 4 bits public int Marker; // 1 bit public int PayloadType; // 7 bits public int SequenceNumber; // 16 bits public int TimeStamp; // 32 bits public int Ssrc; // 32 bits //Bitstream of the RTP header public byte[] header = new byte[ HEADER_SIZE ]; This was my approach: /* * bits 0-1: Version * bit 2: Padding * bit 3: Extension * bits 4-7: CC */ header[0] = new Integer( (Version << 6)|(Padding << 5)|(Extension << 6)|CC ).byteValue(); /* * bit 0: Marker * bits 1-7: PayloadType */ header[1] = new Integer( (Marker << 7)|PayloadType ).byteValue(); /* SequenceNumber takes 2 bytes = 16 bits */ header[2] = new Integer( SequenceNumber >> 8 ).byteValue(); header[3] = new Integer( SequenceNumber ).byteValue(); /* TimeStamp takes 4 bytes = 32 bits */ for ( int i = 0; i < 4; i++ ) header[7-i] = new Integer( TimeStamp >> (8*i) ).byteValue(); /* Ssrc takes 4 bytes = 32 bits */ for ( int i = 0; i < 4; i++ ) header[11-i] = new Integer( Ssrc >> (8*i) ).byteValue(); Any other, maybe 'better' ways to do this?

    Read the article

  • Time Stamp and byte array

    - by JB_SO
    Hi, I'm trying to insert a timestamp (hour:min:sec) into a two-byte array and i'm a little confused on how to accomplish this...any help is greatly appreciated! int Hour = CTime::GetCurrentTime().GetHour(); int Minute = CTime::GetCurrentTime().GetMinute(); int Second = CTime::GetCurrentTime().GetSecond(); BYTE arry[2]; //Need to insert 'Hour', 'Minute', & 'Second' into 'arry' Thanks!

    Read the article

  • Java Conversion of byte[] into a srting and then back to a byte[]

    - by Sid
    I am working on a proxy server. I am getting data in byte[] which i convert into a string to perform certain operations. Now when i convert this new string back into a byte [] it causes unkonw problems. So mainly its like i need to know how to correctly convert a byte[] into a string and then back into a byte[] again. I tried to just convert the byte[] to string and then back to byte[] again (to make sure thats its not my operations that are causing problems). So its like: // where reply is a byte[] String str= new String(reply,0, bytesRead); streamToClient.write(str.getBytes(), 0, bytesRead); is not equivalent to streamToClient.write(reply, 0, bytesRead); my proxy works fine when i just send the byte[] without any conversion but when i convert it from byte[] to a string and then back to a byte[] its causes problems. can some one please help? =]

    Read the article

  • How can I access a byte array as shorts in Java

    - by shellback3
    I have a an array of byte, size n, that really represents an array of short of size n/2. Before I write the array to a disk file I need to adjust the values by adding bias values stored in another array of short. In C++ I would just assign the address of the byte array to a pointer for a short array with a cast to short and use pointer arithmetic or use a union. How may this be done in Java - I'm very new to Java BTW.

    Read the article

  • Convert Byte [] to PDF

    - by Sri Kumar
    Hello All, With help of this question C# 4.0: Convert pdf to byte[] and vice versa i was able to convert byte[] to PDF. But the problem here is not all the contents were written in PDF. Byte array length is 25990 approx. Only 21 to 26 KB size PDF file was created. When i try to open the PDF it says file is corrupted. What could be the reason? I tried the BinaryWriter but it creates PDF of 0 KB.

    Read the article

  • How should I handle searching through byte arrays in Java?

    - by Zombies
    Preliminary: I am writting my own httpclient in Java. I am trying to parse out the contents of chunked encoding. Here is my dilema: Since I am trying to parse out chunked http transfer encoding with a gzip payload there is a mix of ascii and binary. I can't just take the http resp content and convert it to a string and make use of StringUtils since the binary data can easily contain nil characters. So what I need to do is some basic things for parsing out each chunk and its chunk length (as per chunked transfer/HTTP/1.1 spec). Are there any helpful ways of searching through byte arrays of binary/part ascii data for certain patterns (like a CR LF) (instead of just a single byte) ? Or must I write the for loops for this?

    Read the article

  • how to send an array of bytes over a TCP connection (java programming)

    - by Mark Roberts
    Can somebody demonstrate how to send an array of bytes over a TCP connection from a sender program to a receiver program in Java. (I'm new to Java programming, and can't seem to find an example of how to do this that shows both ends of the connection (sender and receiver.) If you know of an existing example, maybe you could post the link. (No need to reinvent the wheel.) P.S. This is NOT homework! :-)

    Read the article

  • how to work with javascript typed arrays without using for

    - by ramesh babu
    var sendBuffer = new ArrayBuffer(4096); var dv = new DataView(sendBuffer); dv.setInt32(0, 1234); var service = svcName; for (var i = 0; i < service.length; i++) { dv.setUint8(i + 4, service.charCodeAt(i)); } ws.send(sendBuffer); how to workout this wihout using for loop. for loop decreasing performance while works with huge amount of data.

    Read the article

  • Adobe Air: Read and Write MP3 or JPG from local directory and switch bytes

    - by Max
    I would like to make my local jpg and mp3 files kind of unreadable (without encoding) by just putting the first 100 bytes from the beginning of the file to the end and then saving the file with a .dat extension. I know I have to use the byte array but can't get it work. I would also need then a small function to read that file and put the 100bytes back to the front so that I can play/display the file. It would be great if you could post the whole function because I am quite new to Air so that I fully understand. Thank You!!!!

    Read the article

  • System.Drawing.Image as source for asp.net image container

    - by trnTash
    I created image from byte array System.Drawing.Image newImage; using (MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length)) { ms.Write(imageBytes, 0, imageBytes.Length); newImage = System.Drawing.Image.FromStream(ms, true); } and now I need to have this image as a source for asp:Image (System.Web.UI.WebControls.Image). Is this possible as I know that conversion is impossible?

    Read the article

  • How to read some bytes from BYTE*

    - by chekalin-v
    I have BYTE pointer. For example the length of this BYTE array is 10. How can I read 4 bytes from 3 position BYTE array? Now I doing it so BYTE *source = "1234567890\0"; BYTE* tmp = new BYTE[4+1](); for(int i=0; i<4; i++) { tmp[i] = source[i+3]; }

    Read the article

  • Blob byte array in XML to Image

    - by Rayvr
    Hi, I am getting a XML File to generate a preview, in a format like this: <PARAM> <LABEL>Preview 16x16</LABEL> <ID>{03F5C6D3-ABCD-4889-B3AA-C3524C62FA1C}</ID> <LAYER>-1</LAYER> <VALUE> <BLOB> /9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8S EhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2wBDAQUFBQcGBw4ICA4eFBEU Hh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAAR CAAOABADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAA AgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkK FhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWG h4iJipKTlJWWl5iZmqKjpKWmp6ipqrKztLW2t7i5usLDxMXGx8jJytLT1NXW19jZ2uHi4+Tl 5ufo6erx8vP09fb3+Pn6/8QAHwEAAwEBAQEBAQEBAQAAAAAAAAECAwQFBgcICQoL/8QAtREA AgECBAQDBAcFBAQAAQJ3AAECAxEEBSExBhJBUQdhcRMiMoEIFEKRobHBCSMzUvAVYnLRChYk NOEl8RcYGRomJygpKjU2Nzg5OkNERUZHSElKU1RVVldYWVpjZGVmZ2hpanN0dXZ3eHl6goOE hYaHiImKkpOUlZaXmJmaoqOkpaanqKmqsrO0tba3uLm6wsPExcbHyMnK0tPU1dbX2Nna4uPk 5ebn6Onq8vP09fb3+Pn6/9oADAMBAAIRAxEAPwDP+IXxH+Ilr4/1DRrLxZqUrjUTbMLKdtsz eZgLCgHyDHy4GSeee9dT4Z8G/FjxHrmla3Y3bRlRtl1iW9ztGTnlXLS47YG0nrXQa78Bda07 U7jXNM1nS9yGVhJLHJvk8wkEkchWAYjcuDzxggGuB8K6v49i8X28Wg+IodMkaUQFI4sQSEt1 eM5B42qOPlVVVcAV5M8NKdSMW/cV3vrfXyb/AB/I+4+sVUnPCUVeyV3Z3010923krdPU/9k= </BLOB> </VALUE> </PARAM> I need to convert the <BLOB> section into an Image. I access the Element Value like this: string clean = valueC.ElementAt(0).Value.Replace("\t", string.Empty).Replace("\n", string.Empty); I've tried to read it into a MemoryStream and convert to Image: MemoryStream ms = new MemoryStream(blob, 0, blob.Length); ms.Write(blob, 0, blob.Length); Image i = Image.FromStream(ms); In this way I get "Parameter not valid exception" at getting the Image. I've also tried to save it directly into a File: using (FileStream fs = new FileStream(label + ".jpg", FileMode.Create)) { fs.Write(blob, 0, blob.Length); } But when I try to open the generated file, displays a message about damage in it. I know that encoding is important, I've already tried ASCII, UTF-8, UTF-7 and this: BinaryFormatter bf = new BinaryFormatter(); MemoryStream ms = new MemoryStream(); bf.Serialize(ms, clean); ms.Seek(0, 0); byte[] blob = ms.ToArray(); I dont know what else to do. I'll appreciate if somebody can help me. Thanks

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9  | Next Page >