Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7730851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T06:19:55+00:00 2026-06-01T06:19:55+00:00

I have : ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); encoder.encode(question, outputStream); and when System.out.println(outputStream) prints

  • 0

I have :

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
encoder.encode(question, outputStream);

and when System.out.println(outputStream) prints this .. i see 0►☻☺♣▬♂test some and I want to see this in HEX like 30 04 12 54 33

How can I do that ?

Thanks

I was able to write the binary to a file like this :

File file = new File("out.bin");
FileOutputStream filename = new FileOutputStream(file);
outputStream.writeTo(filename);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T06:19:56+00:00Added an answer on June 1, 2026 at 6:19 am

    Although the System.out.println() method can print different things out, it is mainly for printing strings. For this purpose, it will try to convert the input into character string according to the platform or some explicitly given character encoding. To print raw bytes as hex, you need some manipulation before printing them out. The following example might be useful to you.

    import java.io.*;
    
    class PrintHex
    {
        public static void main(String[] args) 
        {
            byte[] raw = {0x30,0x04,0x12,0x54,0x33};
            byte[] raw1 = {'G','I','F'};
            ByteArrayOutputStream bo = new ByteArrayOutputStream();
            ByteArrayOutputStream bo1 = new ByteArrayOutputStream();
            bo.write(raw,0,raw.length);
            bo1.write(raw1,0,raw1.length);
    
            System.out.println(bo);
            System.out.println(bo1);
    
            System.out.println("0x" + getHex(raw));
            System.out.println("0x" + getHex(raw1));
        }
        static final String HEXES = "0123456789ABCDEF";
    
        public static String getHex( byte [] raw ) {
            if ( raw == null ) {
               return null;
            }
            final StringBuilder hex = new StringBuilder( 2 * raw.length );
            for ( final byte b : raw ) {
               hex.append(HEXES.charAt((b & 0xF0) >> 4))
             .append(HEXES.charAt((b & 0x0F)));
            }
            return hex.toString();
       }
    }
    

    The getHex method is from http://www.rgagnon.com/javadetails/java-0596.html

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is what I have so far, Socket clientSocket = new Socket(HOST, PORT); ByteArrayOutputStream
I have a ByteArrayEntity as follows: ByteArrayOutputStream bos = new ByteArrayOutputStream(); tempPic.compress(CompressFormat.PNG, 0, bos);
I have a web app and the client has requested to see some reports.
I have to send a ByteArrayOutputStream through a rest service, and I got this
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a
Have a n-tire web application and search often times out after 30 secs. How
Have you managed to get Aptana Studio debugging to work? I tried following this,
I am using java sockets for communication. On the client side I have some
I have a URLConnection, that access a web page. URL url = new URL(https://domain);
This is the code I have, it actually works, not perfectly but it does,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.