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 + "'");
}
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()));
}
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);
}
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;
}
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;
}
Aggregations