List of usage examples for java.io OutputStream OutputStream
OutputStream
From source file:Main.java
public Console() { JTextArea textArea = new JTextArea(24, 80); textArea.setBackground(Color.BLACK); textArea.setForeground(Color.LIGHT_GRAY); textArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12)); System.setOut(new PrintStream(new OutputStream() { @Override/*from w w w .j av a2s. com*/ public void write(int b) throws IOException { textArea.append(String.valueOf((char) b)); } })); frame.add(textArea); }
From source file:corina.logging.CorinaLog.java
private static PrintStream createPrintStream(final Log log, final boolean error) { return new PrintStream(new OutputStream() { public void write(int b) { byte[] barray = { (byte) b }; write(barray, 0, 1);//from w w w . j a va 2s.c om } public void write(byte[] b, int off, int len) { String str = new String(b, off, len); // skip any trailing EOL if ("\r".equals(str) || "\n".equals(str) || "\r\n".equals(str)) return; if (error) { log.error(str); } else { log.info(str); } } }); }
From source file:org.fejoa.library.crypto.KDFParameters.java
public HashValue hash(MessageDigest messageDigest) { OutputStream outputStream = new DigestOutputStream(new OutputStream() { @Override/*w w w. ja v a 2s .c o m*/ public void write(int i) throws IOException { } }, messageDigest); try { outputStream.write(kdfSettings.hash(messageDigest).getBytes()); outputStream.write(kdfSalt); outputStream.close(); } catch (IOException e) { e.printStackTrace(); } return new HashValue(messageDigest.digest()); }
From source file:com.clican.pluto.transaction.resources.memory.XAFileResourceMemoryImpl.java
public OutputStream getOutputStream() throws XAException, FileNotFoundException { if (xidThreadLocal.get() == null) { throw new XAException(); }//w ww. j a va 2 s .com OutputStream os = new OutputStream() { @Override public void close() throws IOException { } @Override public void flush() throws IOException { } @Override public void write(byte[] b, int off, int len) throws IOException { if (lockedXid != xidThreadLocal.get()) { throw new IOException( "This file [" + file + "] has been locked by anthoer thread, you can't write it"); } lockedXid = xidThreadLocal.get(); byte[] data = modifiedDataMapping.get(xidThreadLocal.get()); int srcOff = 0; if (data == null) { data = new byte[len]; } else { byte[] old = data; data = new byte[data.length + len]; srcOff = old.length; for (int i = 0; i < old.length; i++) { data[i] = old[i]; } } for (int i = srcOff; i < data.length; i++) { data[i] = b[i - srcOff]; } modifiedDataMapping.put(xidThreadLocal.get(), data); } @Override public void write(byte[] b) throws IOException { write(b, 0, b.length); } @Override public void write(int b) throws IOException { write(new byte[] { (byte) b }); } }; return os; }
From source file:tools.descartes.wcf.rServerBridge.RServerBridgeControl.java
private RServerBridgeControl(boolean silent) { OutputStream out = System.out; if (true == silent) { out = new OutputStream() { @Override//from w w w .j a v a 2s .com public void write(final int arg0) throws IOException { } }; } else { out = new OutputStream() { private int lineEnd = (int) '\n'; private ByteArrayOutputStream baos = new ByteArrayOutputStream(); @Override public void write(int b) throws IOException { if (b == lineEnd) { RSERVELOG.info(baos.toString()); baos.reset(); } else baos.write(b); } }; } RserverConf serverconf = new RserverConf(HOST, PORT, USER, PASSWD, null); this.rCon = Rsession.newInstanceTry(new PrintStream(out), serverconf); }
From source file:org.s23m.cell.editor.semanticdomain.ui.components.FileReceiver.java
public OutputStream receiveUpload(final String filename, final String mimeType) { return new OutputStream() { @Override// ww w .j a v a 2 s . com public void write(final int b) throws IOException { byteList.add((byte) b); } }; }
From source file:com.btoddb.trellis.common.serialization.JavaSerializer.java
@Override public ByteBuffer serialize(final ByteBuffer bb, Serializable obj) { OutputStream os = new OutputStream() { @Override/*from w ww . j a va 2 s .co m*/ public void write(int oneByte) throws IOException { bb.put((byte) oneByte); } }; serializeToOutputStream(obj, os); return bb; }
From source file:com.clican.pluto.transaction.resources.memory.XAFileSetResourceMemoryImpl.java
public OutputStream getOutputStream(final File file) throws XAException, FileNotFoundException { if (xidThreadLocal.get() == null) { throw new XAException(); }/*from w w w . ja va 2 s . c o m*/ OutputStream os = new OutputStream() { @Override public void close() throws IOException { } @Override public void flush() throws IOException { } @Override public void write(byte[] b, int off, int len) throws IOException { if (lockedXid != null && lockedXid != xidThreadLocal.get()) { throw new IOException("This directory [" + directory + "] has been locked by anthoer thread, you can't write it"); } lockedXid = xidThreadLocal.get(); byte[] data = modifiedDataMapping.get(xidThreadLocal.get()).get(file); int srcOff = 0; if (data == null) { data = new byte[len]; } else { byte[] old = data; data = new byte[data.length + len]; srcOff = old.length; for (int i = 0; i < old.length; i++) { data[i] = old[i]; } } for (int i = srcOff; i < data.length; i++) { data[i] = b[i - srcOff]; } modifiedDataMapping.get(xidThreadLocal.get()).put(file, data); } @Override public void write(byte[] b) throws IOException { write(b, 0, b.length); } @Override public void write(int b) throws IOException { write(new byte[] { (byte) b }); } }; return os; }
From source file:org.fejoa.library.crypto.UserKeyParameters.java
public HashValue hash(MessageDigest messageDigest) { OutputStream outputStream = new DigestOutputStream(new OutputStream() { @Override/*from ww w.j ava2 s . c o m*/ public void write(int i) throws IOException { } }, messageDigest); try { outputStream.write(kdfParameters.hash(messageDigest).getBytes()); outputStream.write(userKeySalt); outputStream.write(hashAlgo.getBytes()); outputStream.close(); } catch (IOException e) { e.printStackTrace(); } return new HashValue(messageDigest.digest()); }
From source file:com.shigeodayo.ardrone.utils.ARDroneInfo.java
private boolean connectToDroneThroughFtp() { FTPClient client = new FTPClient(); BufferedOutputStream bos = null; try {/*from w w w . j a v a2 s. com*/ client.connect(ARDroneConstants.IP_ADDRESS, ARDroneConstants.FTP_PORT); if (!client.login("anonymous", "")) { ARDrone.error("Login failed", this); return false; } client.setFileType(FTP.BINARY_FILE_TYPE); bos = new BufferedOutputStream(new OutputStream() { @Override public void write(int arg0) throws IOException { //System.out.println("aa:" + (char)arg0); switch (count) { case 0: major = arg0 - '0'; break; case 2: minor = arg0 - '0'; break; case 4: revision = arg0 - '0'; break; default: break; } count++; } }); if (!client.retrieveFile("/" + VERSION_FILE_NAME, bos)) { ARDrone.error("Cannot find \"" + VERSION_FILE_NAME + "\"", this); return false; } bos.flush(); //System.out.print("major:" + major); //System.out.print(" minor:" + minor); //System.out.println(" revision:" + revision); //System.out.println("done"); } catch (IOException e) { e.printStackTrace(); return false; } finally { try { if (bos != null) { bos.flush(); bos.close(); } client.disconnect(); } catch (IOException e) { e.printStackTrace(); return false; } } return true; }