Package totalcross.io

Class Base64decoderStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class Base64decoderStream
    extends java.io.InputStream
    Receive a stream of base64 encoded bytes and decode to the original.

    Given a base 64 encoded image (img64), one may use:

     Image createImage(String img64) {
                    ByteArrayStream bas = new ByteArrayStream(img64.getBytes()); // get a Stream to read the String
                    InputStream stringInput = bas.asInputStream(); // use ByteArrayStream as a java.io.InputStream compliant object
        
                    Base64decoderStream decoder = new Base64decoderStream(stringInput); // now we can read the original bytes
                    Stream imgSource = Stream.asStream(decoder); // use Base64decoderStream as a totalcross.io.Stream compliant object
                    return new Image(imgSource); // passing the stream directly to the image for the sake of memory
     }
     
    • Constructor Summary

      Constructors 
      Constructor Description
      Base64decoderStream​(java.io.InputStream base64encodedStream)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      int read()  
      int read​(byte[] b, int off, int len)  
      long skip​(long n)
      Unable to skip.
      • Methods inherited from class java.io.InputStream

        available, mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Base64decoderStream

        public Base64decoderStream​(java.io.InputStream base64encodedStream)
    • Method Detail

      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • skip

        public long skip​(long n)
                  throws java.io.IOException
        Unable to skip. Will throw IOException
        Overrides:
        skip in class java.io.InputStream
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException