FAQ Database Discussion Community
python,io,output,outputstream
This question already has an answer here: Temporarily Redirect stdout/stderr 6 answers Say I have a python program composed of three lines. if __name__=“__main__”: foo( ) print “Hello” Here, foo( ) is a third-part function that outputs things to the standard output. E.g, foo( ) has only one line...
java,outputstream,bufferedwriter
I'm new in java and there is a question about BufferedWriter and OutputStream closing. I have some logic, where it is inconvenient to use try-with-resources: public static void writeFile(String fileName, String encoding, String payload) { BufferedWriter writer = null; OutputStream stream = null; try { boolean needGzip = payload.getBytes(encoding).length >...
java,outputstream
So, you can save a form file through several methods, I guess, I use 2, but I never really know when to use which. I have these 2 pieces of codes that do the same: 1-This writes my form file to specified path. FormFile archivo = myForm.getArchivo(); File newFile =...
java,file,outputstream,zipoutputstream
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...
c++,printing,outputstream,opencv3.0
Currently using OpenCV3, but in OpenCV2, there was a way to format matrix outputs. It is used in a tutorial here. The format function seems to have changed from format(mat, str) in OpenCV2 to format(mat, int) OpenCV3. Making this call: cout << "4x4: " << endl << format(fourByFour, "python") <<...
java,image,sockets,outputstream
I used the code from Here as below and got only half of the picture sent, could anybody tell me the reason? The code to get the size and read the size is too complex to me so I couldn't figure it out. public class Send { public static void...
java,xml,outputstream,fileoutputstream,class-members
I am trying to store an OutputStream as a member of a class so that I can write to it from multiple methods. I put together this jUnit test to demonstrate the problem I have. public class XmlStreamWriterTest { private OutputStream outputStream; @Before public void setUp() throws Exception { File...
java,stream,byte,inputstream,outputstream
I'm trying to implement a communication system with an automatic repeat request strategy. I use three classes: Transmitter, Channel, Receiver. I have a maximum number of byte for message (window). But when I receive the byte sent, sometimes I receive less bytes than window. Why? My code is this: Transmitter...
java,outputstream
I am writing a piece of code: OutputStream outputStream = new FileOutputStream(createdFile); GZIPOutputStream gzipOutputStream = new GZIPOutputStream(outputStream); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(gzipOutputStream)); Do I need to close every stream or writer like the following? gzipOutputStream.close(); bw.close(); outputStream.close(); Or will just closing the last stream be fine? bw.close(); ...
java,sockets,client-server,inputstream,outputstream
I am trying to build a simple client-server aplication. Now I want to print out the current working directory of the server. I have tried by using String workingDir= System.getProperty("user.dir"); method. But it doesn't actually print out the directory. I don't know why. I need help. package clint; import java.io.*;...
java,outputstream,fileoutputstream,java-6,xmlstreamwriter
In my application I have a problem where the the OutputStream does not write anything to the file when I run "mvn clean test", but when I run it in IntelliJ by right-clicking on run testWritingToFile(), it works fine and outputs to the file. I have the following test: @Test...
java,file,outputstream
Below you find the constructor of a server in order to setup it. In a few words, it restore its state from the last time that it was up reading a List of objects (called log) and two int (called currentTerm and votedFor). Any time that any of these "volatile"...
java,pdf,blob,inputstream,outputstream
I have the following situation into a Java application. From the database a retrieve this Blob object that is the representation of a PDF file on the DB: Blob blobPdf = cedolinoPdf.getAllegatoBlob(); Now I have to convert it into a PDF file. How can I do this task? Tnx...
java,oop,inputstream,outputstream
I am sending 2 objects using an ObjectOutputSteam. Can I send the second one before receiving the first one with an ObjectInputStream? Thanks!...
java,io,outputstream
The below code is quoted from : http://examples.javacodegeeks.com/core-java/io/fileoutputstream/java-io-fileoutputstream-example/ Although the OutputStream is an abstract method, at the below code, OutputStream object is used for writing into the file. Files.newOutputStream(filepath)) returns OutputStream. Then, the type of out is OutputStream, and out references OutputStream. How can this be possible while OutputStream is...
java,junit,outputstream
So I looked up this question and tried it, but with no success. My code should be testing if the method is correctly outputing the text onto the console by reading it back in using Streams. ByteArrayOutputStream outStream = new ByteArrayOutputStream(); PrintStream myStream = new PrintStream(outStream); System.setOut(myStream); o.doSomething(); //printing out...
java,jar,outputstream
I was recently trying to export my game to a jar file, and I ran into a problem with converting files to input and output streams. With the regular code that was not exported, I was able to read and write to text files by simply calling the Scanner and...
java,android,inputstream,outputstream
i have made this two routines to copy files using inputstream and outpustream. they are quite the same however the second one rise ArrayIndexOutOfBoundsException while the first one works flawlessly and i don't know why: public void CopyStream(long size, InputStream is, OutputStream os) { final int buffer_size = 4096; byte[]...
jsf-2,jasper-reports,outputstream,zipoutputstream
public String generateReport() { try { final FacesContext facesContext = FacesContext.getCurrentInstance(); final HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse(); response.reset(); response.setHeader("Content-Disposition", "attachment; filename=\"" + "myReport.zip\";"); final BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream()); final ZipOutputStream zos = new ZipOutputStream(bos); for (final PeriodScale periodScale : Scale.getPeriodScales(this.startDate,...
java,sockets,networking,inputstream,outputstream
I have a client-server application. Where the client sends an object and the server sends the same object back, a simple echo server. The code below works fine if I am making a new instance of Client for every new request. However, if I use an existing instance of the...
java,arrays,outputstream
I have a question about the output of Arrays in Java. So, when I have this code: char[] chars = new char[] {'a', 'b', 'c'}; System.out.println(chars); Then the output is: abc. I know that an Array is an Object in Java. So I think the toString() method will be called...
java,outputstream
I have a folder called images under resources folder in eclipse. And I have multiple images in images folder. I want to display all the images in my browser by calling a web-service. I have tried the following code.I am able to retrieve only one image.I want this for multiple...
android,file,outputstream
I know this question has been asked before, but I can't make it to work. Please help. I added the external storage permission, why is it still read-only? public class MainActivity extends Activity { public static final String LOGTAG="EXPLORECA"; public static final String USERNAME="pref_username"; public static final String VIEWIMAGE="pref_viewimages"; private...
java,encryption,inputstream,outputstream
I've tried to sum up my question, but really there's more behind it. For a task at uni we are supposed to create two constructors (English isn't my first language) 1) public SecureInputStream(InputStream base, OutputStream remote) 2) public SecureOutputStream(OutputStream base, InputStream remote) 1) is supposed to create BigIntegers g,n,k then...