微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android.util.Base64OutputStream的实例源码

项目:weex    文件Screencastdispatcher.java   
@Override
public void run() {
  if (!mIsRunning || mBitmap == null) {
    return;
  }
  int width = mBitmap.getWidth();
  int height = mBitmap.getHeight();
  mStream.reset();
  Base64OutputStream base64Stream = new Base64OutputStream(mStream,Base64.DEFAULT);
  // request format is either "jpeg" or "png"
  Bitmap.CompressFormat format = Bitmap.CompressFormat.valueOf(mRequest.format.toupperCase());
  mBitmap.compress(format,mRequest.quality,base64Stream);
  mEvent.data = mStream.toString();
  mMetadata.pageScaleFactor = 1;
  mMetadata.deviceWidth = width;
  mMetadata.deviceHeight = height;
  mEvent.Metadata = mMetadata;
  mPeer.invokeMethod("Page.screencastFrame",mEvent,null);
  mMainHandler.postDelayed(mEndAction,FRAME_DELAY);
}
项目:Amginori    文件Base64.java   
public static String encodeObject(Serializable serializable) {
    ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
    ObjectOutputStream objectOutput;
    try {
        objectOutput = new ObjectOutputStream(arrayOutputStream);
        objectOutput.writeObject(serializable);
        byte[] data = arrayOutputStream.toByteArray();
        objectOutput.close();

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Base64OutputStream b64 = new Base64OutputStream(out,android.util.Base64.DEFAULT);
        b64.write(data);
        b64.close();
        return new String(out.toByteArray());
    } catch (IOException e) {
        e.printstacktrace();
    }
    return null;
}
项目:android.java    文件FileUtils.java   
public static String getStringFile(File f) {
    InputStream inputStream = null;
    String encodedFile = "",lastVal;
    try {
        inputStream = new FileInputStream(f.getAbsolutePath());

        byte[] buffer = new byte[10240];//specify the size to allow
        int bytesRead;
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        Base64OutputStream output64 = new Base64OutputStream(output,Base64.DEFAULT);

        while ((bytesRead = inputStream.read(buffer)) != -1) {
            output64.write(buffer,bytesRead);
        }
        output64.close();
        encodedFile = output.toString();
    } catch (FileNotFoundException e1) {
        e1.printstacktrace();
    } catch (IOException e) {
        e.printstacktrace();
    }
    lastVal = encodedFile;
    return lastVal;
}
项目:stetho    文件Screencastdispatcher.java   
@Override
public void run() {
  if (!mIsRunning || mBitmap == null) {
    return;
  }
  int width = mBitmap.getWidth();
  int height = mBitmap.getHeight();
  mStream.reset();
  Base64OutputStream base64Stream = new Base64OutputStream(mStream,FRAME_DELAY);
}
项目:ID.me-WebVerify-SDK-Android    文件ObjectHelper.java   
/**
 * Converts an object to their string byte array representation.
 *
 * @param object an object
 * @return the {@code string} byte array representation of the object
 */
@Nullable
public static String toStringByteArray(Object object) {
  ObjectOutputStream objectOutput;
  ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
  try {
    objectOutput = new ObjectOutputStream(arrayOutputStream);
    objectOutput.writeObject(object);
    byte[] data = arrayOutputStream.toByteArray();
    objectOutput.close();
    arrayOutputStream.close();

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Base64OutputStream b64 = new Base64OutputStream(out,Base64.DEFAULT);
    b64.write(data);
    b64.close();
    out.close();
    return new String(out.toByteArray());
  } catch (IOException e) {
    e.printstacktrace();
  }
  return null;
}
项目:androidclient    文件PersonalKey.java   
public String toBase64() {
    ObjectOutputStream os = null;
    try {
        ByteArrayOutputStream buf = new ByteArrayOutputStream();
        Base64OutputStream enc = new Base64OutputStream(buf,Base64.NO_WRAP);
        os = new ObjectOutputStream(enc);

        PGP.serialize(mPair,os);

        os.close();
        return buf.toString();
    }
    catch (Exception e) {
        // shouldn't happen - crash
        throw new RuntimeException(e);
    }
    finally {
        try {
            if (os != null)
                os.close();
        }
        catch (IOException ignored) {
        }
    }
}
项目:Aglona-Reader-Android    文件MainActivity.java   
public static String objectToString(Serializable object) {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        new ObjectOutputStream(out).writeObject(object);
        byte[] data = out.toByteArray();
        out.close();

        out = new ByteArrayOutputStream();
        Base64OutputStream b64 = new Base64OutputStream(out,Base64.DEFAULT);
        b64.write(data);
        b64.close();
        out.close();

        return new String(out.toByteArray());
    } catch (IOException e) {
        e.printstacktrace();
    }
    return null;
}
项目:Roid-Library    文件RLFileUtil.java   
/**
 * 
 * @param file
 * @return
 */
