Note that there are some explanatory texts on larger screens.

plurals
  1. POProcessing a BZIP string/file in Scala
    primarykey
    data
    text
    <p>I'm punishing myself a bit by doing the python challenges series in Scala.</p> <p>Now, one of the challenges is to read in a string that's been compressed using the bzip algorithm and output the result.</p> <pre><code>BZh91AY&amp;SYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M\x07&lt;]\xc9\x14\xe1BA\x06\xbe\x084 </code></pre> <p>Now, after some digging it appears as if there isn't a standard java library for bzip processing, but there is something in the apache ant project, <a href="http://www.kohsuke.org/bzip2/" rel="nofollow">that this guy</a> has kindly taken out for use as a separate library.</p> <p>The thing is, I can't seem to get it to work with the following code, it just hangs in the scala REPL and the JVM maxes out at 100% CPU usage</p> <p>This is the code I'm trying...</p> <pre><code>import java.io.{ByteArrayInputStream} import org.apache.tools.bzip2.{CBZip2InputStream} import org.apache.commons.io.{IOUtils} object ChallengeEight extends Application { val inputString = """BZh91AY&amp;SYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!\x9ah3M\x07&lt;]\xc9\x14\xe1BA\x06\xbe\x084""" val inputStream = new ByteArrayInputStream( inputString.getBytes("UTF-8") ) //convert string to inputstream inputStream.skip(2) //skip the 'BZ' part at the start val bzipInputStream = new CBZip2InputStream(inputStream) //hangs here.... val result = IOUtils.toString(bzipInputStream, "UTF-8"); println(result) } </code></pre> <p>Anyone got any ideas? Or is the <code>CBZip2InputStream</code> class expecting some extra bytes that you might find in a file that has been zipped with <code>bzip2</code>?</p> <p>Any help would be appreciated</p> <p><strong>EDIT</strong> For the record this is the python solution</p> <pre><code>import bz2 un = "BZh91AY&amp;SYA\xaf\x82\r\x00\x00\x01\x01\x80\x02\xc0\x02\x00 \x00!" \ "\x9ah3M\x07&lt;]\xc9\x14\xe1BA\x06\xbe\x084" print [bz2.decompress(elt) for elt in (un)] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload