I am learning GoF Java Design Patterns and I want to see some real life examples of them. Can you guys point to some good usage of these Design Patterns.(preferably in Java's core libraries).
Thank you
I know the question has been discussed before, but it seems always under the assumption that inheritance is at least sometimes preferable to composition. I'd like to challenge that assumption in hopes of gaining some understanding.
My question is this: Since you can accomplish anything with object composition that you can with classical inheritance and since classical inheritance is very often...
As shown below, there are two straightforward ways I could make a stream copier (bar introducing Apache Commons or similar). Which one should I go for, and why ?
public class StreamCopier {
private int bufferSize;
public StreamCopier() {
this(4096);
}
public StreamCopier(int bufferSize) {
this.bufferSize = bufferSize;
}
public long copy(InputStream in , OutputStream out ) throws IOExcepti...
I have generated many pdf files in memory and I want to compress them into one zip file before sending it as a email attachment. I have looked at Rubyzip and it does not allows me to create a zip file without saving it to disk (maybe I am wrong).
Is there any way I can compress those file without creating a temp file ?
I am writing an OutputStream, just noticed this in the OutputStream interface,
public abstract void write(int b) throws IOException;
This call write one byte to the stream but why it takes integer as an argument?
I set up a server with a ServerSocket, connect to it with a client machine. They're directly networked through a switch and the ping time is <1ms.
Now, I try to push a "lot" of data from the client to the server through the socket's output stream. It takes 23 minutes to transfer 0.6Gb. I can push a much larger file in seconds via scp.
Any idea what I might be doing wrong? I'm basically...
I have come across these two terms and my understanding of them seem to overlap with each other. Flush is used with buffers and sync is used to talk about persisting changes of file to disk.
In C , fflush(stdin) makes sure that the buffer is cleared. And fsync to persist changes file to disk.
If these concepts are not universally defined, would prefer a linux, java explanation.
found a relat...
I'm trying to upload a file via URLConnection, but I need to read/write it as a binary file without any encoding changes.
So i've tried to read byte[] array from a FileInputStream, but now i have an issue. The PrintWriter object I use for outputing to the server does not allow me to do writer.write(content) (where content is of type byte[]). How can i fix this? Or is there another way to quick...
I know the general idea but I'm just not sure if it has an effect since the Android api states following: "Flushes this stream. Implementations of this method should ensure that any buffered data is written out. This implementation does nothing."
This implementation does nothing <-- does that mean its useless to do or am I missing something?
What is a stream in the programming world ?
Why do we need it ?
Kindly explain with the help of an analogy, if possible.
Why some methods that write bytes/chars to streams takes int instead of byte/char??
Someone told me in case of int instead of char:
because char in java is just 2 bytes length, which is OK with most character symbols already in use, but for certain character symbols (chines or whatever), the character is being represented in more than 2 bytes, and hence we use int instead.
How far this explan...
I am currently attempting to modify some open source software in JSP and am unaware of the syntax.
How does one dump a complex variable to the browser using JSP?
We have a system where a client makes an HTTP GET request, the system does some processing on the backend, zips the results, and sends it to the client. Since the processing can take some time, we send this as a ZipOutputStream wrapping the response.getOutputStream().
However, when we have an exceptionally small amount of data in the first ZipEntry, and the second entry takes a long time, the...
I need to convert numerical values into byte arrays. For example, to convert a long to a byte array, I have this method:
public static byte[] longToBytes(long l) {
ByteBuffer buff = ByteBuffer.allocate(8);
buff.order(ByteOrder.BIG_ENDIAN);
buff.putLong(l);
return buff.array();
}
It's pretty straightforward - take a long, allocate an array that can hold it, and throw it in there. R...
which is the right way to download a file using JSF?, just putting a link to the file ?? in that case how do i get the file URL??
i have seen one example using BufferedInputStream:
http://www.winstonprakash.com/articles/jsf/file_download_link.htm
What are the differences?
Thanks
In Really force file sync/flush in Java, the author writes in the summary of the answers:
Use c.force(true) followed by s.getFD().sync() for Java NIO
My question is: do you really need both? Isn't force enough? Aren't force and sync just different interfaces for doing the same thing? I can't find anyplace where this is confirmed.
Our app sends the contents of the derby.log file to our server whenever Apache Derby throws a SQLException in our app.
In order to get detailed logs, we are setting the 'derby.infolog.append' property to true.
However, we are noticing enormously large logs files since the logs also contain bootup output each time a connection is made to the database.
NOTE: we are using Derby in embedded mode...
Two quotes:
All of the remaining messages in the protocol take the form of <length prefix><message ID><payload>. The length prefix is a four byte big-endian value. The message ID is a single decimal byte. The payload is message dependent.
request: <len=0013><id=6><index><begin><length>
The request message is fixed length, and is used t...
If I have a file, and I want to literally write '42' to it (the value, not the string), which for example is 2a in hex, how do I do it? I want to be able to use something like outfile.write(42) or outfile.write(2a) and not write the string to the file.
(I realize this is a simple question but I can't find the answer of google, probably because I don't know the correct search terms)
I am working on sound processing with the use of Java now. Within my project, I have to deal with the stream. So I have a lot of staffs to do with DataLine and OutputStream or InputStream.
But to me, they are too similar:(
Is there someone who can help me with this question? Thanks in advance!
Here are some code I used :
TargetDataLine line;
ByteArrayOutputStream out = new By...
I'am a big fan of
http://php.net/manual/en/function.flush.php
Can I do the same thing using Java?
thanks for your help