public static String filetoBase64(String file) {
    String result= null;
    try {
        FileInputStream fis = new FileInputStream(new File(file));
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Base64OutputStream base64out = new Base64OutputStream(baos,Base64.NO_WRAP);
        byte[] buffer = new byte[1024];
        int len = 0;
        while ((len = fis.read(buffer)) >= 0) {
            base64out.write(buffer,len);
        }
        base64out.flush();
        base64out.close();
        /*
         * Why should we close Base64OutputStream before processing the data:
         * http://stackoverflow.com/questions/24798745/android-file-to-base64-using-streaming-sometimes-missed-2-bytes
         */
        result = new String(baos.toByteArray(),"UTF-8");
        baos.close();
        fis.close();
    } catch (Exception e) {
        e.printstacktrace();
    }
    return result;
}
项目:RestVolley    文件JsonStreamerEntity.java   
private void writetoFromStream(OutputStream os,StreamWrapper entry)
        throws IOException {

    // Send the Meta data.
    writeMetaData(os,entry.name,entry.contentType);

    int bytesRead;

    // Upload the file's contents in Base64.
    Base64OutputStream bos = new Base64OutputStream(os,Base64.NO_CLOSE | Base64.NO_WRAP);

    // Read from input stream until no more data's left to read.
    while ((bytesRead = entry.inputStream.read(buffer)) != -1) {
        bos.write(buffer,bytesRead);
    }

    // Close the Base64 output stream.
    if (bos != null) {
        bos.close();
    }

    // End the Meta data.
    endMetaData(os);

    // Close input stream.
    if (entry.autoClose) {
        // Safely close the input stream.
        if (entry.inputStream != null) {
            entry.inputStream.close();
        }
    }
}
项目:RestVolley    文件JsonStreamerEntity.java   
private void writetoFromFile(OutputStream os,FileWrapper wrapper)
        throws IOException {

    // Send the Meta data.
    writeMetaData(os,wrapper.file.getName(),wrapper.contentType);

    int bytesRead;

    // Open the file for reading.
    FileInputStream in = new FileInputStream(wrapper.file);

    // Upload the file's contents in Base64.
    Base64OutputStream bos = new Base64OutputStream(os,Base64.NO_CLOSE | Base64.NO_WRAP);

    // Read from file until no more data's left to read.
    while ((bytesRead = in.read(buffer)) != -1) {
        bos.write(buffer,bytesRead);
    }

    // Close the Base64 output stream.
    if (bos != null) {
        bos.close();
    }

    // End the Meta data.
    endMetaData(os);

    // Safely close the input stream.
    if (in != null) {
        in.close();
    }
}
项目:Dream-Catcher    文件ResponseBodyFileManager.java   
public OutputStream openResponseBodyFile(String requestId,boolean base64Encode)
    throws IOException {
  OutputStream out = mContext.openFileOutput(getFilename(requestId),Context.MODE_PRIVATE);
  out.write(base64Encode ? 1 : 0);
  if (base64Encode) {
    return new Base64OutputStream(out,Base64.DEFAULT);
  } else {
    return out;
  }
}
项目:weex    文件ResponseBodyFileManager.java   
public OutputStream openResponseBodyFile(String requestId,Base64.DEFAULT);
  } else {
    return out;
  }
}
项目:stetho    文件ResponseBodyFileManager.java   
public OutputStream openResponseBodyFile(String requestId,Base64.DEFAULT);
  } else {
    return out;
  }
}
项目:sa-sdk-android    文件ViewSnapshot.java   
public synchronized void writeBitmapJSON(Bitmap.CompressFormat format,int quality,OutputStream out)
        throws IOException {
    if (null == mCached || mCached.getWidth() == 0 || mCached.getHeight() == 0) {
        out.write("null".getBytes());
    } else {
        out.write('"');
        final Base64OutputStream imageOut = new Base64OutputStream(out,Base64.NO_WRAP);
        mCached.compress(Bitmap.CompressFormat.PNG,100,imageOut);
        imageOut.flush();
        out.write('"');
    }
}
项目:shr    文件NetUtil.java   
public static String getBase64Param(File f) throws Exception {
  FileInputStream in = new FileInputStream(f.getAbsoluteFile());
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  Base64OutputStream output64 = new Base64OutputStream(out,Base64.DEFAULT);
  byte[] b = new byte[8192];
  int n;
  while ((n = in.read(b)) != -1) {
    output64.write(b,n);
  }
  output64.close();
  in.close();
  return out.toString();
}
项目:Pix-Art-Messenger    文件FileBackend.java   
private Avatar getPepAvatar(Bitmap bitmap,Bitmap.CompressFormat format,int quality) {
    try {
        ByteArrayOutputStream mByteArrayOutputStream = new ByteArrayOutputStream();
        Base64OutputStream mBase64OutputStream = new Base64OutputStream(mByteArrayOutputStream,Base64.DEFAULT);
        MessageDigest digest = MessageDigest.getInstance("SHA-1");
        DigestOutputStream mDigestOutputStream = new DigestOutputStream(mBase64OutputStream,digest);
        if (!bitmap.compress(format,quality,mDigestOutputStream)) {
            return null;
        }
        mDigestOutputStream.flush();
        mDigestOutputStream.close();
        long chars = mByteArrayOutputStream.size();
        if (format != Bitmap.CompressFormat.PNG && quality >= 50 && chars >= Config.AVATAR_CHAR_LIMIT) {
            int q = quality - 2;
            Log.d(Config.LOGTAG,"avatar char length was " + chars + " reducing quality to " + q);
            return getPepAvatar(bitmap,format,q);
        }
        Log.d(Config.LOGTAG,"settled on char length " + chars + " with quality=" + quality);
        final Avatar avatar = new Avatar();
        avatar.sha1sum = CryptoHelper.bytesToHex(digest.digest());
        avatar.image = new String(mByteArrayOutputStream.toByteArray());
        if (format.equals(Bitmap.CompressFormat.WEBP)) {
            avatar.type = "image/webp";
        } else if (format.equals(Bitmap.CompressFormat.JPEG)) {
            avatar.type = "image/jpeg";
        } else if (format.equals(Bitmap.CompressFormat.PNG)) {
            avatar.type = "image/png";
        }
        avatar.width = bitmap.getWidth();
        avatar.height = bitmap.getHeight();
        return avatar;
    } catch (Exception e) {
        return null;
    }
}
项目:DPR-KITA    文件ViewSnapshot.java   
public synchronized void writeBitmapJSON(Bitmap.CompressFormat format,OutputStream out)
    throws IOException {
    if (null == mCached || mCached.getWidth() == 0 || mCached.getHeight() == 0) {
        out.write("null".getBytes());
    } else {
        out.write('"');
        final Base64OutputStream imageOut = new Base64OutputStream(out,imageOut);
        imageOut.flush();
        out.write('"');
    }
}
项目:Conversations    文件FileBackend.java   
private Avatar getPepAvatar(Bitmap bitmap,"settled on char length " + chars + " with quality=" + quality);
        final Avatar avatar = new Avatar();
        avatar.sha1sum = CryptoHelper.bytesToHex(digest.digest());
        avatar.image = new String(mByteArrayOutputStream.toByteArray());
        if (format.equals(Bitmap.CompressFormat.WEBP)) {
            avatar.type = "image/webp";
        } else if (format.equals(Bitmap.CompressFormat.JPEG)) {
            avatar.type = "image/jpeg";
        } else if (format.equals(Bitmap.CompressFormat.PNG)) {
            avatar.type = "image/png";
        }
        avatar.width = bitmap.getWidth();
        avatar.height = bitmap.getHeight();
        return avatar;
    } catch (Exception e) {
        return null;
    }
}
项目:otrta    文件GsonData.java   
public static String ObjectToGSON(Object o){
    try{
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        Base64OutputStream baSEOs = new Base64OutputStream(baos,Base64.DEFAULT);
        DeflaterOutputStream dfos = new DeflaterOutputStream(baSEOs);
        dfos.write(gSON.toJson(o).getBytes());
        dfos.flush();
        dfos.close();
        String ret = new String(baos.toByteArray());
        return ret;
    }catch (Exception ex){
        ex.printstacktrace();
    }
    return null;
}
项目:pixate-freestyle-android    文件UrlStreamOpenerTests.java   
@Override
protected void setUp() throws Exception {
    super.setUp();

    Context context = this.getContext();
    PixateFreestyle.init(context.getApplicationContext());

    // Grab the bitmap placed in the assets. We can use it to compare
    // results later.
    InputStream is = context.getAssets().open(IMAGE_ASSET);
    assetBitmap = BitmapFactory.decodeStream(is);
    is.close();

    Resources resources = context.getResources();

    int rawFileId = resources.getIdentifier(RAW_TEST_FILE,"raw",this.getContext().getPackageName());

    testFileContents = readStream(resources.openRawResource(rawFileId));

    // Create a document file.
    OutputStreamWriter writer =
            new OutputStreamWriter(getContext().openFileOutput(DOCUMENT_FILE,Context.MODE_PRIVATE));
    try {
        writer.write(testFileContents);
    } finally {
        writer.close();
    }

    // Learn the document file's file:// uri so we can test that scheme.
    documentFileUri = new File(context.getFilesDir(),DOCUMENT_FILE).toURI().toString();

    // Clean it up to make it look like someone would type it in css
    // (file:// instead of just file:/)
    if (documentFileUri.startsWith("file:/") && !documentFileUri.startsWith("file://")) {
        documentFileUri = documentFileUri.replace("file:","file://");
    }

    // Create a temp file.
    tempFile = new File(context.getCacheDir(),TMP_FILE);
    writer = new OutputStreamWriter(new FileOutputStream(tempFile));
    try {
        writer.write(testFileContents);
    } finally {
        writer.close();
    }

    // Get a base64 of the test asset image bytes so we can do a data: call
    // and compare results.
    is = context.getAssets().open(IMAGE_ASSET);
    ByteArrayOutputStream output = new ByteArrayOutputStream();
    Base64OutputStream bos = new Base64OutputStream(output,Base64.DEFAULT);

    try {
        byte[] buffer = new byte[2048];
        int count = is.read(buffer);

        while (count > 0) {
            bos.write(buffer,count);
            count = is.read(buffer);
        }

        assetBitmapBase64 = output.toString();

    } finally {
        is.close();
        bos.close();
    }

}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。