I extract the contents from the body part (BodyPart) as follows: bodyPart.getDataHandler().getDataSource().getInputStream() , I need to extract this way. I get an InputStream, I need to overtake it into a string without decoding (i.e. to remain "as is").

Sometimes there is 8-bit/7-bit encoding, sometimes base64 .

I tried all the methods from this article habr , but they modified the inputStream . Please tell me the solution.

Extract from original letter:

 -Type: image/png; name=logo inline image Content-Disposition: inline; filename=logo inline image Content-Transfer-Encoding: base64 Content-ID: <logo> X-Attachment-Id: 7c408fe710f19880_0.1 iVBORw0KGgoAAAANSUhEUgAAAKMAAABdCAYAAADJ9NbpAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJ bWFnZVJlYWR5ccllPAAADwZJREFUeNrsnXt0FNUdx+/s5iWKGEsS5VHyEiFFCiYUscDRnlAPaq0S EiwIra9EIVRATxM8p9b2D5voUbDHF0FtrRICSXiILyQqPmqFGkSq8jDZBM07p4YISBKyM/3e2Vmy DHd3Z3ZmdrOb+zvnl3nszN3ZuZ/5vebORJAkiXDhMhjExk8BFw4jFy4qifJcEAQhoEYSth6lUMd1 3jLuh6F4EnmoM7gsI+2NvQlbGq7kp5RLSGGERaQw/gv6YWK141f8tHIJdcxYDh0G3ZZYVb+cn1ou ekXwjHcCjRnPxI2S2IgGxxLapiQ9BV3RkXeZk8eMXIJqGeGqRUw2eqwqhG5P3HTkAn6auQTbTVPZ 

Excerpt after translating to string:

  PNG IHDR ]    tEXtSoftwareAdobe ImageReadyq e<IDATx   {t     % K Q !E &    Pj ,  D!T@O<     Q  Am Ix /$*>j D  0  ;  H 3   Y wwgvfv   ;  y          D $ p 2  O#.*  \! F  P u 2   xy 3 ,#    [    KHa E 0  ab  W  ru X  XU   Z.zE  w          $=]  w    \ j  EL6z * nO t ~   MS  Z    I G S % 0v K9    Sh     T~   2  # Q   ^ O9M L  o E4 -B  a  i0   c qTIbd E   e<m       Al  $      ;x 0 g  
  • Could you give a real example of the text of the letter and the result? - Senior Pomidor
  • @SeniorAutomator edited the question again. First put the wrong example. - GermanSevostyanov
  • one
    and you tried to count in byte [] and then convert to String? - Senior Pomidor
  • @SeniorAutomator just tried. new String (ByteStreams.toByteArray (inputStream)); same thing - GermanSevostyanov
  • Obviously, this is not the correct encoding. - Artem Konovalov

0