outputstream

How can I force a CipherOutputStream to finish encrypting but leave the underlying stream open?

半世苍凉 提交于 2019-12-05 03:06:21
I have a CipherOutputStream backed by another OutputStream. After I have finished writing all the data I need encrypted to the CipherOutputStream, I need to append some unencrypted data. The documentation for CipherOutputStream says that calling flush() will not force the final block out of the encryptor; for that I need to call close() . But close() also closes the underlying OutputStream, which I still need to write more to. How can I force the last block out of the encryptor without closing the stream? Do I need to write my own NonClosingCipherOutputStream? If you don't have a reference to

How to put data from an OutputStream into a ByteBuffer?

怎甘沉沦 提交于 2019-12-04 22:32:48
In Java I need to put content from an OutputStream (I fill data to that stream myself) into a ByteBuffer. How to do it in a simple way? DJClayworth You can create a ByteArrayOutputStream and write to it, and extract the contents as a byte[] using toByteArray() . Then ByteBuffer.wrap(byte []) will create a ByteBuffer with the contents of the output byte array. mark There is a more efficient variant of @DJClayworth's answer. As @seh correctly noticed, ByteArrayOutputStream.toByteArray() returns a copy of the backing byte[] object, which may be inefficient. However, the backing byte[] object as

StreamCorruptedException when sending Serialized objects via Bluetooth

我怕爱的太早我们不能终老 提交于 2019-12-04 12:59:37
I have a Serialized class that I need to send as an object via Bluetooth, and also implements Runnable. As such, I set a few variables first, then send it as an object to be executed by another Android device, which will then set its result into a variable, and send back the same object with the result in one of the variables. I have been using the following two methods to serialize my object and get a ByteArray before sending them through the OutputStream of my BluetoothSocket, and to deserialize that ByteArray to get back my object. public static byte[] serializeObject(Object o) throws

Usage of FilterOutputStream

感情迁移 提交于 2019-12-04 12:22:32
What is practical usage of FilterOutputStream in Java? From javadocs: This class is the superclass of all classes that filter output streams. These streams sit on top of an already existing output stream (the underlying output stream) which it uses as its basic sink of data, but possibly transforming the data along the way or providing additional functionality. For me it seems to have same methods as OutputStream (maybe it overrides them for some reason?). What kind of data "transformation" does it offer and when can one use it in own Java application? Joshua Bloch in Effective Java Item 16:

How do I redirect log4j output to my HttpServletResponse output stream?

不打扰是莪最后的温柔 提交于 2019-12-04 06:22:39
I'm using log4j 1.2.15 in a Spring 3.1.1.RELEASE application deployed on JBoss AS 7.1.1.Final. I'm trying to route output written in log4j to my response output stream. I have output written like this private static final Logger LOG = Logger.getLogger(TrainingSessionServiceImpl.class); … LOG.info("Creating/updating training session associated with order #:" + order.getId()); and I'm trying to route it to my output stream like so … @RequestMapping(value = "/refreshPd", method = RequestMethod.GET) public void refreshPD(final HttpServletResponse response) throws IOException { ... final

Reader/Writer与InputStream/OutputStream的区别

有些话、适合烂在心里 提交于 2019-12-03 19:19:34
1. Readers and writers are like input streams and output streams. The primary difference lies in the fundamental datatype that is read or written; streams are byte-oriented, whereas readers and writers use characters and strings. 2. The reason for this is internationalization. Readers and writers were designed to allow programs to use a localized character set and still have a stream-like model for communicating with external devices. 3. These are analogous to the read( ) methods defined for InputStream. For example, read( ) still returns an integer. The difference is that, instead of data

Android Bluetooth: java.io.IOException: Service discovery failed

两盒软妹~` 提交于 2019-12-03 16:49:48
I'm trying to develop an Android application which transfers images from one device to another. The received image would then be shown on the ImageView inside my application. To achieve my task, I thought to send a byte array of the bitmap. I'm able to get the first image on the imageview. But, as soon as I click on the button to send another image the application fails to send the bitmap. It shows me an exception "java.io.IOException: Service fiscovery failed." To send any image successfully I need to restart my application on the receiving/remote device. Can anyone please suggest a solution

How to save the file from HTTPS url in JAVA?

瘦欲@ 提交于 2019-12-03 10:20:57
问题 I am trying to save a file from URL using outputstream. The URL is secure by https. So I got some error when I try to get the file as the following javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target at sun.security.ssl.Alerts.getSSLException(Unknown Source) at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source) at sun

How to convert image into hexa decimal bytes array to send it to output stream in iOS sdk

血红的双手。 提交于 2019-12-03 03:57:12
I wan to print an image on a bluetooth printer. I got some sample code by the printer manufacturer. Here is the code - unsigned char buffer3[796]={ 0x55 , 0x66 , 0x77 , 0x88 , 0x44 , 0x1B , 0x58 , 0x31 , 0x19, 0x20, 0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00

Does swift have a protocol for writing a stream of bytes?

邮差的信 提交于 2019-12-03 01:30:01
I can't find anything in the Swift book about io. Is there any generic protocol similar to Java's OutputStream or Go's Writer interface for writing a stream of bytes? If you are writing a class that returns a stream, do you need to write your own protocol or use an Objective C protocol? To be clear am asking for a Swift native interface for this not because I avoiding using Objective C or Cocoa, but for a description of the expected behavior for Swift to Swift code going forward. This is something the Swift docs are quiet about and I wanted to know more about so I looked into it. There is a