info.guardianproject.iocipher.FileOutputStream Java Examples

The following examples show how to use info.guardianproject.iocipher.FileOutputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StillCameraActivity.java    From CameraV with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected File doInBackground(byte[]... data) {

	try {

		long mTime = System.currentTimeMillis();
		File fileSecurePicture = new File(mFileBasePath, "camerav_image_" + mTime + ".jpg");
		mResultList.add(fileSecurePicture.getAbsolutePath());

		FileOutputStream out = new FileOutputStream(fileSecurePicture);
		out.write(data[0]);
		out.flush();
		out.close();

		return fileSecurePicture;

	} catch (IOException ioe) {
		Log.e(StillCameraActivity.class.getName(), "error saving picture", ioe);
	}

	return null;
}
 
Example #2
Source File: SecureMediaStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Resize an image to an efficient size for sending via OTRDATA, then copy
 * that resized version into vfs. All imported content is stored under
 * /SESSION_NAME/ The original full path is retained to facilitate browsing
 * The session content can be deleted when the session is over
 *
 * @param sessionId
 * @return vfs uri
 * @throws IOException
 */
public static Uri resizeAndImportImage(Context context, String sessionId, Uri uri, String mimeType)
        throws IOException {

    String originalImagePath = uri.getPath();
    String targetPath = "/" + sessionId + "/upload/" + UUID.randomUUID().toString() + "/image";
    boolean savePNG = false;

    if (originalImagePath.endsWith(".png") || (mimeType != null && mimeType.contains("png"))
            || originalImagePath.endsWith(".gif") || (mimeType != null && mimeType.contains("gif"))
            ) {
        savePNG = true;
        targetPath += ".png";
    }
    else
    {
        targetPath += ".jpg";


    }

    //load lower-res bitmap
    Bitmap bmp = getThumbnailFile(context, uri, DEFAULT_IMAGE_WIDTH);

    File file = new File(targetPath);
    file.getParentFile().mkdirs();
    FileOutputStream out = new info.guardianproject.iocipher.FileOutputStream(file);
    
    if (savePNG)
        bmp.compress(Bitmap.CompressFormat.PNG, 100, out);
    else
        bmp.compress(Bitmap.CompressFormat.JPEG, 90, out);

    out.flush();
    out.close();        
    bmp.recycle();        

    return vfsUri(targetPath);
}
 
Example #3
Source File: GalleryActivity.java    From CameraV with GNU General Public License v3.0 5 votes vote down vote up
@Override
    protected java.io.File doInBackground(File... params) {

        try {
String fileName = "/sdcard/" + new Date().getTime() + ".pgp.asc";
            java.io.File fileTimeCap = new java.io.File(fileName);
            java.io.FileOutputStream osTimeCap = new java.io.FileOutputStream(fileTimeCap);

            boolean asciiArmor = true;
            boolean integrityCheck = true;

            PgpHelper pgpHelper = PgpHelper.getInstance();

            PGPPublicKey encKey = pgpHelper.readPublicKey(new java.io.FileInputStream(new java.io.File("/sdcard/jack.asc")));

            pgpHelper.encryptStream(osTimeCap, new FileInputStream(params[0]), params[0].getName(), params[0].length(), new Date(), encKey, asciiArmor, integrityCheck);

            params[0].delete();

return fileTimeCap;
        }
        catch (Exception ioe)
        {
            Log.e("PGPExport","unable to export",ioe);
            Toast.makeText(activity,"Unable to export to PGP: " + ioe.getMessage(),Toast.LENGTH_LONG).show();
        }

        return null;
    }
 
Example #4
Source File: GalleryActivity.java    From CameraV with GNU General Public License v3.0 5 votes vote down vote up
private void handleSendUri(Uri dataUri) {
	try {
		ContentResolver cr = getContentResolver();
		InputStream in = cr.openInputStream(dataUri);
		Log.i(TAG, "incoming URI: " + dataUri.toString());
		String fileName = dataUri.getLastPathSegment();
		File f = new File("/" + fileName);
		BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(f));
		readBytesAndClose(in, out);
		Log.v(TAG, f.getAbsolutePath() + " size: " + String.valueOf(f.length()));
	} catch (Exception e) {
		Log.e(TAG, e.getMessage(), e);
	}
}
 
