I am very new to programming. Sorry if it's a too beginner question.    I am studying protocol buffers for homework.  and I don't know how to get bytes from Message.   Here is the exapmple below from Google Protocol Buffers Documentation,   message Test1 {   required int32 a = 1; }   In an application, you create a Test1 message and set a to 150. You then serialize the message to an output stream. If you were able to examine the encoded message, you'd see three bytes:  08 96 01   I am using Eclipse and Java.  I created code below.  package com.example.tutorial;  import java.util.Scanner;  import com.example.tutorial.TestProtos.Test1; import com.example.tutorial.TestProtos.Test1OrBuilder;  public class TestByte {     public static void main(String[] args) throws Exception{          Scanner sc = new Scanner(System.in);         System.out.println("Enter a number:");           int a = sc.nextInt();         Test1.Builder t = Test1.newBuilder();         Test1 obj = t.setA(a).build();         byte[] arr = obj.toByteArray();          System.out.println("byte: "+arr);   when I enter '150', it gives me   byte: [B@45ee12a7         I want to get three bytes like the example in google documentation.  I am asking how to get the bytes from encoded message using protocol buffers.   can anyone tell me how? Thank you!!
872
In Java, arrays don't override toString(), so if you try to print one directly, you get the className + '@' + the hex of the  of the array, as defined by Object.toString():  int[] intArray = new int[] {1, 2, 3, 4, 5}; System.out.println(intArray);     // prints something like '[I@3343c8b3'   But usually, we'd actually want something more like [1, 2, 3, 4, 5]. What's the simplest way of doing that? Here are some example inputs and outputs:  // Array of primitives: int[] intArray = new int[] {1, 2, 3, 4, 5}; //output: [1, 2, 3, 4, 5]  // Array of object references: String[] strArray = new String[] {"John", "Mary", "Bob"}; //output: [John, Mary, Bob]
21914
I have 3 byte arrays in C# that I need to combine into one. What would be the most efficient method to complete this task?
6195
Using PHP, what's the fastest way to convert a string like this: "123" to an integer?  Why is that particular method the fastest? What happens if it gets unexpected input, such as "hello" or an array?
16792
Can we not implement the HTTP protocol using just a request body and a response body?   For example, the URL will contain request, which will be mapped to a function depending on programming language on server side say a Servlet and in response HTML and JavaScript response will be sent across.   Why does HTTP protocol have notion of methods?  From the answers, I get some sense of why concept of methods is there..This leads to another related question:  For example in gmail compose link, the PUT/POST request and data will be sent. How does the browser come to know which method to use? Does the gmail page sent by server include the method name to use when calling gmail compose request? when we call www.gmail.com , it must be using GET method, how does the browser know that this method to use?  PS : I don't have enough credits to comment on answers, so I am not able to comment on many questions raised by people related to intention behind this question.   As some answers tell, we can create new users on DELETE method, then this raises question the intention behind notion of methods in http protocol, because at the end of the day, it totally depends on servers what function they want to map an URL to. Why should client tell servers what methods to use for an URL.
120763
I have to serialize around a million items and I get the following exception when I run my code:  Exception in thread "main" java.lang.OutOfMemoryError: Java heap space     at java.util.Arrays.copyOfRange(Unknown Source)     at java.lang.String.&lt;init&gt;(Unknown Source)     at java.io.BufferedReader.readLine(Unknown Source)     at java.io.BufferedReader.readLine(Unknown Source)     at org.girs.TopicParser.dump(TopicParser.java:23)     at org.girs.TopicParser.main(TopicParser.java:59)   How do I handle this?
75841
My application is receiving email through SMTP server. There are one or more attachments in the email and email attachment return as byte[] (using sun javamail api).  I am trying to zip the attachment files on the fly without writing them to disk first.  What is/are possible way to achieve this outcome?
14231
What would be the best way to fill a C# struct from a byte[] array where the data was from a C/C++ struct?  The C struct would look something like this (my C is very rusty):  typedef OldStuff {     CHAR Name[8];     UInt32 User;     CHAR Location[8];     UInt32 TimeStamp;     UInt32 Sequence;     CHAR Tracking[16];     CHAR Filler[12]; }   And would fill something like this:  [StructLayout(LayoutKind.Explicit, Size = 56, Pack = 1)] public struct NewStuff {     [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]     [FieldOffset(0)]     public string Name;      [MarshalAs(UnmanagedType.U4)]     [FieldOffset(8)]     public uint User;      [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 8)]     [FieldOffset(12)]     public string Location;      [MarshalAs(UnmanagedType.U4)]     [FieldOffset(20)]     public uint TimeStamp;      [MarshalAs(UnmanagedType.U4)]     [FieldOffset(24)]     public uint Sequence;      [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]     [FieldOffset(28)]     public string Tracking; }   What is best way to copy OldStuff to NewStuff, if OldStuff was passed as byte[] array?  I'm currently doing something like the following, but it feels kind of clunky.  GCHandle handle; NewStuff MyStuff;  int BufferSize = Marshal.SizeOf(typeof(NewStuff)); byte[] buff = new byte[BufferSize];  Array.Copy(SomeByteArray, 0, buff, 0, BufferSize);  handle = GCHandle.Alloc(buff, GCHandleType.Pinned);  MyStuff = (NewStuff)Marshal.PtrToStructure(handle.AddrOfPinnedObject(), typeof(NewStuff));  handle.Free();   Is there better way to accomplish this?    Would using the BinaryReader class offer any performance gains over pinning the memory and using Marshal.PtrStructure?
4190
I am looking to use Java to get the MD5 checksum of a file.  I was really surprised but I haven't been able to find anything that shows how to get the MD5 checksum of a file.  How is it done?
111228
Am I missing something, or is RSA very very limiting when it comes to ecrypting data when it comes to the actual message size?  I have read that you can only encrypt a message of around 117 to 200 bytes in size (depending on your key size: 1024 or 2048 bits). Is this correct?  If so, I think I have read people suggesting on using it for larger files. I guess they are just repeating the process many times over and over in blocks of 117 bytes?
90586
Example C API signature:  void Func(unsigned char* bytes);  In C, when I want to pass a pointer to an array, I can do:  unsigned char* bytes = new unsigned char[1000]; Func(bytes); // call   How do I translate the above API to P/Invoke such that I can pass a pointer to C# byte array?
120264
I got this packet captured with tcpdump but I'm not sure how to use the --hex-string param to match the packet. Can someone show me how to do it?  11:18:26.614537 IP (tos 0x0, ttl 17, id 19245, offset 0, flags [DF], proto UDP (17), length 37)     x.x.187.207.1234 &gt; x.x.152.202.6543: [no cksum] UDP, length 9         0x0000:  f46d 0425 b202 000a b853 22cc 0800 4500  .m.%.....S"...E.         0x0010:  0025 4b2d 4000 1111 0442 5ebe bbcf 6701  .%K-@....B^...g.         0x0020:  98ca 697d 6989 0011 0000 ffff ffff 5630  ..i}i.........V0         0x0030:  3230 3300 0000 0000 0000 0000            203.........
73598
I have a char array buffer that I am using to store characters that the user will input one by one.  My code below works but has a few glitches that I can't figure out:   when I execute a printf to see what's in Buffer, it does fill up but I get garbage characters at the end it won't stop at 8 characters despite being declared as char Buffer[8];   Can somebody please explain to me what is going on and perhaps how I could fix this? Thanks.  char Buffer[8]; //holds the byte stream int i=0;  if (/* user input event has occurred */)  {         Buffer[i] = charInput;         i++;          // Display a response to input         printf("Buffer is %s!\n", Buffer);  }   Output:   tagBuffer is 1┬┬w! tagBuffer is 12┬w! tagBuffer is 123w! tagBuffer is 1234! tagBuffer is 12345! tagBuffer is 123456=! tagBuffer is 1234567! tagBuffer is 12345678!  tagBuffer is 123456789!
6153
I thought to create a simple test to send and receive a buffer via UART. I succeeded in sending bytes from my PC to the nucleo bord and receiving them in blocking and non-blocking mode. But for some reason I can't succeed to send data from UART3 and receive the bytes on UART2.  I have a nucleo-f103rb and have the following pins setup:   UART2: tx=PA2;rx=PA3 UART3: tx=PB10;rx=PB11   And then the following code:    while (1)   {     /* USER CODE END WHILE */     /* USER CODE BEGIN 3 */     if (HAL_UART_Transmit(&amp;huart3, send, 2, 1000) == HAL_OK)     {         if (HAL_UART_Receive(&amp;huart2, receive, 2, 1000) == HAL_OK)         {             HAL_GPIO_TogglePin(GPIOA, LD2_Pin);         }     }   }   All the boiler plate is generated using cube mx. So the UART 2 and 3 are all default, same for the button pins.    I connected the transmit pin of uart3 to the receiving pin of uart2 I connected the receive pin of uart3 to the transmitting pin of uart2 (while not used in this trivial example though)   What am I missing here?  Update  As comments and answers suggested, I shouldn't be using the blocking mode approach. So I rewrote it slightly to rely more on interrupts.  I attached a callback to the nucleo blue button  void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {     if (GPIO_Pin == B1_Pin)     {         HAL_UART_Transmit_IT(&amp;huart3, (uint8_t *)send, 2);     } }   And I added a callback for receiving stuff over uart  void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {   /* Prevent unused argument(s) compilation warning */   UNUSED(huart);    /* NOTE : This function should not be modified, when the callback is needed,             the HAL_UART_RxCpltCallback can be implemented in the user file    */       // Toggle the pin to see some proof that I received something      HAL_GPIO_TogglePin(LD2_GPIO_Port, LD2_Pin);       // Resubscribe uart2      HAL_UART_Receive_IT(&amp;huart2, (uint8_t *)receive, 2); }   In the main function I call the interrupt so that the callback is active.  while (HAL_UART_Receive_IT(&amp;huart2, receive, 2) != HAL_OK);  __NOP(); while (1) { }   Again, when debugging through I do end up in the button released callback, but the callback on the uart receive isn't triggered. When I send stuff from the PC, it does. So it seems that sending stuff via uart3 isn't working. So I guess that must be the wiring.     But I really can't see what I am missing here, the pins are clearly defined in the pinout here: .  I hope the photo is clear enough, but this is how I connected them.
12460
What is the best way to write bytes in the middle of a file using Java?
26428
I need to stream a file from Salesforce in our webapplication. To make sure the file is properly opened, I have to set Content-Type header.  How to retrieve the Content-Type (MIME) of a file?  I expect values like: image/png, application/pdf, text/html etc.  How to get these values? I am using the Java and a SOAP client to retrieve the data.
112233
To communicate with a REST interface on a private system, I need to send a JSON message from a trigger. I have a message object that has some fields, lists and a child object:  public class MerchantConfig {  public class MIDConfig {     public String mid;     public String currencyCode;     public String cardTemplateName;     public String paymentPanelRestriction;     public List&lt;String&gt; restrictedCountries;      public String paymentPanelRestrictionForCountries; }  public String merchantName; public String sopgTemplateName; public Integer dispositionTimeWindowInMinutes; public List&lt;String&gt; features; public Boolean activateImmediately; public List&lt;MIDConfig&gt; midConfiguration; }   I can serialize it to JSON using the built-in serializer:  String body = JSON.serializePretty([MerchantConfig instance]);   The result:  {   "sopgTemplateName" : null,   "midConfiguration" : [ {     "restrictionCountries" : [ "DE", "AT" ],     "paymentPanelRestrictionForCountries" : "MANDATORY",     "paymentPanelRestriction" : "OPTIONAL",     "mid" : "1000000001",     "currencyCode" : "EUR",     "cardTemplateName" : null   }, {     "restrictionCountries" : [ ],     "paymentPanelRestrictionForCountries" : "",     "paymentPanelRestriction" : "OPTIONAL",     "mid" : "1000000002",     "currencyCode" : "USD",     "cardTemplateName" : null   }, {     "restrictionCountries" : [ ],     "paymentPanelRestrictionForCountries" : "",     "paymentPanelRestriction" : "PROHIBITED",     "mid" : "1000000003",     "currencyCode" : "AUD",     "cardTemplateName" : null   } ],   "merchantName" : "Test Merchant",   "features" : [ XYZ ],   "dispositionTimeWindowInMinutes" : 10,   "activateImmediately" : true }   How can I serialize this object so that all properties that are null don't show up in the JSON string?   In this example, "sopgTemplateName" and all "cardTemplateName" properties are null and should not appear in the JSON string. The empty list "restrictionCountries" should still appear as an empty list, though.
18114
I have a method with an out parameter that tries to do a type conversion. Basically:  public void GetParameterValue(out object destination) {     object paramVal = "I want to return this. could be any type, not just string.";      destination = null; // default out param to null     destination = Convert.ChangeType(paramVal, destination.GetType()); }   The problem is that usually someone would call this like:  string output; GetParameterValue(output);   This will fail because of:  destination.GetType()   destination is null, so we can't call .GetType() on it. We also can not call:  typeof(destination)   because destination is a variable name not a type name.  So is there any way to get the type of an object that is set to null? I would think there would have to be a way to know what type a storage location is without it being assigned anything.    Just to give a bit more info, I am trying to make a utility method that will grab the output parameters of an Oracle stored procedure. The issue is that DbParameter.Value is of type object.  What would be ideal would be for the developers to do something like:  string val = GetParameterValue("parameterName");   The notable thing is that there is no casting of types. In practice, you don't know the lparam of the "equals", so I went with:  string val; GetParameterValue("parameterName", out val);   And figured within the method, I would know the destination type of the output variable. I guess that was a bad assumption. As an alternative, I also wrote the method:  public T GetParameterValue&lt;T&gt;(string paramName)   So the developers can do:  string val = GetParameterValue&lt;string&gt;("parameterName");   I find the explicit "string" declaration to be repetitive, especially since in practice, the destination if probably an object property and the oracle data type could change (think ORM):  MyObj.SomeProp = GetParameterValue&lt;MyObj.SomeProp.GetType()&gt;("parameterName");   But again, if MyObj.SomeProp is null, that .GetType() call fails. The VM has to know the type of MyObj.SomeProp, even when its null, right? or else how would it catch cast exceptions?    To partially solve my own problem, I can do:  MyObj.SomeProp = GetParameterValue&lt;typeof(MyObj).GetField("SomeProp").GetType()&gt;("parameterName");   The whole idea was to not have to explicitly use the Type in more than one place, so that if the data type changes, it only has to be changed in the destination object (MyObj.SomeProp) and in the DB. There has to be a better way...