readLine() for a gzip file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Phil

    readLine() for a gzip file

    At present I use the following to read a text file
    ...
    private BufferedReader in = null;
    ...
    try {
    in = new BufferedReader( new FileReader(File name));
    while((line = in.readLine()) != null) {
    // work
    }

    I would like to gzip the input file, how do I change my code
    to read a gzipped text file? From the Sun tutorial I only saw
    how to read a given number of bytes, but I want to read lines.

    Any help appreciated.
    tnx, Phil...
  • dfdfd

    #2
    Re: readLine() for a gzip file

    How in the hell are you going to read lines from a zipped file? what the
    hell
    is wrong with this news group, are all you people smoking crack or what?
    I've never seen such an endless stream of absolutely dumbass questions
    as those that for some reason or another end up being defecated onto
    this group.

    Angry post to follow.
    "Phil" <rynes@ieee.org > wrote in message
    news:lczZa.8041 7$Oz4.20213@rwc rnsc54...
    At present I use the following to read a text file
    ...
    private BufferedReader in = null;
    ...
    try {
    in = new BufferedReader( new FileReader(File name));
    while((line = in.readLine()) != null) {
    // work
    }

    I would like to gzip the input file, how do I change my code
    to read a gzipped text file? From the Sun tutorial I only saw
    how to read a given number of bytes, but I want to read lines.

    Any help appreciated.
    tnx, Phil...


    Comment

    • Phil

      #3
      Re: readLine() for a gzip file

      The class GZIPInputStream in the package java.util.zip
      is supposed to do the decompression for you automatically.
      I just want to read it line by line instead of a buffer of bytes.

      "dfdfd" <dfdf@aol.com > wrote in message news:DpzZa.1228 3$ug.11789@lake read01...[color=blue]
      > How in the hell are you going to read lines from a zipped file? what the
      > hell
      > is wrong with this news group, are all you people smoking crack or what?
      > I've never seen such an endless stream of absolutely dumbass questions
      > as those that for some reason or another end up being defecated onto
      > this group.
      >
      > Angry post to follow.
      > "Phil" <rynes@ieee.org > wrote in message
      > news:lczZa.8041 7$Oz4.20213@rwc rnsc54...
      > At present I use the following to read a text file
      > ...
      > private BufferedReader in = null;
      > ...
      > try {
      > in = new BufferedReader( new FileReader(File name));
      > while((line = in.readLine()) != null) {
      > // work
      > }
      >
      > I would like to gzip the input file, how do I change my code
      > to read a gzipped text file? From the Sun tutorial I only saw
      > how to read a given number of bytes, but I want to read lines.
      >
      > Any help appreciated.
      > tnx, Phil...
      >
      >[/color]

      Comment

      • Pedro Sam

        #4
        Re: readLine() for a gzip file

        Phil <rynes@ieee.org > wrote:[color=blue]
        > The class GZIPInputStream in the package java.util.zip
        > is supposed to do the decompression for you automatically.
        > I just want to read it line by line instead of a buffer of bytes.[/color]

        whoa... since we are in Java land... Let's get the terms right. There's
        a difference between bytes and characters. When you use Reader/Writer,
        you're dealing with characters, and when you use InputStream and
        OutputStream, you're dealing with bytes.

        I presume you mean characters and not bytes. You probably want to wrap
        the the FileReader with

        [angry stuff snipped]

        As you have noticed there's no gzip reader, but you do have gzip
        inputstream. One can cross from the world of inputstream to the reader
        world by using the InputStreamRead er. Here's what I'd do:

        BufferedReader reader = new BufferedReader(
        new InputStreamRead er(
        new GZIPInputStream (
        new FileInputStream ( filename.gz ) ) ) );

        You may run into problems if you're dealing with multi byte characters
        ....

        Pedro

        [color=blue][color=green]
        >> "Phil" <rynes@ieee.org > wrote in message
        >> news:lczZa.8041 7$Oz4.20213@rwc rnsc54...
        >> At present I use the following to read a text file
        >> ...
        >> private BufferedReader in = null;
        >> ...
        >> try {
        >> in = new BufferedReader( new FileReader(File name));
        >> while((line = in.readLine()) != null) {
        >> // work
        >> }
        >>
        >> I would like to gzip the input file, how do I change my code
        >> to read a gzipped text file? From the Sun tutorial I only saw
        >> how to read a given number of bytes, but I want to read lines.[/color][/color]


        --
        Caution: breathing may be hazardous to your health.

        Comment

        • Phil

          #5
          Re: readLine() for a gzip file

          Pedro,
          Thanks a bunch, I tried your suggestion exactly and it worked the first time!!!
          Phil...

          "Pedro Sam" <p2sam@uwaterlo o.ca> wrote in message news:bh6kqd$p3u $1@tabloid.uwat erloo.ca...[color=blue]
          > Phil <rynes@ieee.org > wrote:[color=green]
          > > The class GZIPInputStream in the package java.util.zip
          > > is supposed to do the decompression for you automatically.
          > > I just want to read it line by line instead of a buffer of bytes.[/color]
          >
          > whoa... since we are in Java land... Let's get the terms right. There's
          > a difference between bytes and characters. When you use Reader/Writer,
          > you're dealing with characters, and when you use InputStream and
          > OutputStream, you're dealing with bytes.
          >
          > I presume you mean characters and not bytes. You probably want to wrap
          > the the FileReader with
          >
          > [angry stuff snipped]
          >
          > As you have noticed there's no gzip reader, but you do have gzip
          > inputstream. One can cross from the world of inputstream to the reader
          > world by using the InputStreamRead er. Here's what I'd do:
          >
          > BufferedReader reader = new BufferedReader(
          > new InputStreamRead er(
          > new GZIPInputStream (
          > new FileInputStream ( filename.gz ) ) ) );
          >
          > You may run into problems if you're dealing with multi byte characters
          > ...
          >
          > Pedro
          >
          > [color=green][color=darkred]
          > >> "Phil" <rynes@ieee.org > wrote in message
          > >> news:lczZa.8041 7$Oz4.20213@rwc rnsc54...
          > >> At present I use the following to read a text file
          > >> ...
          > >> private BufferedReader in = null;
          > >> ...
          > >> try {
          > >> in = new BufferedReader( new FileReader(File name));
          > >> while((line = in.readLine()) != null) {
          > >> // work
          > >> }
          > >>
          > >> I would like to gzip the input file, how do I change my code
          > >> to read a gzipped text file? From the Sun tutorial I only saw
          > >> how to read a given number of bytes, but I want to read lines.[/color][/color]
          >
          >
          > --
          > Caution: breathing may be hazardous to your health.[/color]

          Comment

          Working...