Example #5
Source File: VideoCameraActivity.java    From CameraV with GNU General Public License v3.0 5 votes vote down vote up
private void initAudio(final String audioPath) throws Exception {

			fileAudio  = new File(audioPath); 
			
			   outputStreamAudio = new BufferedOutputStream(new info.guardianproject.iocipher.FileOutputStream(fileAudio),8192*8);
				
			   if (useAAC)
			   {
				   aac = new AACHelper();
				   aac.setEncoder(MediaConstants.sAudioSampleRate, MediaConstants.sAudioChannels, MediaConstants.sAudioBitRate);
			   }
			   else
			   {
			   
				   int minBufferSize = AudioRecord.getMinBufferSize(MediaConstants.sAudioSampleRate, 
					MediaConstants.sChannelConfigIn, 
				     AudioFormat.ENCODING_PCM_16BIT)*8;
				   
				   audioData = new byte[minBufferSize];
	
				   int audioSource = MediaRecorder.AudioSource.CAMCORDER;
				   
				   if (this.getCameraDirection() == CameraInfo.CAMERA_FACING_FRONT)
				   {
					   audioSource = MediaRecorder.AudioSource.MIC;
					   
				   }
				   
				   audioRecord = new AudioRecord(audioSource,
						   MediaConstants.sAudioSampleRate,
						   MediaConstants.sChannelConfigIn,
				     AudioFormat.ENCODING_PCM_16BIT,
				     minBufferSize);
			   }
	 }
 
Example #6
Source File: VideoCameraActivity.java    From CameraV with GNU General Public License v3.0 5 votes vote down vote up
public Encoder (File fileOut, int baseFramesPerSecond, boolean withEmbeddedAudio) throws IOException
{
	this.fileOut = fileOut;

	fos = new info.guardianproject.iocipher.FileOutputStream(fileOut);
	SeekableByteChannel sbc = new IOCipherFileChannelWrapper(fos.getChannel());

	org.jcodec.common.AudioFormat af = null;
	
	if (withEmbeddedAudio)
		af = new org.jcodec.common.AudioFormat(org.jcodec.common.AudioFormat.MONO_S16_LE(MediaConstants.sAudioSampleRate));
	
	muxer = new ImageToMJPEGMOVMuxer(sbc,af,baseFramesPerSecond);			
}
 
Example #7
Source File: SecureMediaStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
public static void copyToExternal(String sourcePath, java.io.File targetPath) throws IOException {
    // copy
    FileInputStream fis = new FileInputStream(new File(sourcePath));
    java.io.FileOutputStream fos = new java.io.FileOutputStream(targetPath, false);

    IOUtils.copyLarge(fis, fos);

    fos.close();
    fis.close();
}
 
Example #8
Source File: SecureMediaStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
public static void copyToVfs(InputStream sourceIS, String targetPath) throws IOException {
    // create the target directories tree
    mkdirs( targetPath );
    // copy
    FileOutputStream fos = new FileOutputStream(new File(targetPath), false);

    IOUtils.copyLarge(sourceIS, fos);

    fos.close();
    sourceIS.close();
}
 
Example #9
Source File: SecureMediaStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
public static void copyToVfs(java.io.File sourceFile, String targetPath) throws IOException {
    // create the target directories tree
    mkdirs( targetPath );
    // copy
    java.io.InputStream fis = null;
    fis  = new java.io.FileInputStream(sourceFile);

    FileOutputStream fos = new FileOutputStream(new File(targetPath), false);

    IOUtils.copyLarge(fis, fos);

    fos.close();
    fis.close();
}
 
