Apply a ASCII Hex encoding to the stream : Base64 Stream « File Input Output « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » File Input Output » Base64 StreamScreenshots 
Apply a ASCII Hex encoding to the stream
    
/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 
 *      http://www.apache.org/licenses/LICENSE-2.0
 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/* $Id: ASCIIHexOutputStream.java 426584 2006-07-28 16:01:47Z jeremias $ */


import java.io.OutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;

/**
 * This class applies a ASCII Hex encoding to the stream.
 *
 @version $Id: ASCIIHexOutputStream.java 426584 2006-07-28 16:01:47Z jeremias $
 */
public class ASCIIHexOutputStream extends FilterOutputStream
        {

    private static final int EOL   = 0x0A//"\n"
    private static final int EOD   = 0x3E//">"
    private static final int ZERO  = 0x30//"0"
    private static final int NINE  = 0x39//"9"
    private static final int A     = 0x41//"A"
    private static final int ADIFF = A - NINE - 1;

    private int posinline = 0;


    /** @see java.io.FilterOutputStream **/
    public ASCIIHexOutputStream(OutputStream out) {
        super(out);
    }


    /** @see java.io.FilterOutputStream **/
    public void write(int bthrows IOException {
        b &= 0xFF;

        int digit1 = ((b & 0xF0>> 4+ ZERO;
        if (digit1 > NINE) {
            digit1 += ADIFF;
        }
        out.write(digit1);

        int digit2 = (b & 0x0F+ ZERO;
        if (digit2 > NINE) {
            digit2 += ADIFF;
        }
        out.write(digit2);

        posinline++;
        checkLineWrap();
    }


    private void checkLineWrap() throws IOException {
        //Maximum line length is 80 characters
        if (posinline >= 40) {
            out.write(EOL);
            posinline = 0;
        }
    }


    /** @see Finalizable **/
    public void finalizeStream() throws IOException {
        checkLineWrap();
        //Write closing character ">"
        super.write(EOD);

        flush();
   
    }


    /** @see java.io.FilterOutputStream **/
    public void close() throws IOException {
        finalizeStream();
        super.close();
    }


}

   
    
    
    
  
Related examples in the same category
1. BASE64 Decoder Stream
2. BASE64 Encoder Stream from Sun Microsystems
3. Base64 Character decoder as specified in RFC1113.
4. Base64 Character encoder as specified in RFC1113.
5. Performs Base-64 decoding on an underlying stream.
6. Class encodes the bytes written to the OutPutStream to a Base64 encoded string.
7. BASE64 Decoder Stream from Sun Microsystems
8. BASE64 Encoder Stream
9. Decode a BASE64 encoded input stream to some output stream
10. Hex dump
11. Dumps data in hexadecimal format
12. Base64 Codec
13. Base64 encoding from DbUnit.org
14. Base64 provides Base64 encoding/decoding of strings and streams
15. Base64 - encode/decode data using the Base64 encoding scheme
16. Base64 from Eric Glass jcifs at samba dot org
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.