Lawrance Miao

Greenhorn
+ Follow
since Jan 24, 2005
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Lawrance Miao

Thanks, Joe Ess. I think I'd be better to read that article carefully.
18 years ago
First, thanks Joe Ess. That article is very impressing.

But, that is not the solution I think. Because the inputstream is a little different from that one. I've successed to copy one jpg to another one if the jpg image is not in the zip file.

I've found the solution when I'm idling in the JDK docs:

import java.io.*;
import java.util.*;
import java.util.zip.*;
import com.sun.image.codec.jpeg.*; //solution.
import java.awt.image.*;

public class TestZipImage
{
public static void main(String args[])
{
try{
ZipInputStream zin =
new ZipInputStream(new FileInputStream("t10001.zip"));
ZipEntry entry;
while ((entry = zin.getNextEntry()) != null)
{
if (entry.getName().contains("t10001.jpg"))
{
String fileName = entry.getName();
FileOutputStream out = new FileOutputStream("copy_t10001.jpg");
//--Work Code------------------------------------------------------
JPEGImageDecoder jpgDec = JPEGCodec.createJPEGDecoder(zin);
BufferedImage bimage = jpgDec.decodeAsBufferedImage();
JPEGImageEncoder jpgEnd = JPEGCodec.createJPEGEncoder(out);
jpgEnd.encode(bimage);
out.flush();
//---Work Code---------------------------------------------------

//---Not Work Code-----------------------------------------------
// byte[] b = new byte[(int)entry.getSize() * 10];
// zin.read(b);
// out.write(b);
//---Not Work Code-----------------------------------------------

out.close();
}
zin.closeEntry();
}
zin.close();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}

I think the reason is the format of the extracting of jpg files.
18 years ago
Hi all
Today I tried to use ZipInputStream and ZipOutputStream to write a program like Winzip. But when I decompressed a .jpg file from the zip file into a common file, the problem appeared. The image file is totally changed.

My method is:

zin = new ZipInputStream(new FileInputStream(zipFileName));
while ((entry = zin.getNextEntry()) != null)
{
if (entry.getName().contains("hello.jpg"))
{
String fileName = entry.getName();
FileOutputStream out = new FileOutputStream("helloCopy.jpg");
byte[] b = new byte[(int)entry.getSize()];
zin.read(b);
out.write(b);
out.close();
}
zin.closeEntry();
}
zin.close();

This method was almost right when I used other kind of file formats not including images. I really puzzled!!

Is there any solutions??
18 years ago
Try a whole afternoon, but fail.
18 years ago
To Norm Radder :
When the dll file is in the Jar file, what is the dll file's conventional path of the local operation system? My platform is WinXP
18 years ago
Hi all

These days my project need to use JNI to call MS sound dll to make some words sound. The project works well until I put them all in a jar file. My question is does there exist anyway to put a .dll file into a jar, and let the System.load(String) or System.loadLibrary(String) methods to find it??

I've tried lots of ways tonight, and nearly to be crazy now. There're some methods I've used:
1. Use class.getResource to get the URL and from the URL's toString method get the "file:/Dir" string. Pass this string to loadLibrary method.
Failed from the outside, not to talk about jar.
URL s= PlayerHelper.class.getResource("com_c3_gisk_PlayerHelper.dll");
String str = s.toString();
System.load(str);

2. Delete the "str" in the method one, replace the "file:/" string to an empty string "". Still use load(str). This time it works well in the outside. But when put it in the jar file, failed.

3. Use System.loadLibrary("com_c3_gisk_PlayerHelper") to use the relative location. Success in the outside, but failed in the Jar file.

The main reason is if we use the getResource() in the jar file, the URL's toString method will return the string like the following:
"jar:file:/C:/test.jar!/com_c3_gisk_PlayerHelper.dll".

Help me!
18 years ago
thx ram . I think I get it.
static methods in class Thread like sleep(), currentThread(),when we write them in our code, they could know the running thread object. How ??
Why a static method can access an object of its own class ??