Example #10
Source File: ProofMode.java    From zom-android-matrix with Apache License 2.0 5 votes vote down vote up
private static void writeProof (Context context, String mediaPath, String hash, boolean showDeviceIds, boolean showLocation, boolean showMobileNetwork, String safetyCheckResult, boolean isBasicIntegrity, boolean isCtsMatch, long notarizeTimestamp, String notes)
{

    File fileMedia = new File(mediaPath);

    File fileMediaSig = new File(mediaPath + OPENPGP_FILE_TAG);
    File fileMediaProof = new File(mediaPath + PROOF_FILE_TAG);
    File fileMediaProofSig = new File(mediaPath + PROOF_FILE_TAG + OPENPGP_FILE_TAG);

    try {

        //sign the media file
        if (!fileMediaSig.exists())
            PgpUtils.getInstance(context).createDetachedSignature(new FileInputStream(fileMedia), new FileOutputStream(fileMediaSig), PgpUtils.DEFAULT_PASSWORD);

        //add data to proof csv and sign again
        boolean writeHeaders = !fileMediaProof.exists();
        writeTextToFile(context, fileMediaProof, buildProof(context, mediaPath, writeHeaders, showDeviceIds, showLocation, showMobileNetwork, safetyCheckResult, isBasicIntegrity, isCtsMatch, notarizeTimestamp, notes));

        if (fileMediaProof.exists()) {
            //sign the proof file again
            PgpUtils.getInstance(context).createDetachedSignature(new FileInputStream(fileMediaProof), new FileOutputStream(fileMediaProofSig), PgpUtils.DEFAULT_PASSWORD);
        }

    } catch (Exception e) {
        Log.e("MediaWatcher", "Error signing media or proof", e);
    }

}
 
Example #11
Source File: SecureCameraActivity.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onPictureTaken(final byte[] data, Camera camera) {
    try {
        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(filename)));
        out.write(data);
        out.flush();
        out.close();

        if (thumbnail != null) {
            Bitmap thumbnailBitmap = getThumbnail(getContentResolver(), filename);
            FileOutputStream fos = new FileOutputStream(thumbnail);
            thumbnailBitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
        }

        Intent intent = new Intent();
        intent.putExtra(FILENAME, filename);
        intent.putExtra(THUMBNAIL, thumbnail);
        intent.putExtra(MIMETYPE, "image/*");

        setResult(Activity.RESULT_OK, intent);

        finish();
    } catch (Exception e) {
        e.printStackTrace();
        setResult(Activity.RESULT_CANCELED);
        finish();
    }
    finish();
}
 
Example #12
Source File: ProofMode.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
private static void writeTextToFile (Context context, File fileOut, String text)
{
    try {
        PrintStream ps = new PrintStream(new FileOutputStream(fileOut,true));
        ps.println(text);
        ps.flush();
        ps.close();
    }
    catch (IOException ioe)
    {
        ioe.printStackTrace();
    }

}
 
Example #13
Source File: ProofMode.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
private static void writeProof (Context context, String mediaPath, String hash, boolean showDeviceIds, boolean showLocation, boolean showMobileNetwork, String safetyCheckResult, boolean isBasicIntegrity, boolean isCtsMatch, long notarizeTimestamp, String notes)
{

    File fileMedia = new File(mediaPath);

    File fileMediaSig = new File(mediaPath + OPENPGP_FILE_TAG);
    File fileMediaProof = new File(mediaPath + PROOF_FILE_TAG);
    File fileMediaProofSig = new File(mediaPath + PROOF_FILE_TAG + OPENPGP_FILE_TAG);

    try {

        //sign the media file
        if (!fileMediaSig.exists())
            PgpUtils.getInstance(context).createDetachedSignature(new FileInputStream(fileMedia), new FileOutputStream(fileMediaSig), PgpUtils.DEFAULT_PASSWORD);

        //add data to proof csv and sign again
        boolean writeHeaders = !fileMediaProof.exists();
        writeTextToFile(context, fileMediaProof, buildProof(context, mediaPath, writeHeaders, showDeviceIds, showLocation, showMobileNetwork, safetyCheckResult, isBasicIntegrity, isCtsMatch, notarizeTimestamp, notes));

        if (fileMediaProof.exists()) {
            //sign the proof file again
            PgpUtils.getInstance(context).createDetachedSignature(new FileInputStream(fileMediaProof), new FileOutputStream(fileMediaProofSig), PgpUtils.DEFAULT_PASSWORD);
        }

    } catch (Exception e) {
        Log.e("MediaWatcher", "Error signing media or proof", e);
    }

}
 
