title: How to convert a Java string into a ByteString without re-escaping the string
body: <p>I'm trying to convert an already java encoded string into a ByteString, without re-encoding the string.</p>
  <p>My method looks like this:</p>
  <pre><code>import com.google.api.HttpBody;
  import com.google.protobuf.ByteString;
  
  protected HttpBody getHttpBody(String contentType, String data) {
          System.out.println(&quot;=======d==:&quot; + data);
          HttpBody.Builder bodyBuilder = HttpBody.newBuilder();
          bodyBuilder.setContentType(contentType);
          try {
              bodyBuilder.setData(ByteString.copyFrom(data.getBytes()));
          } catch (Exception e) {}
          HttpBody body =  bodyBuilder.build();
          System.out.println(&quot;=======d2==:&quot; + body);
          return body;
      }
  </code></pre>
  <p>The input &quot;data&quot; looks like this:</p>
  <pre><code>=======d==:------WebKitFormBoundaryeyaPdl6AduTufZV4\r\nContent-Disposition: form-data; name=\&quot;content\&quot;; filename=\&quot;473892_CRUST_grammars.zip\&quot;\r\nContent-Type: application/x-zip-compressed\r\n\r\nPK\003\004\024\000\000\000\b\000\342:nT\222{\260q;\001\000\000\022\002\000\000\021\000\000\000en-US/CRUST.grxmleQOO\2030\024?\217OQ\353\201\023+h4s\026\226\005\227x\232\211l1\272L\322\2617\326\004ZR\212\250\237\336\256\262\211YO\257\357\375\376\275\226N&gt;\313\002}\200\252\271\024\241\033\f}\027\201\310\344\226\213&lt;ty\362\344\215F7w^\340N\&quot;\207\346\212\225%S\310P\306\0053\000\f\302[&amp;\370\304\307\206\217\221\222R\2078~^&amp;\v|\300\212:\304{\255\2531!m\333\016\333\353\241T9\271\362\375\200\370\267\244\023\305\221\203\272CK\320\f\tVB\210\353\226+\310R!U\311\n\376\r\251\226i\245\344\206mx\3015\207\032\243L\n\r\3028\006\230D\2163\240\252)\000\361\355)B\235\311\312HU\315\246\340\231\361\031\f\250\024\340\311\335\237%2=\256\241\214,Y\301\0165\212\207\3702\333\003\324_F\227j\226G\364b\025?L\027\323\225\0256\372\217\263Y\362j/\357\261E\242X5\265\036\317\337\322\376l&gt;{A\3759\276_\257#J\254$\261\266\207L\344\030\312\224\207\024\377w\351\222\364\&quot;\233\207:[\303v\255\&quot;\372%\240\243A\037p\356D\217\337\0209?PK\001\002\024\000\024\000\000\000\b\000\342:nT\222{\260q;\001\000\000\022\002\000\000\021\000\000\000\000\000\000\000\001\000 \000\000\000\000\000\000\000en-US/CRUST.grxmlPK\005\006\000\000\000\000\001\000\001\000?\000\000\000j\001\000\000\000\000\r\n------WebKitFormBoundaryeyaPdl6AduTufZV4--\r\n
  </code></pre>
  <p>While the data after being converted to ByteString looks like this:</p>
  <pre><code>=======d2==:content_type: &quot;multipart/form-data; boundary=----WebKitFormBoundaryeyaPdl6AduTufZV4&quot;
  data: &quot;------WebKitFormBoundaryeyaPdl6AduTufZV4\\r\\nContent-Disposition: form-data; name=\\\&quot;content\\\&quot;; filename=\\\&quot;473892_CRUST_grammars.zip\\\&quot;\\r\\nContent-Type: application/x-zip-compressed\\r\\n\\r\\nPK\\003\\004\\024\\000\\000\\000\\b\\000\\342:nT\\222{\\260q;\\001\\000\\000\\022\\002\\000\\000\\021\\000\\000\\000en-US/CRUST.grxmleQOO\\2030\\024?\\217OQ\\353\\201\\023+h4s\\026\\226\\005\\227x\\232\\211l1\\272L\\322\\2617\\326\\004ZR\\212\\250\\237\\336\\256\\262\\211YO\\257\\357\\375\\376\\275\\226N&gt;\\313\\002}\\200\\252\\271\\024\\241\\033\\f}\\027\\201\\310\\344\\226\\213&lt;ty\\362\\344\\215F7w^\\340N\\\&quot;\\207\\346\\212\\225%S\\310P\\306\\0053\\000\\f\\302[&amp;\\370\\304\\307\\206\\217\\221\\222R\\2078~^&amp;\\v|\\300\\212:\\304{\\255\\2531!m\\333\\016\\333\\353\\241T9\\271\\362\\375\\200\\370\\267\\244\\023\\305\\221\\203\\272CK\\320\\f\\tVB\\210\\353\\226+\\310R!U\\311\\n\\376\\r\\251\\226i\\245\\344\\206mx\\3015\\207\\032\\243L\\n\\r\\3028\\006\\230D\\2163\\240\\252)\\000\\361\\355)B\\235\\311\\312HU\\315\\246\\340\\231\\361\\031\\f\\250\\024\\340\\311\\335\\237%2=\\256\\241\\214,Y\\301\\0165\\212\\207\\3702\\333\\003\\324_F\\227j\\226G\\364b\\025?L\\027\\323\\225\\0256\\372\\217\\263Y\\362j/\\357\\261E\\242X5\\265\\036\\317\\337\\322\\376l&gt;{A\\3759\\276_\\257#J\\254$\\261\\266\\207L\\344\\030\\312\\224\\207\\024\\377w\\351\\222\\364\\\&quot;\\233\\207:[\\303v\\255\\\&quot;\\372%\\240\\243A\\037p\\356D\\217\\337\\0209?PK\\001\\002\\024\\000\\024\\000\\000\\000\\b\\000\\342:nT\\222{\\260q;\\001\\000\\000\\022\\002\\000\\000\\021\\000\\000\\000\\000\\000\\000\\000\\001\\000 \\000\\000\\000\\000\\000\\000\\000en-US/CRUST.grxmlPK\\005\\006\\000\\000\\000\\000\\001\\000\\001\\000?\\000\\000\\000j\\001\\000\\000\\000\\000\\r\\n------WebKitFormBoundaryeyaPdl6AduTufZV4--\\r\\n&quot;
  </code></pre>
  <p>What I want is for the 2 data fields to look the same. As you can see after the conversion to ByteString, the data content gets escaped again (which I don't want).</p>
  <p>I've tried a couple of copyFrom /copyFromUtf8 approaches, providing encoding, even tried to unescape the input using StringEscapeUtils functionality, before passing it into copyFrom, but messes up the message structure.</p>
  <p>This message is a multipart form data payload which contains a zip file with a text file in it.
  I need this in order to mock a request for some integration tests.</p>
  <p>Any idea how I can achieve this ?</p>
  <p>Thanks</p>