Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Contributor
vishal_trivedi
Posts: 12
Registered: ‎06-22-2012
My Device: developer
My Carrier: Vodafone

UnZipping Using ZipMe

 

 

I have a zip file containing a folder and inside the folder I have some image file.I wish to extract these images.However I have not been able to find anything.I have been looking at zipMe but have not been able to find any relevant help.

Below is the code that I have developed so far.

 



ZipEntry dataZE;
InputStream isData;
StringBuffer sbData;
ZipInputStream dataZIS;

String src="file:///store/home/user/images.zip";
String path = "file:///store/home/";
String fileName = "";
FileConnection f_Conn;

 

public UnZipper() {

debugger("Unzipper constructor");

try {
f_Conn = (FileConnection) Connector.open(src);
} catch (IOException e) {
debugger("f_conn error :" + e.getMessage());
}

try {
isData = f_Conn.openInputStream();
} catch (IOException e) {
debugger("f_conn error getting ip_stream:" + e.getMessage());
}

sbData = new StringBuffer();

dataZIS = new ZipInputStream(isData);

debugger("got all thing initialized");

}

 

public void run() {

debugger("unzipper run");

try {
startUnziping();
} catch (IOException e) {

debugger("Error unzipping " + e.getMessage());
}

debugger("finished...");

}


private void startUnziping() throws IOException {

debugger("startUnziping");
dataZE = dataZIS.getNextEntry();
fileName = dataZE.getName();
writeFile();
dataZIS.closeEntry();

debugger(">>>>>>>>>>> : " + fileName);
}

private void readFile() throws IOException {

debugger("readFile");
int ch;
int i = 0;
while ((ch = dataZIS.read()) != -1) {

debugger((i++) + " : " + sbData.toString()
+ " >>> writting this..");
sbData.append(ch);
}

}

 

private void writeFile() {

debugger("writting file...");
FileConnection f_Conn = null;
byte[] file_bytes = new byte[sbData.length()];
file_bytes = sbData.toString().getBytes();

try {
readFile();
} catch (IOException e) {
debugger("Error while reading " + e.getMessage());
}

try {
f_Conn = (FileConnection) Connector.open(path + fileName);
} catch (IOException e) {
debugger("getting f_conn" + e.getMessage());
}

if (!f_Conn.exists()) {
// create the file first
debugger("I know file does not exists");
try {
f_Conn.mkdir();
} catch (IOException e) {
debugger("Oops!!! error creating fle : " + e.getMessage());
}
}
try {
f_Conn.setWritable(true);
debugger("file is nt writeable");
} catch (IOException e) {
debugger("cannot make it writeable : " + e.getMessage());
}
OutputStream lo_OS = null;
try {
lo_OS = f_Conn.openOutputStream();
debugger("got out Stream hero!!!");
} catch (IOException e) {
debugger("cant get out Stream !!!");
}
try {
lo_OS.write(file_bytes);
debugger("yess...writtent everything");
} catch (IOException e) {
add(new LabelField("Error writing file ..." + e.getMessage()));
}
try {
lo_OS.close();
debugger("now closing connection...");
} catch (IOException e) {
debugger("error closing out stream : " + e.getMessage());
}

}
}

 



I have been able to get ZipEntry representing folder that contains images however I have not been able to figure out how i must extract those images.

Thanks for help.

Please use plain text.
Developer
simon_hain
Posts: 15,947
Registered: ‎07-29-2008
My Device: Z10 LE
My Carrier: O2 Germany

Re: UnZipping Using ZipMe

check this thread:
http://supportforums.blackberry.com/t5/Java-Development/Searching-a-way-to-manipulate-7-zip-zip-and-...

(the search is often helpful)
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
Contributor
vishal_trivedi
Posts: 12
Registered: ‎06-22-2012
My Device: developer
My Carrier: Vodafone

Re: UnZipping Using ZipMe

thanks for suggestion but i was having a look at it before and wasnt able to find jar for it.
And besides i have already spent a lot of time (facing time crisis) and dont want to start again :smileysad:
Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: UnZipping Using ZipMe

I presume you followed SImons link and found this?

 

http://supportforums.blackberry.com/t5/Java-Development/Unzip-zip-archive-with-sample-resource-insta...

 

There is sample unzip code included in there.  And the code will run significantly faster than ZIP Me.  Finally let me warn you that I could not get ZipMe to unzip large files, small were fine, large just failed.

 

Good luck. 

Please use plain text.