Search in sources :

Example 91 with FileOutputStream

use of java.io.FileOutputStream in project playn by threerings.

the class AndroidSurfaceGL method onSurfaceLost.

@Override
public void onSurfaceLost() {
    try {
        AndroidGLContext actx = (AndroidGLContext) ctx;
        bindFramebuffer();
        ByteBuffer pixelBuffer = ByteBuffer.allocate(texWidth * texHeight * 4);
        actx.gl.glReadPixels(0, 0, texWidth, texHeight, GL20.GL_RGBA, GL20.GL_UNSIGNED_BYTE, pixelBuffer);
        actx.checkGLError("glReadPixels");
        try {
            cachedPixels = new File(cacheDir, "surface-" + Integer.toHexString(hashCode()));
            FileOutputStream out = new FileOutputStream(cachedPixels);
            out.write(pixelBuffer.array());
            out.close();
        } catch (IOException e) {
            PlayN.reportError("IOException writing cached Surface to file.", e);
            cachedPixels = null;
        }
        pixelBuffer = null;
    } catch (OutOfMemoryError e) {
        PlayN.reportError("OutOfMemoryError reading cached Surface to buffer.", e);
        cachedPixels = null;
    }
    clearTexture();
}
Also used : FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer) File(java.io.File)

Example 92 with FileOutputStream

use of java.io.FileOutputStream in project Android-ImageResizer by svenkapudija.

the class ImageWriter method writeToFile.

public static boolean writeToFile(Bitmap image, File file) {
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    image.compress(CompressFormat.JPEG, 100, bytes);
    try {
        FileOutputStream fos = new FileOutputStream(file);
        fos.write(bytes.toByteArray());
        fos.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return false;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    return true;
}
Also used : FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 93 with FileOutputStream

use of java.io.FileOutputStream in project syncany by syncany.

the class TestFileUtil method createFile.

private static void createFile(File fileToCreate, long sizeInBytes, Random randomGen) throws IOException {
    if (fileToCreate != null && fileToCreate.exists()) {
        throw new IOException("File already exists");
    }
    FileOutputStream fos = new FileOutputStream(fileToCreate);
    int bufSize = 4096;
    long cycles = sizeInBytes / (long) bufSize;
    for (int i = 0; i < cycles; i++) {
        byte[] randomByteArray = createArray(bufSize, randomGen);
        fos.write(randomByteArray);
    }
    // create last one
    // modulo cannot exceed integer range, so cast should be ok
    byte[] arr = createArray((int) (sizeInBytes % bufSize), randomGen);
    fos.write(arr);
    fos.close();
}
Also used : FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException)

Example 94 with FileOutputStream

use of java.io.FileOutputStream in project syncany by syncany.

the class TestFileUtil method writeByteArrayToFile.

public static void writeByteArrayToFile(byte[] inputByteArray, File fileToCreate) throws IOException {
    FileOutputStream fos = new FileOutputStream(fileToCreate);
    fos.write(inputByteArray);
    fos.close();
}
Also used : FileOutputStream(java.io.FileOutputStream)

Example 95 with FileOutputStream

use of java.io.FileOutputStream in project fino by sysdream.

the class InspectionStub method loadMacro.

/**
     * @see IInspectionService.loadMacro
     */
public int loadMacro(final String name, final String dex) throws RemoteException {
    /*
	 * Then try and load the class
	 */
    try {
        String tmpname = UUID.randomUUID().toString() + ".jar";
        final File internal = new File(this.context.getDir("dex", Context.MODE_PRIVATE), tmpname);
        final File optimized = this.context.getDir("outdex", Context.MODE_PRIVATE);
        final FileOutputStream fos = new FileOutputStream(internal);
        fos.write(Base64.decode(dex, Base64.DEFAULT));
        fos.close();
        DexClassLoader loader = new DexClassLoader(internal.getAbsolutePath(), optimized.getAbsolutePath(), null, this.context.getClassLoader());
        Class clazz = loader.loadClass(name);
        return pushObject(clazz);
    } catch (Exception e) {
        //TODO debug
        e.printStackTrace();
        return -1;
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) DexClassLoader(dalvik.system.DexClassLoader) File(java.io.File) RemoteException(android.os.RemoteException)

Aggregations

FileOutputStream (java.io.FileOutputStream)6586 File (java.io.File)3769 IOException (java.io.IOException)2864 FileInputStream (java.io.FileInputStream)1189 OutputStream (java.io.OutputStream)1071 BufferedOutputStream (java.io.BufferedOutputStream)907 InputStream (java.io.InputStream)864 FileNotFoundException (java.io.FileNotFoundException)682 OutputStreamWriter (java.io.OutputStreamWriter)644 Test (org.junit.Test)528 BufferedWriter (java.io.BufferedWriter)313 PrintWriter (java.io.PrintWriter)311 ZipEntry (java.util.zip.ZipEntry)311 BufferedInputStream (java.io.BufferedInputStream)287 DataOutputStream (java.io.DataOutputStream)275 ZipOutputStream (java.util.zip.ZipOutputStream)273 ByteArrayOutputStream (java.io.ByteArrayOutputStream)267 ArrayList (java.util.ArrayList)247 Writer (java.io.Writer)215 URL (java.net.URL)206