Example #14
Source File: SecureCameraActivity.java    From zom-android-matrix with Apache License 2.0 5 votes vote down vote up
@Override
public void onPictureTaken(final byte[] data, Camera camera) {
    try {
        BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(filename)));
        out.write(data);
        out.flush();
        out.close();

        if (thumbnail != null) {
            Bitmap thumbnailBitmap = getThumbnail(getContentResolver(), filename);
            FileOutputStream fos = new FileOutputStream(thumbnail);
            thumbnailBitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos);
        }

        Intent intent = new Intent();
        intent.putExtra(FILENAME, filename);
        intent.putExtra(THUMBNAIL, thumbnail);
        intent.putExtra(MIMETYPE, "image/*");

        setResult(Activity.RESULT_OK, intent);

        finish();
    } catch (Exception e) {
        e.printStackTrace();
        setResult(Activity.RESULT_CANCELED);
        finish();
    }
    finish();
}
 
Example #15
Source File: ProofMode.java    From zom-android-matrix with Apache License 2.0 5 votes vote down vote up
private static void writeTextToFile (Context context, File fileOut, String text)
{
    try {
        PrintStream ps = new PrintStream(new FileOutputStream(fileOut,true));
        ps.println(text);
        ps.flush();
        ps.close();
    }
    catch (IOException ioe)
    {
        ioe.printStackTrace();
    }

}
 
Example #16
Source File: CameraActivity.java    From Zom-Android-XMPP with GNU General Public License v3.0 4 votes vote down vote up
private void storeBitmap (Bitmap bitmap)
{
    // import
    String sessionId = "self";
    String offerId = UUID.randomUUID().toString();

    try {

        final Uri vfsUri = SecureMediaStore.createContentPath(sessionId,"cam" + new Date().getTime() + ".jpg");

        OutputStream out = new FileOutputStream(new File(vfsUri.getPath()));
        bitmap = getResizedBitmap(bitmap,SecureMediaStore.DEFAULT_IMAGE_WIDTH,SecureMediaStore.DEFAULT_IMAGE_WIDTH);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100 /*ignored for JPG*/, out);

        bitmap.recycle();
        System.gc();

        String mimeType = "image/jpeg";

        //adds in an empty message, so it can exist in the gallery and be forwarded
        Imps.insertMessageInDb(
                getContentResolver(), false, new Date().getTime(), true, null, vfsUri.toString(),
                System.currentTimeMillis(), Imps.MessageType.OUTGOING_ENCRYPTED_VERIFIED,
                0, offerId, mimeType);

        if (mOneAndDone) {
            Intent data = new Intent();
            data.setData(vfsUri);
            setResult(RESULT_OK, data);
            finish();
        }

        if (Preferences.useProofMode()) {

            try {
                ProofMode.generateProof(CameraActivity.this, vfsUri);
            } catch (FileNotFoundException e) {
                Log.e(ImApp.LOG_TAG,"error generating proof for photo",e);
            }
        }


    }
    catch (IOException ioe)
    {
        Log.e(ImApp.LOG_TAG,"error importing photo",ioe);
    }
}
 
Example #17
Source File: SecureMediaStore.java    From Zom-Android-XMPP with GNU General Public License v3.0 4 votes vote down vote up
public static void copyToVfs(byte buf[], String targetPath) throws IOException {
    File file = new File(targetPath);
    FileOutputStream out = new FileOutputStream(file);
    out.write(buf);
    out.close();
}
 
