J Mangual

Greenhorn
+ Follow
since Nov 15, 2008
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 Mangual

I am reading Vikram Gopal's tutorial on how to write MIDlets. Their example shows the date and time when you launch it. However, when I use the emulator provided with J2ME Wireless Toolkit 2.2, it just disappears when I it launch. A look at the command line says "ALERT: java/lang/ClassFormatError: Bad Version Information". Here's the code it's right out the tutorial:

DateTimeApp.java


Manifest.mf


DateTimeApp.jad
12 years ago
All kinds of care has to be made transmitting the file size because read() and write() do not behave reliably. This one seems to work.

Client:


Server:
I want to copy several files over the same stream. These files may have different sources and different destinations, so I'm using standard input to read the source and file destination names. As written, the client program takes all the input and write it to the same destination file. I would like it to receive a file, detect end of file, close it and create a new FileOutputStream object. Closing the server socket is not an option because I would like to send many files over the same session.

Client

Server

This is really a sequel to an earlier post, but they suggest posting different questions in different threads.
What is the difference between Java EE, ME and SE. Which one should I download?
12 years ago
I changed it so that it reads a variable number of bytes and there is no extra goop at the end of the file now. I try to read and write to the buffer as much as possible, but I realize there is no guarantee to how many bytes are actually written.

The reason I don't want to close the output stream is because I may want to send several files over the same connection. So it's important I find some way of getting the end of file, but maybe that's for another thread. Thanks.

Client:

Server:
Is the FAQ suggesting we are supposed to load the entire file into memory when we receive it?

Here's a quote from Eliotte Rusty Harold's "Java I/O":

Traditional synchronous I/O is designed for traditional applications...

  • Files may be large but not huge. It's possible to read an entire file into memory.
  • An application reads or write only to a few files or network connections at the same time, ideally using only one stream at a time
  • The application is sequential. It won't be able to do muc until it's finished reading or writing a file.


  • So in the FAQ it looks like they read the whole file into the buffer and then process it. Do I need to read the whole file into memory just to copy it accurately?

    A correct usage of read() would be to read chunks of a file and collect them in a buffer like so:




    I want to copy files over a network reliably. The program I have works except for two things:
  • The socket connection should terminate after receiving the file. In runtime, the connection does not terminate. My guess is, the client is stuck in the for loop that reads the file from the network.
  • When I used a test file, numbering the lines from 1 to 1000 (each lines reads "[number] ----- L" ), I noticed about 60 extra lines at the end of the file. Probably this is because I read into and copy from 1024-byte arrays which don't totally get written over at the end of the file.


  • So, how do I detect the end of file when I am using byte arrays like this? Or is there an even bigger issue.



    12 years ago
    This may be more of an I/O question...

    I want to copy files over a network reliably. The program I have works except for two things:
  • The socket connection should terminate after receiving the file. In runtime, the connection does not terminate. My guess is, the client is stuck in the for loop that reads the file from the network.
  • When I used a test file, numbering the lines from 1 to 1000 (each lines reads "[number] ----- L" ), I noticed about 60 extra lines at the end of the file. Probably this is because I read into and copy from 1024-byte arrays which don't totally get written over at the end of the file.


  • So, how do I detect the end of file when I am using byte arrays like this? Or is there an even bigger issue.



    Before I installed Sun Java, my console was suggesting I download things like Cacao or Kaffe. I realized these were open source alternatives to Sun's version. Ultimately, I got the Sun version which is free anyway.

    What are the pros and cons of downloading something like Kaffe? I am not going to do anything too fancy. Can I use it to write networking applications like sockets or java swing applications? I am hoping Kaffe has many of the generally used Java features and maybe not some of the most recent changes.
    12 years ago
    How does one count the number of threads in a program? I want to modify the method below so that when a new socket connects (and a new thread is opened) the count increases by 1 and when the thread ends it decreases by 1. Alternatively, I would like to store all the active threads in an array. Is there a standard way of doing this?

    Is there a limit to the size of files you can copy using java.io.* ? How about over a socket connection, can you copy files the same way. First you have to read the file then you have to send over the network, then you have to copy the data to a file. There seems like a lot of room for error. My friend says I should be able to send files as large as 1GB over a socket connection, is he right?
    12 years ago
    Here is some sample code I found while searching. Is there a way to transfer files which does not depend on the file size?

    The Server:

    The Client:
    12 years ago
    how do i copy files over a network using a socket? I have something written but I hard-code the file size.
    12 years ago
    I need to write a program (client and server side) which takes a file name and sense the file via a socket connection to another address. For example, I might want to send a pdf file across a network. A google search gave quickly gave me a way of copying methods from one location to another on my own computer simply using InputStream and OutputStream. When trying to send files over the Net i quickly confused myself with all the different kinds of streams. Is it possible to write everything with output stream?
    12 years ago
    Semicolons (;) in Windows, huh... now it compiles.

    Follow-up, there are three things I'm specifying in the classpath, servlet-api.jar, "classes" (not sure what that is) and "." which I guess means the current folder.

    [edit]Disable smilies. CR[/edit]
    [ November 17, 2008: Message edited by: Campbell Ritchie ]
    12 years ago