outputstream

Sharing output streams through a JNI interface

匆匆过客 提交于 2019-12-21 03:37:33
问题 I am writing a Java application that uses a C++ library through a JNI interface. The C++ library creates objects of type Foo , which are duly passed up through JNI to Java. Suppose the library has an output function void Foo::print(std::ostream &os) and I have a Java OutputStream out . How can I invoke Foo::print from Java so that the output appears on out ? Is there any way to coerce the OutputStream to a std::ostream in the JNI layer? Can I capture the output in a buffer the JNI layer and

Are the C formatted I/O functions (printf, sprintf, etc) more popular than IOStream, and if so, why? [closed]

匆匆过客 提交于 2019-12-20 17:39:05
问题 As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 9 years ago . I've been looking through a lot of code made by others lately and happened to notice everyone uses "printf" style C functions a lot,

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

旧巷老猫 提交于 2019-12-20 15:23:23
问题 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

Could I duplicate or intercept an output stream in Java?

∥☆過路亽.° 提交于 2019-12-19 17:40:44
问题 I want to intercept the standard output stream, then copy the content to another stream, but I also hope to keep the standard output stream like the original. Could I achieve that in Java? 回答1: You can use something like the example of TeeOutputStream explained here Writing Your Own Java I/O Stream Classes Basically you create a TeeOutputStream, give it your stream and current System.out then use System.setOut with the new stream. Anything written to System.out will be written to the original

Using PrintWriter and OutputStream

十年热恋 提交于 2019-12-19 08:01:06
问题 I am creating a project with struts and I have a problem using Jasper IReports. I want to export some info into a pdf file and I keep getting the java.lang.IllegalStateException: getOutputStream() has already been call... Exception due to openning a ServletOutputStream in my code when the page already opens a PrintWriter. The code is in the model (so it is not in the jsp, it's in a java file), as it follows: public void handle(HttpServletResponse res, Connection connection, String path)throws

How to write Strings to an OutputStream

不问归期 提交于 2019-12-19 05:23:17
问题 How can I create class that takes an implentation of OutputStream and writes the the content to it? For example, the following print method is wrong and will not compile. What are the options or better techniques? public class FooBarPrinter{ private OutputStream o; public FooBarPrinter(OutputStream o){ this.o=o; } public void print(String s){ o.write(s); } } 回答1: A generic OutputStream doesn't have the ability to write a String directly to it. Instead, you need to get the byte[] of the String

Why do I have to close the ZipOutputStream in a certain way in this situation?

孤街醉人 提交于 2019-12-19 04:22:44
问题 I have two examples : Example 1: try (ByteArrayOutputStream baous = new ByteArrayOutputStream(); FileOutputStream fouscrx = new FileOutputStream(new File(output, "example"))) { try (ZipOutputStream zous = new ZipOutputStream(baous)) { for (File file: files) { try (FileInputStream fis = new FileInputStream(file)) { ZipEntry zipEntry = new ZipEntry(file.getPath().substring(output.getPath().length() + 1)); zous.putNextEntry(zipEntry); byte[] bytes = new byte[2048]; int length; while ((length =

Java servlet and IO: Create a file without saving to disk and sending it to the user

心不动则不痛 提交于 2019-12-18 13:25:23
问题 I`m hoping can help me out with a file creation/response question. I know how to create and save a file. I know how to send that file back to the user via a ServletOutputStream. But what I need is to create a file, without saving it on the disk, and then send that file via the ServletOutputStream. The code above explains the parts that I have. Any help appreciated. Thanks in Advance. // This Creates a file // String text = "These days run away like horses over the hill"; File file = new File(

Java servlet and IO: Create a file without saving to disk and sending it to the user

杀马特。学长 韩版系。学妹 提交于 2019-12-18 13:24:19
问题 I`m hoping can help me out with a file creation/response question. I know how to create and save a file. I know how to send that file back to the user via a ServletOutputStream. But what I need is to create a file, without saving it on the disk, and then send that file via the ServletOutputStream. The code above explains the parts that I have. Any help appreciated. Thanks in Advance. // This Creates a file // String text = "These days run away like horses over the hill"; File file = new File(

Writing Data to an OutputStream with Swift 5+

百般思念 提交于 2019-12-18 09:34:38
问题 This code used to be fine (in the sense that the compiler didn't complain): extension OutputStream { func write(_ data: Data) -> Int { return data.withUnsafeBytes { pointer in return self.write(pointer, maxLength: data.count) } } } Since Swift 5.0, this produces a warning: Warning: 'withUnsafeBytes' is deprecated: use withUnsafeBytes<R>(_: (UnsafeRawBufferPointer) throws -> R) rethrows -> R instead I tried using the proposed method but I can't seem to wrangle the UnsafeRawBufferPointer into