Search in sources :

Example 76 with BufferedOutputStream

use of java.io.BufferedOutputStream in project MagicCamera by wuhaoyu1990.

the class EglSurfaceBase method saveFrame.

/**
     * Saves the EGL surface to a file.
     * <p>
     * Expects that this object's EGL surface is current.
     */
public void saveFrame(File file) throws IOException {
    if (!mEglCore.isCurrent(mEGLSurface)) {
        throw new RuntimeException("Expected EGL context/surface is not current");
    }
    // glReadPixels fills in a "direct" ByteBuffer with what is essentially big-endian RGBA
    // data (i.e. a byte of red, followed by a byte of green...).  While the Bitmap
    // constructor that takes an int[] wants little-endian ARGB (blue/red swapped), the
    // Bitmap "copy pixels" method wants the same format GL provides.
    //
    // Ideally we'd have some way to re-use the ByteBuffer, especially if we're calling
    // here often.
    //
    // Making this even more interesting is the upside-down nature of GL, which means
    // our output will look upside down relative to what appears on screen if the
    // typical GL conventions are used.
    String filename = file.toString();
    int width = getWidth();
    int height = getHeight();
    IntBuffer ib = IntBuffer.allocate(width * height);
    GLES20.glReadPixels(0, 0, width, height, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, ib);
    OpenGlUtils.checkGlError("glReadPixels");
    BufferedOutputStream bos = null;
    try {
        bos = new BufferedOutputStream(new FileOutputStream(filename));
        Bitmap bmp = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        bmp.copyPixelsFromBuffer(IntBuffer.wrap(ib.array()));
        bmp.compress(Bitmap.CompressFormat.PNG, 90, bos);
        bmp.recycle();
    } finally {
        if (bos != null)
            bos.close();
    }
    Log.d(TAG, "Saved " + width + "x" + height + " frame as '" + filename + "'");
}
Also used : Bitmap(android.graphics.Bitmap) IntBuffer(java.nio.IntBuffer) FileOutputStream(java.io.FileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream)

Example 77 with BufferedOutputStream

use of java.io.BufferedOutputStream in project XobotOS by xamarin.

the class SocketHandler method initSocket.

// Initialize the socket connection and prepare the output stream
private void initSocket(String host, String port) throws IOException {
    // check the validity of the host name
    if (host == null || host.isEmpty()) {
        throw new IllegalArgumentException("host == null || host.isEmpty()");
    }
    // check the validity of the port number
    int p = 0;
    try {
        p = Integer.parseInt(port);
    } catch (NumberFormatException e) {
        throw new IllegalArgumentException("Illegal port argument");
    }
    if (p <= 0) {
        throw new IllegalArgumentException("Illegal port argument");
    }
    // establish the network connection
    try {
        this.socket = new Socket(host, p);
    } catch (IOException e) {
        getErrorManager().error("Failed to establish the network connection", e, ErrorManager.OPEN_FAILURE);
        throw e;
    }
    super.internalSetOutputStream(new BufferedOutputStream(this.socket.getOutputStream()));
}
Also used : IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) Socket(java.net.Socket)

Example 78 with BufferedOutputStream

use of java.io.BufferedOutputStream in project XobotOS by xamarin.

the class FileHandler method findNextGeneration.

void findNextGeneration() {
    super.close();
    for (int i = count - 1; i > 0; i--) {
        if (files[i].exists()) {
            files[i].delete();
        }
        files[i - 1].renameTo(files[i]);
    }
    try {
        output = new MeasureOutputStream(new BufferedOutputStream(new FileOutputStream(files[0])));
    } catch (FileNotFoundException e1) {
        this.getErrorManager().error("Error opening log file", e1, ErrorManager.OPEN_FAILURE);
    }
    setOutputStream(output);
}
Also used : FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) BufferedOutputStream(java.io.BufferedOutputStream)

Example 79 with BufferedOutputStream

use of java.io.BufferedOutputStream in project zaproxy by zaproxy.

the class HttpConnection method tunnelCreated.

