J Kneeland

Ranch Hand
+ Follow
since Aug 15, 2004
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by J Kneeland

Well,as you may know, you use Buffers to work with NIO channels. You can get an object into a byte array by using an ObjectOutputStream wrapped around a ByteArrayOutputStream. After you are done writing the object, you can get the array from the ByteArrayOutputStream by calling its toByteArray() method which returns a byte array. Now that you have the object in a byte array, you need to get it into a Buffer. The best choice for this is the ByteBuffer class since it is implemented using a byte array internaly. You can obtain a ByteBUffer object that contains this data by calling the static method wrap(byte[]) and passing the byte array you had. You can now send the data through the channel by calling it's write(Buffer) method and passing the buffer. In order to retrieve the data using NIO, you would do the exact opposite using the input stream complements to the output streams you used.

Done using NIO SocketChannels:
* Note, not accounting for exceptions. Catch them yourself *

15 years ago
You need to be using the file scheme to do that. new URL("file://.....";); The file is supposed to be on the same machine and it is just another way of giving the location on the system. You probably need to figure out another way instead of using Files.
15 years ago
I am trying to make a download manager. I am using a class download that will do most of the work and will allow you to use multiple connections like FlashGet or the like.

Here is a proof of concept class that copies a file using more than one thread at the same time. The only problem I have is that I can't figure out how change the number of threads after download.

Current algorithm:

1) Call to copy()
2) It makes x amount of Threads using Thread(this) and runs them
3) Check if the length of the destination file is set - set it
4) Divide the file length by the number of threads; multiply this by the id of the thread and you get the end position ; id -1 for the start postion
5)Synch on the file and seek to the current position
6)Read
7)Synch on the other file and seek to the current position
8)Write
9)Go to 5 till you have read till stop

Anyone got any ideas on how to allow it to resize the partitions and add/remove threads?

15 years ago
That was what I was looking for.


Thanks Mike
15 years ago

Originally posted by Jeanne Boyarsky:
You also want to make sure you download and study the case study from the AP test web site.



Yes, I was also going to do that.

Thanks
15 years ago
The only problem with this is it has to go into a ByteBuffer. I guess I could store it into a ShortBuffer though.

Edit: Yeah, I need a ByteBuffer so I need an array of bytes.

Thanks
[ September 25, 2004: Message edited by: J Kneeland ]
15 years ago
Do I see prefix arithmetic?


I noticed that about most Java books. They tended to cover way more than was required like Applets and graphics which they don't even talk about on the test. I was looking for something pretty bareboned, but I will look in to this book

Thanks
[ September 24, 2004: Message edited by: J Kneeland ]
15 years ago
I found some code used as an example of how to get the time since 1900 and unsinged 32 bit number for implenting a time server.



Well it doesn't seem to work and this is the first time I have used bit wise operators before. Anyone spot the problem?
15 years ago
I know Java pretty well if you don't count graphics or applets. I was wondering what you would suggest for studying for the AP CS test. I was going to take the AP class, but they notified me at the last minute that they figured out that I would have to pass a C++ course in two weeks and make a 90. Well, this wasn't working to well for me, so I think I may take the test by myself. What review books and study guides are good?
15 years ago
You have the right idea, but wrong way. Look at the system.exec() method. It returns a Process object on which you can get an input stream and and output stream to talk to it.
15 years ago
I am using telnet to test it out. I telnet in and it works find, but it always says I'm still connected on the other side. I can even call isConnected(); on the channel and it still returns true. You need Java 1.5 to compile this since I am using BlockingQueue and Generics. You can find the precompiled versions at http://files.amdfanboy.com under JChat.

I guess I didn't see that, thanks
16 years ago
Any open source Java project that wouldn't mind someone who has a reasonable amount of experience(Intermediate?)? I would really like a chance to use Java networking(esp java.nio) and become more proficient in it. If at all possible, I prefer smaller groups. (people < 20)

THX
I would like to ask about any open source Java project that wouldn't mind someone who has a reasonable amount of experience(Intermediate?). I would really like a chance to use Java networking(esp java.nio) and become more proficient in it.

Thanks
16 years ago