title: How to recognise the arraybuffer is string or image?
body: <p>We are using websocket to transfer the data in bytearray. On the receiving end, the javascript has to determine whether the ArrayBuffer received is of type String or Image. If it is String then convert to String otherwise convert to Blob. Something as below, except i don't know how to recognize the arraybuffer is string or image. </p>
  
  <pre><code>if (message instanceof ArrayBuffer) {
           if(message of type string)
           var bytearray = new Uint8Array(message);
           to convert to string
          var out = String.fromCharCode.apply(null, bytearray);
          console.log(out);
       }
         if(message of type image){
          imageId.height = 400;
          imageId.width = 600;
          imageId.src = convertArrayBufferBlobUrl(message);
        }
  </code></pre>
  
  <p><strong>Update:</strong></p>
  
  <p>From the server i will send the image as folloing java code. How can i append or prepend flag in the byte array to identify as image or string by the client browser(javascript)?</p>
  
  <p>ImageIO.write(getSubImage(bufferedImage,width,height), "png", baos );
  byte[] result=baos.toByteArray();</p>