Methods Summary |
---|
public javax.mail.internet.MimeMultipart | getAllImages()Gets the book images in MimeMultipart form
String[] titles = EBookServiceServantData.getBookTitles();
Image[] images = getImages(titles, false);
try {
MimeMultipart mp = new MimeMultipart();
for (int i = 0; i < images.length; i++) {
MimeBodyPart mbp = new MimeBodyPart();
mbp.setContent(images[i], "image/jpeg");
mbp.addHeader("Content-Type", "image/jpeg");
mp.addBodyPart(mbp);
}
return mp;
} catch (MessagingException ex) {
throw new EBookServiceException("Failed building MimeMultipart: " + ex.getMessage());
}
|
public int | getBookCount()Gets the number of books known to the service
String[] titles = EBookServiceServantData.getBookTitles();
return titles == null ? 0 : titles.length;
|
public javax.xml.transform.Source[] | getBookDetails(java.lang.String[] titles)Gets XML details for a given list of books.
int length = titles.length;
Source[] sources = new Source[length];
for (int i = 0; i < length; i++) {
String data = EBookServiceServantData.getXMLDetails(titles[i]);
if (data == null) {
throw new EBookServiceException("Unknown title: [" + titles[i] + "]");
}
try {
data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + data;
sources[i] = new StreamSource(new ByteArrayInputStream(data.getBytes("utf-8")));
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
}
}
return sources;
|
public java.lang.String[] | getBookTitles()Gets the set of book titles.
return EBookServiceServantData.getBookTitles();
|
public javax.activation.DataHandler[] | getImageHandlers(java.lang.String[] titles, boolean gif)Gets book images in the form of a DataHandler
int length = titles.length;
DataHandler[] handlers = new DataHandler[length];
for (int i = 0; i < length; i++) {
byte[] imageData = EBookServiceServantData.getImageData(titles[i], gif);
if (imageData == null) {
throw new EBookServiceException("Unknown title: [" + titles[i] + "]");
}
handlers[i] = new DataHandler(new ByteArrayDataSource("Image Data",
imageData,
gif ? "image/gif" : "image/jpeg"));
}
return handlers;
|
public java.awt.Image[] | getImages(java.lang.String[] titles, boolean gif)Gets the images for a books with given titles
int length = titles.length;
Image[] images = new Image[length];
for (int i = 0; i < length; i++) {
byte[] imageData = EBookServiceServantData.getImageData(titles[i], gif);
if (imageData == null) {
throw new EBookServiceException("Unknown title: [" + titles[i] + "]");
}
if (tracker == null) {
tracker = new MediaTracker(new Component() {});
}
Image image = Toolkit.getDefaultToolkit().createImage(imageData);
tracker.addImage(image, 0);
images[i] = image;
}
try {
tracker.waitForAll();
for (int i = 0; i < length; i++) {
tracker.removeImage(images[i]);
}
} catch (InterruptedException ex) {
}
return images;
|