Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import android.util.Base64;
import android.util.Log;

public class Main {
    private static final String LOGTAG = "GeckoBitmapUtils";

    public static byte[] getBytesFromDataURI(String dataURI) {
        final String base64 = dataURI.substring(dataURI.indexOf(',') + 1);
        return getBytesFromBase64(base64);
    }

    /**
     * Return a byte[] containing the bytes in a given base64 string, or null if this is not a valid
     * base64 string.
     */
    public static byte[] getBytesFromBase64(String base64) {
        try {
            return Base64.decode(base64, Base64.DEFAULT);
        } catch (Exception e) {
            Log.e(LOGTAG, "exception decoding bitmap from data URI: " + base64, e);
        }

        return null;
    }
}