, - . , . http- . DB.
, :
public interface ImageProvider {
public void storeImage(MyImageClass image, String imageLable);
public MyImageClass getImage(String imageLable);
}
.
, :
public class ImageJarProvider implements ImageProvider {
private File jar = null;
public ImageJarProvider(File jar) {
this.jar = jar;
}
public void storeImage(MyImageClass image, String imageLable) {
JarFile jarFile = new JarFile(jar);
ZipEntry inputEntry = jarFile.getEntry("path/you/need/to/file");
File outFile = new File("temp.jar");
FileOutputStream zipFileStream = new FileOutputStream(outfile);
ZipOutputStream zipOutStream = new ZipOutputStream(new BufferedOutputStream(zipFileStream));
ZipEntry entry = new ZipEntry("filename you pack");
zipOutStream.putNextEntry(entry);
BufferedInputStream origin = new BufferedInputStream(new jarFile.getInputStream(inputEntry));
byte data[] = new byte[2048];
int count = 0;
while((count = origin.read(data, 0, data.length)) != -1) {
zipOutStream.write(data, 0, count);
}
zipOutStream.close();
origin.close();
}
public MyImageClass getImage(String imageLable) {
...
}
}
public class ImageHttpProvider implements ImageProvider {
public ImageHttpProvider(String host, int port) {
...
}
public void storeImage(MyImageClass image, String imageLable) {
...
}
public MyImageClass getImage(String imageLable) {
...
}
}
public class ImageDirProvider implements ImageProvider {
public ImageDirProvider(File dir) {
...
}
public void storeImage(MyImageClass image, String imageLable) {
...
}
public MyImageClass getImage(String imageLable) {
...
}
}
public class ImageDBProvider implements ImageProvider {
public ImageDBProvider(String jdbcURL, Properties jdbcProperties) {
...
}
public void storeImage(MyImageClass image, String imageLable) {
...
}
public MyImageClass getImage(String imageLable) {
...
}
}
.
, , .