🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.language
Article #14876

Re: Hex dump in java

#14876
From: Dion Gillard
Date: Sun, 25 Jul 1999 00:00
72 lines
3036 bytes
In article <7n4d34$k011@forums.borland.com>, johnrobertcollins@erols.com 
says...
|  
|  Kory <koryf@simba.ca> wrote in message
|  news:7ljdfg$45m1@forums.borland.com...
|  > Is there a function that will do a Hex dump of a bit stream?
|  
|  I don't think there is a built-in one to do that but there are classes to do
|  that in "Java I/O" book I believe.  Check for it at www.amazon.com
For the 'undocumented' aka built-in one:
import sun.misc.*;
import java.io.*;

/** A class to test the encoders and decoders using a hard coded string
	Tested encoders and decoders are:
		- BASE64, UC, UU
	HexDumpEncoder doesn't have a corresponding decoder
*/
public class EnDecodeTest {
   public static void main(String[] args) throws IOException {

	// text to encode and decode
      String originalText = "Hi There, please encode and decode me";
	// turn the string into a byte array
      byte[] originalBytes = originalText.getBytes();

	// create all the encoders and decoders for later use
      BASE64Encoder b64E = new BASE64Encoder();
      BASE64Decoder b64D = new BASE64Decoder();
      UCEncoder ucE = new UCEncoder();
      UCDecoder ucD = new UCDecoder();
      UUEncoder uuE = new UUEncoder();
      UUDecoder uuD = new UUDecoder();
      HexDumpEncoder hxE = new HexDumpEncoder();

      System.out.println("Orignl *" + originalText + "*");
      System.out.println("===============================================
=========");

      // do base 64 stuff
      System.out.println();
      String b64Enc = b64E.encodeBuffer(originalBytes);
      System.out.println("Base64 *" + b64Enc + "*");

      String b64Dec = new String(b64D.decodeBuffer(b64Enc));
      System.out.println("Decode *" + b64Dec + "*");

      // do UC stuff
      System.out.println();
      String ucEnc = ucE.encodeBuffer(originalBytes);
      System.out.println("UCEnc  *" + ucEnc + "*");

      String ucDec = new String(ucD.decodeBuffer(ucEnc));
      System.out.println("Decode *" + ucDec + "*");

      // do UU stuff
      System.out.println();
      String uuEnc = uuE.encodeBuffer(originalBytes);
      System.out.println("UUEnc  *" + uuEnc + "*");

	// this will fail under jdk1.1.1 and higher - uncomment if you 
want to test
      //String uuDec = new String(uuD.decodeBuffer(uuEnc));
      //System.out.println("Decode *" + uuDec + "*");

      // do HexDump stuff
      System.out.println();
      String hxEnc = hxE.encodeBuffer(originalBytes);
      System.out.println("HexEnc *" + hxEnc + "*");

   }
}
Technical Details
Message-ID: <MPG.12040256e4bbcacd989685@forums.inprise.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7ljdfg$45m1@forums.borland.com> <7n4d34$k011@forums.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f74b3,25f7aa4fc98eaf7
X-Google-Attributes: gidf74b3,public
From: dion@multitask.com.au (Dion Gillard)
Subject: Re: Hex dump in java
Date: 1999/07/25
Message-ID: <MPG.12040256e4bbcacd989685@forums.inprise.com>
X-Deja-AN: 504906805
References: <7ljdfg$45m1@forums.borland.com> <7n4d34$k011@forums.borland.com>
Organization: Multitask Consulting
Newsgroups: borland.public.jbuilder.java.language