Example #18
Source File: VideoCameraActivity.java    From CameraV with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onPreviewFrame(byte[] data, Camera camera) {
	
	//even when not recording, we'll compress frames in order to estimate our FPS
	
    Camera.Parameters parameters = camera.getParameters();
    mLastWidth = parameters.getPreviewSize().width;
    mLastHeight = parameters.getPreviewSize().height;
    
	if (mRotation > 0) //flip height and width
	{
		mLastWidth =parameters.getPreviewSize().height;
		mLastHeight =parameters.getPreviewSize().width;
	}
    
    mPreviewFormat = parameters.getPreviewFormat();
    
    byte[] dataResult = data;
	
	if (mPreCompressFrames)
	{
		if (mRotation > 0)
		{
			dataResult = rotateYUV420Degree90(data,mLastHeight,mLastWidth);
			
			 if (getCameraDirection() == CameraInfo.CAMERA_FACING_FRONT)
			 {						 
				 dataResult = rotateYUV420Degree90(dataResult,mLastWidth,mLastHeight);
				 dataResult = rotateYUV420Degree90(dataResult,mLastHeight,mLastWidth);						 
			 }
			
		}
		
		YuvImage yuv = new YuvImage(dataResult, mPreviewFormat, mLastWidth, mLastHeight, null);
	    ByteArrayOutputStream out = new ByteArrayOutputStream();
	    yuv.compressToJpeg(new Rect(0, 0, mLastWidth, mLastHeight), MediaConstants.sJpegQuality, out);				    
	    dataResult = out.toByteArray();
	}   
	
	if (mFramesTotal == 0 && fileOut != null)
	{
		try {
			info.guardianproject.iocipher.FileOutputStream fosThumb = new info.guardianproject.iocipher.FileOutputStream(new info.guardianproject.iocipher.File(fileOut.getAbsolutePath() + ".thumb.jpg"));
			fosThumb.write(dataResult);
			fosThumb.flush();
			fosThumb.close();
		
		} catch (Exception e) {

			Log.e("VideoCam","can't save thumb",e);
		}
	}
	
	if (mIsRecording && mFrameQ != null)
		if (data != null)
		{

			VideoFrame vf = new VideoFrame();
			vf.image = dataResult;
			vf.duration = 1;//this is frame duration, not time //System.currentTimeMillis() - lastTime;
			vf.fps = mFPS;

			mFrameQ.add(vf);

			mFramesTotal++;

		}

		
	mFpsCounter++;
       if((System.currentTimeMillis() - start) >= 1000) {
       	mFPS = mFpsCounter;
       	mFpsCounter = 0; 
           start = System.currentTimeMillis();
       }
	
}
 
Example #19
Source File: StoryEditorActivity.java    From zom-android-matrix with Apache License 2.0 4 votes vote down vote up
private void storeHTML (String html)
{
    // import
    String sessionId = "self";
    String offerId = UUID.randomUUID().toString();

    try {

        String title = mEditTitle.getText().toString();
        if (TextUtils.isEmpty(title))
            title = "story" + new Date().getTime() + ".html";
        else
            title = URLEncoder.encode(title,"UTF-8")  + ".html";

        final Uri vfsUri = SecureMediaStore.createContentPath(sessionId,title);

        OutputStream out = new FileOutputStream(new File(vfsUri.getPath()));
        String mimeType = "text/html";

        out.write(html.getBytes());
        out.flush();
        out.close();

        //adds in an empty message, so it can exist in the gallery and be forwarded
        Imps.insertMessageInDb(
                getContentResolver(), false, new Date().getTime(), true, null, vfsUri.toString(),
                System.currentTimeMillis(), Imps.MessageType.OUTGOING_ENCRYPTED,
                0, offerId, mimeType, null);


        Intent data = new Intent();
        data.setDataAndType(vfsUri,mimeType);
        setResult(RESULT_OK, data);



    }
    catch (IOException ioe)
    {
        Log.e(LOG_TAG,"error importing photo",ioe);
    }
}
 
