What is the best way to send a file?

i am writing a program and i want to transfer a file from a client class to a server class... what is the best way to do that?
convert the file to bytes using the following
File file=new File("jobs.xml");
           byte buffer[]=new byte[(int)file.length()];
           try {
                BufferedInputStream input=new BufferedInputStream(new FileInputStream("jobs.xml"));
                input.read(buffer,0,buffer.length);
                input.close();
           } catch(Exception e) {//DIORTHOSE TA MSGS
              System.out.println("reading jobs.xml->buffer: "+e.getMessage());
              e.printStackTrace();
           firstServerRef.translationService(theCallbackObjectRef, buffer);for a reason i dont like that i am reading the file again to put it in the buffer and send the buffer... are my worries reasonable or not? is there any other better way to do that?

Use a smaller buffer, repeatedly read and
write, and print the exception's stack trace.
What do you mean by reading again, by the way? I only
see you reading the file once.hmm you mean use a smaller buffer and call the function with the smaller buffer many times in a while?
the client and the server are not on a single machine and i want to call the function only once... could you clarify the thing that you said..
yes you are correct that you see only one reading because i haven't pasted the rest of the code which is sth like...
FileWriter fw = new FileWriter("jobs.xml");
           ObjectOutputStream out = xstream.createObjectOutputStream(fw);
     //      out.writeObject(new Jobb("ougk2", "Walnes",null));
          for(int i=0;i<nameOfServices.length;i++){
               Jobb translationJob=new Jobb();
               //find the service !
             NameComponent nc = new NameComponent(nameOfServices, " ");
// Resolve the object reference in naming
NameComponent path[] = {nc};
//create a ref for the servant of the service
ServiceOperations theRemoteObjRef = ServiceHelper.narrow(ncRef.resolve(path));
// JobOperations theRemoteObjRef = JobHelper.narrow(ncRef.resolve(path));
translationJob.setObjServerRef(theRemoteObjRef.toString());
if(i==0){ //this is the first job
     translationJob.setForTranslation(wordForTranslation);
     firstServerRef=theRemoteObjRef;
     out.writeObject(translationJob);
     out.close();
     File file=new File("jobs.xml");
          byte buffer[]=new byte[(int)file.length()];
          try {
               BufferedInputStream input=new BufferedInputStream(new FileInputStream("jobs.xml"));
               input.read(buffer,0,buffer.length);
               input.close();
          } catch(Exception e) {//DIORTHOSE TA MSGS
     System.out.println("reading jobs.xml->buffer: "+e.getMessage());
     e.printStackTrace();
          firstServerRef.translationService(theCallbackObjectRef, buffer);
which i believe is bad....

Similar Messages

  • What is the best way to safeguard my files and pictures before I send off my MacBook Pro to get fixed?

    What is the best way to safeguard my files and pictures before I send off my MacBook Pro to get fixed? I am running Mavericks and use an AirPort Time Machine to back-up all my files.

    Back up all data on the internal drive(s) before you hand over your computer to anyone. You need at least two independent backups to be completely safe. There are ways to back up a computer that isn't fully functional—ask if you need guidance.
    If privacy is a concern, erase the data partition(s) with the option to write zeros* (do this only if you know how to restore to an empty drive.) Don’t erase the recovery partition, if present.
    Keeping your confidential data secure during hardware repair
    Apple also recommends that you deauthorize a device in the iTunes Store before having it serviced.
    *An SSD doesn't need to be zeroed.

  • What is the best way to merge a file content into log file

    What is the best way to merge a file content into log file.
    In worst case, I will read the file line by line as string, then use
    logger.info(lineString)to output to log file.
    However, is there better way to do this?
    The eventual log file will be something like:
    log message 1
    log message 2
    content from file line 1
    content from file line 2
    content from file line 3
    log message 3
    log message 4Thanks

    John618 wrote:
    Thank you and let me explain:
    1. What do you mean by better?
    I would like to see better performance. read line by line and log each line as string can be slow. Did you measure this and determine that it is actually a problem for your application? Or are you guessing?
    Regardless of what you do you are still going to need to read the file.
    >
    2.The only better way I can think of is not having to do it, but I assume you have a very good reason to want to do this.
    Yes, I have to do it beacuse the requirement is to have that file content be part of logging.
    Any idea?How is it supposed to be part of it? For example which of the following is better?
            File AAA - contents
                       First Line
                       Second Line XXX
            Log 1
                    2009-03-27 DEBUG: Random preceding line
                    2009-03-27 DEBUG: First Line
                    2009-03-27 DEBUG: Second Line XXX
                    2009-03-27 DEBUG: Random following line
            Log 2
                    2009-03-27 DEBUG: Random preceding line
                    2009-03-27 DEBUG: ----- File: AAA -------------
                    First Line
                    Second Line XXX
                    2009-03-27 DEBUG: Random following lineBoth of the above have some advantages and disadvantages.
    The first in a mult-threaded app can end up with intermittent log entries in between lines, so having log lines with thread ids becomes important.
    The first can be created by reading one line at a time and posting one at a time.
    The second can be created by reading the entire file as a single string and then posting using a single log statement.

  • What is the best way to find a file on the servers disk without using web.xml?

              What is the best way to find a file on the servers disk without using web.xml?
              I want to find a configuration file not contained within the war file I have
              created. Is there a way to pass information into the ServletContext with out
              rebuilding the ear or war files? Tomcat 4.0 can do this in its server configuration
              files. Does BEA have the equivalent?
              Regards,
              Eric
              

    You can specify the path to the file as a system property
              eg
              java -Dconfig.file.location=./mydirecotry/myfile.txt com.test.MyApp
              "Eric White" <[email protected]> wrote in message
              news:[email protected]..
              >
              > What is the best way to find a file on the servers disk without using
              web.xml?
              > I want to find a configuration file not contained within the war file I
              have
              > created. Is there a way to pass information into the ServletContext with
              out
              > rebuilding the ear or war files? Tomcat 4.0 can do this in its server
              configuration
              > files. Does BEA have the equivalent?
              >
              > Regards,
              > Eric
              

  • What is the best way to name a file?

    What is the best way to name a file? Use "_" so that the characters make one, long name? Why do that?

    Another take on naming files, particularly image files, is like this:
    I use a file remaning application like Name Mangler to back, sequentially rename the photos.  I put them in a folder with a similar name.  Using the format I do, YYYY-MM-DD- Description-001.jpg, they are easy to sort by date by sorting alphanumerically.
    OT

  • What is the best way to keep your files organised

    I would like to know what is the best way to keep your file organise when I am
    Loading program's like numbers and pages from iPhone to MacBook i alway 
    Get double of the same work sheet

    I would like to know what is the best way to keep your file organise when I am
    Loading program's like numbers and pages from iPhone to MacBook i alway 
    Get double of the same work sheet

  • What is the best way to run .exe files on my mac?

    What is the best way to run .exe files on my mac? I need to run some updates for my john deere gps and the downloads i get can only be run on windows.

    There are several options for running Windows software (*.exe files) on a Mac, depending what your program is, how often you use it, and your personal preferences.
    One way that does not require Windows is an open source effort called WINE.  Check out winehq.org.  You may find that that's all you need for your programs.  There is also a commercial effort that has grown from WINE, and you will find info about it on the site mentioned.  These DO NOT require that you have and install Windows.
    If you want to run sessions devoted only to Windows software, and want programs to run as fast as they do on a PC, the Apple's Bootcamp program is useful.  With it you dedicate a partition on your hard disk to windows, and on startup choose to either boot into OS X or Windows.  Each runs without any connection to the other.  This requires you have a copy of the Windows software as well as the applications you want to run. 
    If you want to be able to easily exchange data between your Windows and Mac programs, and skip back and forth between the two, there are several emulators available that run on Mac OS X and create a Windows environment where many Windows programs can operate along side Mac programs.  Parallels and VMwear are two comercial packages available for purchase and Virtual Box is an open source effort available for free.  Google will find all three for you.
    My only experience is with Virtual Box.  It is slow and a bit clunky, but it is free and meets my needs for the very few "just got to have" windows programs I sometimes use.
    Google is your friend on this and can provide a lot more, and better, information than I can.
    Best of luck,
    Ray

  • Using the new iPad, what's the best way to watch video files (away from home) which are stored on a NAS (WD My Book Live)? Any help would be appreciated!

    Using the new iPad, what’s the best way to watch video files (away from home) which are stored on a NAS (WD My Book Live)?  Any help would be appreciated!

    Before you go, move the files to I tunes and sync them down.  There is no viable way to stream from your nas drive to the pad.

  • What's the best way to removed unwanted files?

    I have an iMac G4 running OS X 10.4.11 with 1GB of DDR SDRAM. I'm wondering what's the best way to remove unwanted files from the RAM, if it's even possible. There are apps and other files I no longer need. If I can dump the unused files will it help the computer run a little faster? Can I eliminate the unwanted files some how by myself or do I need a program that does it? Thanks

    bad dad wrote:
    I have an iMac G4 running OS X 10.4.11 with 1GB of DDR SDRAM. I'm wondering what's the best way to remove unwanted files from the RAM, if it's even possible. There are apps and other files I no longer need. If I can dump the unused files will it help the computer run a little faster? Can I eliminate the unwanted files some how by myself or do I need a program that does it? Thanks
    Applications are stored perminately on the harddrive [ Macintosh HD ]. When applications are running that is when they appear in a window, they take up RAM. You see your running applications by using activity monitor:
    Macintosh-HD -> Applications -> Utilities -> Activity Monitor
    Application when they are not running, they do not take up RAM.  You will not see any performance improvement when you delete an application from your Harddrive.  [ unless you have filled up your harddrive ]
    Best to have greater than 2gig of free space on your Harddrive.  Many posters to these forums state that you need much more free space: 5 gig to 10 gig or 10 percent of you hd size.
    Most applications do not take up much space on the Harddrive.  I copy my unused application to a folder named additional applications.
    (0)
    Be careful when deleting files. A lot of people have trashed their system when deleting things. Place things in trash. Reboot & run your applications. Empty trash.
    Go after large files that you have created & know what they are.  Do not delete small files that are in a folder you do not know what the folder is for. Anything that is less than a megabyte is a small file these days.
    (1)
    Run
    OmniDiskSweeper
    "The simple, fast way to save disk space"
    OmniDiskSweeper is now free!
    http://www.omnigroup.com/applications/omnidisksweeper/download/
    This will give you a list of files and folders sorted by size. Go after things you know that are big.
    (2)
    This will save you a gig of space.
    Monolingual is a program for removing unnecessary language resources from Mac OS X,in order to reclaim several hundred megabytes of disk space. It requires at least Mac OS X 10.3.9 (Panther) and also works on Mac OS X 10.4 (Tiger). It worked for me on 10.4
    http://monolingual.sourceforge.net/
    A detailed write-up on how to use Monolingual:
    http://www.jklstudios.com/misc/monolingual.html
    (3)
    These pages have some hints on freeing up space:
    http://thexlab.com/faqs/freeingspace.html
    http://www.macmaps.com/diskfull.html
    (4)
    Buy an external firewire harddrive.
    (5)
    Buy a flash card.

  • What is the best way to send multiple pdf files to my ipad

    what is the best way or app to send multiple pdf files to my ipad, so that I can then combine them into one folder

    I have the app Readdle Docs. It allows you to move PDF files to your device and to move them around on your device. Might check it out. ( I think there's an iPad version of the app, but I have the iPhone version and it works, just not as pretty)
    THere's also Goodreader, but I don't have experience with it to know if it has folder abilities.

  • What is the best  way to send one email for 2000+ address?

    Hi I want to send oneemail msg (only text) from mor than 2000 address.
    I want that the recp. will not c the other address (i. e. each address should be a BCC)
    what is the best way to do it? sned 2000 emails or to send 20 emails with 1000 recp. ?
    is there any limitation on the number of recp in BCC?
    10x alot Yonatan

    is there any limitation on the number of recp in BCC?
    mail server you are using may be the limiting factor. However, most mail server handle 2000 recp. You will get smtp error 552 if the mail server cant handle 2000 recipients.

  • What's the best way to send photos to a PC user?

    I'm new to the Mac world and need to know the best way to send photos to a PC user.

    Most if not all email have "Attachments" listed in the email menu.  Just click on it & follow the onscreen instructions.  Very simple. 

  • What is the best way to handle .mod files in premiere pro cs4?

    I recently got a JVC Everio GZ-MG130u and as I'm sure many of you are aware, it saves footage in the .mod format.
    I have googled this and found quite a few different solutions, but I'm just wondering if anything has changed since some of these solutions were posted, or in other words, what is the best way at this current point in time to handle .mod files in premiere pro cs4?
    As far as I know, the best thing to do is convert the .mod to .avi and then import it into premiere so it can be edited.. Is there a better way to do it than this? Also, by doing it this way, will I have separate audio and video tracks?
    Thanks.

    I have just done a bit of reading, here. All of the quotes that follow are from users who have posted in that thread.
    It seems that there isn't one solid answer on this subject. The thread that I linked to was started 2 years ago, and replied to just 4 ago, so it's relatively current.
    I noticed a couple different interesting statements:
    posted by mmontgomery:
    In the case of .MOD, you are actually getting a MPEG-2 file. The way
    video files work is that there is a codec (COmpressor/DECompressor)
    algorithm and a file wrapper (or extension). A JVC .MOD file is a
    MPEG-2 encoded file, with a .MOD extension.
    You're faced with two
    challenges, first the .MOD file type is only recognized and support by a
    few applications. I think we covered some of those already. The
    interesting thing about wrappers and extensions is that they can be
    dealt with in a variety of ways. Sometimes all you need to do to convert
    the video file to a compatible video file is to change the extension.
    In the case of .MOD files that's not enough. The .MOD wrapper apparently
    does a few more things than just bare a unique extension name. It
    requires a slightly more complicated method to convert that file. That
    is why there is supplied software and that certain third party
    applications have .MOD support.
    (posted 2 years ago)
    This seems to indicate that Ann's solution of simply re-naming the extension is not good enough, unless I am mis-interpreting what she meant.
    However, another user said:
    posted by futball8:
    I edit with Adobe Premiere Pro CS3. All I have to do is simply rename
    the .MOD files as .MPG and then import into PP CS3. It takes a small
    amount of time to conform the audio, but no file conversion is
    necessary. It's a pretty slick workflow and I've never encountered any
    problems editing them this way.
    (posted 5 months ago)
    One can only assume that simply re-naming the extension from .mod to .mpg works in some circumstances, and doesn't work in others. I assume it depends largely on the editing software being used. Perhaps there are still issues that futball8 was simply unaware of or never encountered.
    That said, there seems to be a couple of different real solutions to this problem that I have found:
    1. Simply use an editing program that supports .mod file format. While pe7 and pe8 supposedly support the .mod format, the following should be noted:
    posted by macksgarage:
    While Elements 'supports' these files, it is markedly unstable and  frequently crashes while using the files, though the application is otherwise reliable.  The solution I have arrived at is to repair the  container using ffmpeg. (see #3)
    (posted 5 months ago)
    2. Use a file conversion utility of your choice that will covert .mod to .avi, or another desired format. Import the resulting .avi file into premiere pro cs4.
    3. Use FFmpeg. This seems to be the best solution as it does not convert any audio or video:
    posted by macksgarae:
    If you are not familiar with ffmpeg, it may be a bit of a bear to
    learn, but it's not only useful for this, but functions as a video swiss
    army knife useful for splicing, muxing/demuxing, and rendering just
    about any format into just about any other format.
    ffmpeg is an open source project from the linux world, but it has
    been ported and is supported on windows.  Fetch it here and place it somewhere handy
    on your system.
    To rewrite the container into a nice, standards compliant .mpg file
    that doesn't make applications die, WITHOUT rerendering video or audio
    itself, I use this command.
    ffmpeg -i INFILE.MOD  -acodec copy - vcodec copy OUTFILE.mpg
    This not only renames the file, but actually rebuilds the container
    around unmodified video and audio data, yielding a file which works much
    more stably with Adobe applications, and presumably others as well, as
    ffmpeg's open source development goals result in very standards
    compliant files.
    (posted 5 months ago)
    Now, this seems to properly address the issues that can arise from simply renaming .mod to .mpg, as suggested by Ann. So from this point, I assume you can simply import the .mpg into Premiere Pro cs4 (or any other .mpg compliant program) and edit without issue, but it seems like I remember hearing something about Premiere not liking mpegs or something like that, so in that case, maybe it'd be better to skip this and go with option #2. But, it's been awhile since I've touched any NLE, much less premiere pro cs4, so I could be completely wrong and it may have no problems handling mpegs.
    All of the things that I've quoted here came from the same thread, so I don't know how accurate any of this is, but the people that have posted these things seem fairly knowledgeable. If someone reads all of this and can confirm or deny any of it, it would be much appreciated.
    Option 1 is not really an option for me, because I am sticking with premiere pro cs4 -- I'm not going to get another editor just because it has .mod support. That leaves me with options 2 and 3: Convert to avi, or change the file wrapper/extension properly with FFmpeg and then simply import the resulting .mpg file... Which is better? Or is there yet another solution that I am unaware of that would be even better?

  • What is the best way to make my file in FCPX Compatible for a DVD.

    I am working with a file that is about 53 minutes in length.  The video is broken up into 14 3to5 minute videos.  During my project, as I completed each video, I saved a master file and shared as APPLE PRO RES so that I wouldnt lose anything as this is my first time working with FCPX.  This made a hi-def quicktime file of each video (came out great). Now I need to put the entire project together.  My individual master files are about 4g a piece and I would imagine putting them together, will be way too large to make a dvd with.
    My question is what is the best way to put it all together and export/share? I have all of the original projects still in FCPX, do i copy and paste them into one big file? Then share, and If I share what format should i share with?  I need to take the file, throw it on a external HD and put on my laptop to create the DVD in IDVD. Needs to be decent quality for the DVD.  I have read that I can create a DVD right from FCPX, but that would be impossible as I am working on a new imac with no burner!
    ANY HELP WOULD BE GREATLY APPRECIATED!

    jpqb48 wrote:
    My question is what is the best way to put it all together and export/share? I have all of the original projects still in FCPX, do i copy and paste them into one big file? Then share, and If I share what format should i share with?
    All sounds good.
    Create a new project and paste your 14 videos (projects) sequentially into it, Perhaps insert a gap clip and put in chapter markers if you want. Share>DVD. Should create a high quality disk.
    Good luck.
    Russ

  • I want to sell my old macbook air, what is the best way to get my files and programs off of it?

    I am going to sell my macbook air (2011) as I am replacing it with a macbook pro retina. I want to remove my files and programs from it before I sell it. What is the best way to go about this?

    1) Perform a Time Machine or Cloned image backup of your system.
    2) Test the Clone tomake sure it works, by booting to it (using the option key).
    3) Boot to the Recovery Partition, then perform an erasure, followed by a reinstallation of the OS.
    4) Shut off the Mac, after instllation and before the reboot. This will permit the next user to experience a "fresh out of the box" experience.
    5) Use the Time Machine or Cloned image to migrate your apps, users & files to your new system, using SETUP ASSISTANT. Do not use Migration Assistant.

Maybe you are looking for

  • Sale order bom can be used in to process order or not

    To change the BOM for particular order items the sale order BOM can be created , to copy the sale order BOM into production order CO08 can be used , whether the process order can be created with ref to sale order any option is available is SAP

  • Enum confusion! Logical or in an if statement

    I'm using enums for the first time and I'm a bit confused. I have: if (type != (Board.PIT | Board.NORMAL | Board.PAIR | Board.ROT | Board.UNDER                    Board.NORTH | Board.EAST | Board.SOUTH | Board.WEST) )          isUpper = true;     Ecl

  • Process Chains Greyed in QA

    HI ,         I have transported my process chains from my Dev to QA, they are all active in Dev and they dont display in QA, but the name of the process chains still appear under the root "Not assigned", And all my Transports were also good, This is

  • 30EA1: Determine column lengths before csv-Import

    Hello out there, I tried to import a csv (actually semicolon separated and enclosed in double quotes) into a new table using SQL Developer. I got error messages that some columns are to short (ORA-12899). Now the question is, is there an option havin

  • Editing more than 4 clips using the multi-cam function. cs5.5

    How can I edit more than 4 clips at a time using the multi-cam function in 5.5?