Convert byte[] to ISO-8859-15 or utf-8

522 Views Asked by At

I need help to convert a byte array into a format which could read the € symbol. Now, the program I'm working on is reading the file like this :

new String(bytes, "ISO-8859-1")

I find ISO-8859-15 and utf-8 can make € readable. But I can't find a way to convert my array into ISO-8859-15. When I try with utf-8, my byte array isn't decode (it trigger a loop). The byte array is from another application which I can't modify or even consult the code.

Is there a way to reveal the € symbol? Is there a way to analyze the contents of the byte array, to detect if the contents is convertible?

if (truc) {

  // Initialisation d'une ressource odet API
  Resource gor = new Resource(...);
  PliPDFBean pdf = new PliPDFBean();
  byte[] flux = null;

  pdf=ImpressionNOE.recuperationFluxNOE(...);

  // Appel http
  int status = gor.webCall(pdf);

  // Recuperation du flux
  flux = gor.getResult();

  if (flux != null) {
    // longueur du byte et type de l'application
    response.setHeader("Content-Disposition", "attachment; filename=Reimpression.pdf");
    response.setContentLength(flux.length);
    response.setContentType("application/pdf");
    // ecrit les donnees dans le pdf
    
    try {
        String string_flux = new String(flux, "ISO-8859-1");
      response.getWriter().write(string_flux);  
    } catch (Exception e) {
        log.error("erreur ImpressionReedition"+ e.getMessage());
    }
    
  }

} 
0

There are 0 best solutions below