Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: InputStream Problem at Client Side

  1. #1
    Junior Member
    Join Date
    Mar 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default InputStream Problem at Client Side

    Hi all once again, one more question from me. But this one stands between me and my final work. I am doing a REST Webservice, in which I have to send image files from the server and had to calculate processing times at the client. So, I choosen InputStream at the server, and same to catch at the Client. Seems some basic problem, I am measuring time before and after InputStream at Client..seems since its a stream as soon as receiving some bytes the program was coming to the next....better to put it in code... REST Web Service and i am using Netbeans 6.8

    Server COde

     
    @Path("/restserver/image23")
    public class imagetest23 {
        @Context
        private UriInfo context;
     
        /** Creates a new instance of imagetest1 */
        public imagetest23() {
        }
     
     
      @GET
     @Path("{id}")
    //@Produces ("StreamingOutput/text")
     
    public InputStream GettheFile(@PathParam ("id") String cId) throws Exception
     
     
     
        {
     
     
          File file =  new File("C:/"+cId+".png");
         InputStream in = null;
     
          //File file =  new File("C:/fone.gif");
          FileInputStream fs = new FileInputStream(file);
            //   int cid=01;
    in = new BufferedInputStream(new FileInputStream(file));
     
            return in;
     
     
     
     
        }
    }

    And at the Client Side

     
    private static void testgettingfiles() throws IOException, WebApplicationException, HttpException, java.sql.SQLException,java.lang.ClassNotFoundException, com.sun.jersey.api.client.UniformInterfaceException {
     
    System.out.println("coming to here, start of the getmethod in client");
     
     
                final String BASE_URI = "http://xxxxx:8080/RestApplication-Server/resources";
               System.out.println("the value of string"+BASE_URI);
                System.out.println("coming to here before start of client");
        Client c = Client.create();
        WebResource service = c.resource(BASE_URI);
     
        System.out.println("coming to here after baseuri");
        System.out.println("the time before fetching starts:");
    long g= System.currentTimeMillis();
     
     
    InputStream in=service.path("/restserver/image12").get(InputStream.class);
     
    long f=System.currentTimeMillis();
     
    System.out.println("the total time :"+(f-g));
     
    }

    So thats the problem ..no matter the size of the image files (trying from 5 mb to 50mb) the processing time is just few milli seconds and almost the same..


    tried a bit logic to convert the files

     
    BufferedImage bi1 = ImageIO.read(in);
    System.out.println("the time after fetching");
    long f=System.currentTimeMillis();
    File file = new File("newimage1.png");//(dint changed)changing to .gif
    ImageIO.write(bi1, "png", file);//(dint changed)changing to .gif
     FileInputStream fs = new FileInputStream(file);

    But getting different size files...and if i take the time here, it also includes conversion and saving file locally times....Since its REST and i test with a plane url and its returning same files size ( tried right click and save as )...

    Thanks in advance guys,...spent whole night on this..


  2. #2
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: InputStream Problem at Client Side

    Well the time spent between creating g and f is only creating the inputstream, its not actually loading/sending any data, your simply saying create me an inputstream to the following file. Java will do that in a couple of milliseconds or less.

    What kind of processing are you supposed to be calculating?

    // Json

Similar Threads

  1. RMI over SSL Client application
    By boilerchicken in forum Java Networking
    Replies: 0
    Last Post: November 10th, 2009, 07:52 AM
  2. Validate in server side..
    By Ganezan in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 27th, 2009, 07:36 AM
  3. Java program to open jsp page on client side instead of server side
    By khanshakil in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: July 8th, 2009, 07:26 AM
  4. [SOLVED] web client
    By 5723 in forum File I/O & Other I/O Streams
    Replies: 8
    Last Post: June 10th, 2009, 05:44 PM
  5. How to write switch statement inside if statement?
    By Rezz in forum Loops & Control Statements
    Replies: 6
    Last Post: June 11th, 2008, 12:27 PM