-
January 2nd, 2009, 12:28 PM
#1
RARInputStream?
Hi
I need to create a RARInputStream, from a rar file, but i havnt really had any luck finding something that did the trick, does some of you know any librarys that could be usefull to me? Or if not, how could i make it myself?
I suppose i could translate a c++ rar library file to java, and extending DataInputStream or something, but i dont really know, would be nice with some advice
-
January 2nd, 2009, 03:08 PM
#2
Re: RARInputStream?
ok, i found something called JunRar which seems to be quite useful, although there is little documentary available, so its not very easy to implement. I have come to a solution like this:
Code:
private void playRARStream()
{
try
{
byte[] readData = new byte[1024];
ReadOnlyAccessFile roaf = new ReadOnlyAccessFile(new File(CoverView.selectedMovieDir + CoverView.selectedMovie));
long start = 0;
long end = 150000000;
BufferedInputStream bis = new BufferedInputStream(new ReadOnlyAccessInputStream(roaf, start, end));
FileOutputStream fos = new FileOutputStream(CoverView.selectedMovieDir + "fos");
int i = bis.read(readData);
System.out.println(CoverView.selectedMovieDir + CoverView.selectedMovie);
Process process = Runtime.getRuntime().exec(new String[] { MovieDBOptions.playMovieCmd, "fos" }, null, new File(CoverView.selectedMovieDir));
while(i != -1)
{
try
{
if(process.exitValue() == 0)
{
break;
}
}
catch(Exception e)
{}
fos.write(readData, 0, i);
i = bis.read(readData);
}
bis.close();
fos.close();
try
{
if(process.exitValue() == 0)
{
(new File(CoverView.selectedMovieDir + "fos")).delete();
}
}
catch(Exception e)
{}
}
catch(Exception e)
{
System.err.println("Unable to play `" + CoverView.selectedMovie + "` with command `" + MovieDBOptions.playMovieCmd + "`");
System.err.println(e);
}
}
NOTE: Its mainly this part which is interesting:
Code:
BufferedInputStream bis = new BufferedInputStream(new ReadOnlyAccessInputStream(roaf, start, end));
FileOutputStream fos = new FileOutputStream(CoverView.selectedMovieDir + "fos");
int i = bis.read(readData);
but my stream doesnt work, as in if i play the `fos` file in vlc i just get an error saying it cannot determine the format, however it works for GZIP archives, with just some minor changes:
Code:
private void playGZStream()
{
try
{
byte[] readData = new byte[1024];
BufferedInputStream bis = new BufferedInputStream(new GZIPInputStream(new FileInputStream(CoverView.selectedMovieDir + CoverView.selectedMovie)));
FileOutputStream fos = new FileOutputStream(CoverView.selectedMovieDir + "fos");
int i = bis.read(readData);
System.out.println(CoverView.selectedMovieDir + CoverView.selectedMovie);
Process process = Runtime.getRuntime().exec(new String[] { MovieDBOptions.playMovieCmd, "fos" }, null, new File(CoverView.selectedMovieDir));
while(i != -1)
{
try
{
if(process.exitValue() == 0)
{
break;
}
}
catch(Exception e)
{}
fos.write(readData, 0, i);
i = bis.read(readData);
}
bis.close();
fos.close();
try
{
if(process.exitValue() == 0)
{
(new File(CoverView.selectedMovieDir + "fos")).delete();
}
}
catch(Exception e)
{}
}
catch(Exception e)
{
System.err.println("Unable to play `" + CoverView.selectedMovie + "` with command `" + MovieDBOptions.playMovieCmd + "`");
System.err.println(e);
}
}
Anyone who can point me in the right direction?
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|