Example #20
Source File: CameraActivity.java    From zom-android-matrix with Apache License 2.0 4 votes vote down vote up
private void storeBitmap (Bitmap bitmap)
{
    // import
    String sessionId = "self";
    String offerId = UUID.randomUUID().toString();

    try {

        final Uri vfsUri = SecureMediaStore.createContentPath(sessionId,"cam" + new Date().getTime() + ".jpg");

        OutputStream out = new FileOutputStream(new File(vfsUri.getPath()));
     //   bitmap = getResizedBitmap(bitmap,SecureMediaStore.DEFAULT_IMAGE_WIDTH,SecureMediaStore.DEFAULT_IMAGE_WIDTH);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100 /*ignored for JPG*/, out);

        bitmap.recycle();
        System.gc();

        String mimeType = "image/jpeg";

        //adds in an empty message, so it can exist in the gallery and be forwarded
        Imps.insertMessageInDb(
                getContentResolver(), false, new Date().getTime(), true, null, vfsUri.toString(),
                System.currentTimeMillis(), Imps.MessageType.OUTGOING_ENCRYPTED,
                0, offerId, mimeType, null);

        if (mOneAndDone) {
            Intent data = new Intent();
            data.setDataAndType(vfsUri,mimeType);
            setResult(RESULT_OK, data);
            finish();
        } else {
            onBitmap(vfsUri, mimeType);
        }

        if (Preferences.useProofMode()) {

            try {
                ProofMode.generateProof(CameraActivity.this, vfsUri);
            } catch (FileNotFoundException e) {
                Log.e(LOG_TAG,"error generating proof for photo",e);
            }
        }


    }
    catch (IOException ioe)
    {
        Log.e(LOG_TAG,"error importing photo",ioe);
    }
}
 
Example #21
Source File: CameraActivity.java    From zom-android-matrix with Apache License 2.0 4 votes vote down vote up
private void storeVideo (java.io.File fileVideo)
{
    // import
    String sessionId = "self";
    String offerId = UUID.randomUUID().toString();

    try {

        final Uri vfsUri = SecureMediaStore.createContentPath(sessionId,"cam" + new Date().getTime() + ".mp4");

        OutputStream out = new info.guardianproject.iocipher.FileOutputStream(new File(vfsUri.getPath()));
        InputStream in = new java.io.FileInputStream(fileVideo);
        IOUtils.copyLarge(in, out);
        in.close();
        out.close();

        if (thumbnail == null) {
            thumbnail = ThumbnailUtils.createVideoThumbnail(fileVideo.getPath(), MediaStore.Images.Thumbnails.MINI_KIND);
        }

        fileVideo.delete();
        System.gc();


        if (thumbnail != null)
            thumbnail.compress(Bitmap.CompressFormat.JPEG,
                    80,new info.guardianproject.iocipher.FileOutputStream(new File(vfsUri.getPath()+".thumb.jpg")));


        String mimeType = "video/mp4";

        //adds in an empty message, so it can exist in the gallery and be forwarded
        Imps.insertMessageInDb(
                getContentResolver(), false, new Date().getTime(), true, null, vfsUri.toString(),
                System.currentTimeMillis(), Imps.MessageType.OUTGOING_ENCRYPTED,
                0, offerId, mimeType, null);

        if (mOneAndDone) {
            Intent data = new Intent();
            data.setDataAndType(vfsUri,mimeType);
            setResult(RESULT_OK, data);
            finish();
        } else {
            onVideo(vfsUri, mimeType);
        }

        if (Preferences.useProofMode()) {

            try {
                ProofMode.generateProof(CameraActivity.this, vfsUri);
            } catch (FileNotFoundException e) {
                Log.e(LOG_TAG,"error generating proof for photo",e);
            }
        }


    }
    catch (IOException ioe)
    {
        Log.e(LOG_TAG,"error importing photo",ioe);
    }
}