/**
     * Instructs the proxy to establish a secure tunnel to the host. The socket will 
     * be switched to the secure socket. Subsequent communication is done via the secure 
     * socket. The method can only be called once on a proxied secure connection.
     *
     * @throws IllegalStateException if connection is not secure and proxied or
     * if the socket is already secure.
     * @throws IOException if an attempt to establish the secure tunnel results in an
     *   I/O error.
     */
public void tunnelCreated() throws IllegalStateException, IOException {
    LOG.trace("enter HttpConnection.tunnelCreated()");
    if (!isTunnelRequired()) {
        throw new IllegalStateException("Connection must be secure " + "and proxied or a tunnel requested to use this feature");
    }
    if (usingSecureSocket) {
        throw new IllegalStateException("Already using a secure socket");
    }
    if (isSecure()) {
        SecureProtocolSocketFactory socketFactory = (SecureProtocolSocketFactory) protocolInUse.getSocketFactory();
        socket = socketFactory.createSocket(socket, hostName, portNumber, true);
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Secure tunnel to " + this.hostName + ":" + this.portNumber);
    }
    int sndBufSize = this.params.getSendBufferSize();
    if (sndBufSize >= 0) {
        socket.setSendBufferSize(sndBufSize);
    }
    int rcvBufSize = this.params.getReceiveBufferSize();
    if (rcvBufSize >= 0) {
        socket.setReceiveBufferSize(rcvBufSize);
    }
    int outbuffersize = socket.getSendBufferSize();
    if (outbuffersize > 2048) {
        outbuffersize = 2048;
    }
    int inbuffersize = socket.getReceiveBufferSize();
    if (inbuffersize > 2048) {
        inbuffersize = 2048;
    }
    inputStream = new BufferedInputStream(socket.getInputStream(), inbuffersize);
    outputStream = new BufferedOutputStream(socket.getOutputStream(), outbuffersize);
    usingSecureSocket = true;
    tunnelEstablished = true;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) SecureProtocolSocketFactory(org.apache.commons.httpclient.protocol.SecureProtocolSocketFactory) BufferedOutputStream(java.io.BufferedOutputStream)

Example 80 with BufferedOutputStream

use of java.io.BufferedOutputStream in project ZI by yixia.

the class BitmapHelper method saveBitmapToFile.

public static boolean saveBitmapToFile(final Bitmap bitmap, String savePath) {
    boolean result = false;
    if (bitmap != null && !bitmap.isRecycled()) {
        File myDrawFile = new File(savePath);
        try {
            BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(myDrawFile));
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, bos);
            bos.flush();
            bos.close();
            result = true;
        } catch (Exception e) {
            Log.e("saveBitmapToFile", e);
        } finally {
            if (bitmap != null) {
                bitmap.recycle();
            }
        }
    }
    return result;
}
Also used : FileOutputStream(java.io.FileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

BufferedOutputStream (java.io.BufferedOutputStream)1219 FileOutputStream (java.io.FileOutputStream)861 IOException (java.io.IOException)617 File (java.io.File)519 OutputStream (java.io.OutputStream)350 BufferedInputStream (java.io.BufferedInputStream)238 InputStream (java.io.InputStream)166 DataOutputStream (java.io.DataOutputStream)158 FileInputStream (java.io.FileInputStream)145 ZipOutputStream (java.util.zip.ZipOutputStream)121 FileNotFoundException (java.io.FileNotFoundException)113 ZipEntry (java.util.zip.ZipEntry)108 ByteArrayOutputStream (java.io.ByteArrayOutputStream)101 ZipFile (java.util.zip.ZipFile)62 URL (java.net.URL)57 XmlSerializer (org.xmlpull.v1.XmlSerializer)57 FastXmlSerializer (com.android.internal.util.FastXmlSerializer)56 ObjectOutputStream (java.io.ObjectOutputStream)54 GZIPOutputStream (java.util.zip.GZIPOutputStream)51 PrintStream (java.io.PrintStream)46