use of de.janrufmonitor.util.io.Base64Decoder in project janrufmonitor by tbrandt77.
the class XMLCallerHandler method endElement.
public void endElement(String uri, String name, String qname) throws SAXException {
if (qname.equalsIgnoreCase(TAG_CALLER) && this.m_image_content != null && this.m_caller != null && this.m_caller.getAttributes().contains(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH)) {
String file = this.m_caller.getAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH).getValue();
if (file != null && file.length() > 0) {
// check for File.separator
if (File.separator.equalsIgnoreCase("/")) {
file = StringUtils.replaceString(file, "\\", File.separator);
}
File f = new File(PathResolver.getInstance().resolve(file));
File image = new File(getCentralImageStorePath(), f.getName());
ByteArrayInputStream encodedIn = new ByteArrayInputStream(this.m_image_content.getBytes());
Base64Decoder b64 = new Base64Decoder(encodedIn);
try {
FileOutputStream decodedOut = new FileOutputStream(image);
Stream.copy(b64, decodedOut);
b64.close();
decodedOut.close();
} catch (FileNotFoundException e) {
} catch (IOException e) {
}
this.m_caller.setAttribute(getRuntime().getCallerFactory().createAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEPATH, image.getAbsolutePath()));
this.m_image_content = null;
}
}
if (this.m_multi && qname.equalsIgnoreCase(TAG_CALLER)) {
this.m_callerList.add(this.m_caller);
List phns = new ArrayList();
this.m_caller = this.getRuntime().getCallerFactory().createCaller(this.getRuntime().getCallerFactory().createName("", ""), phns);
this.m_caller.getPhonenumbers().clear();
}
}
use of de.janrufmonitor.util.io.Base64Decoder in project janrufmonitor by tbrandt77.
the class VcfParser30 method getImageFromBase64.
private String getImageFromBase64(String base64Image, String type) {
try {
ByteArrayInputStream encodedIn = new ByteArrayInputStream(base64Image.getBytes());
Base64Decoder b64 = new Base64Decoder(encodedIn);
ByteArrayOutputStream decodedOut = new ByteArrayOutputStream();
Stream.copy(b64, decodedOut);
b64.close();
decodedOut.close();
ByteArrayInputStream decodedIn = new ByteArrayInputStream(decodedOut.toByteArray());
return this.createImage(decodedIn, (new UUID().toString() + "." + type));
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
return null;
}
use of de.janrufmonitor.util.io.Base64Decoder in project janrufmonitor by tbrandt77.
the class TamMessagePlay method run.
public void run() {
Viewer v = this.m_app.getApplication().getViewer();
if (v != null) {
IStructuredSelection selection = (IStructuredSelection) v.getSelection();
if (!selection.isEmpty()) {
Object o = selection.getFirstElement();
if (o instanceof ICall) {
if (((ICall) o).getAttributes().contains("fritzbox.tamurl")) {
File message_file = null;
String url = ((ICall) o).getAttributes().get("fritzbox.tamurl").getValue();
File tamMessageDir = new File(PathResolver.getInstance(PIMRuntime.getInstance()).getDataDirectory() + File.separator + "fritzbox-messages");
tamMessageDir.mkdirs();
if (tamMessageDir.exists() && tamMessageDir.isDirectory()) {
message_file = new File(tamMessageDir, ((ICall) o).getUUID() + ".wav");
if (!message_file.exists()) {
FirmwareManager fwm = FirmwareManager.getInstance();
try {
if (!fwm.isLoggedIn())
fwm.login();
String data = fwm.getTamMessage(url);
if (data == null)
return;
ByteArrayInputStream bin = new ByteArrayInputStream(data.getBytes());
Base64Decoder b64 = new Base64Decoder(bin);
FileOutputStream fos = new FileOutputStream(message_file);
Stream.copy(b64, fos);
fos.flush();
fos.close();
} catch (IOException e) {
this.m_logger.warning(e.toString());
} catch (FritzBoxLoginException e) {
this.m_logger.warning(e.toString());
}
}
}
try {
AudioInputStream stream = AudioSystem.getAudioInputStream(message_file);
AudioFormat format = stream.getFormat();
DataLine.Info info = new DataLine.Info(Clip.class, format);
Clip clip = (Clip) AudioSystem.getLine(info);
clip.open(stream);
clip.start();
} catch (IOException e) {
this.m_logger.severe(e.getMessage());
} catch (LineUnavailableException e) {
this.m_logger.severe(e.getMessage());
} catch (UnsupportedAudioFileException e) {
this.m_logger.severe(e.getMessage());
}
} else {
new SWTExecuter() {
protected void execute() {
int style = SWT.APPLICATION_MODAL | SWT.OK;
MessageBox messageBox = new MessageBox(new Shell(DisplayManager.getDefaultDisplay()), style);
messageBox.setMessage(getI18nManager().getString(getNamespace(), "notam", "label", getLanguage()));
messageBox.open();
}
}.start();
return;
}
}
}
}
}
use of de.janrufmonitor.util.io.Base64Decoder in project janrufmonitor by tbrandt77.
the class CompressBase64 method decompressBase64Decode.
public static synchronized byte[] decompressBase64Decode(byte[] encoded) throws IOException {
// create a base64 decoded string
ByteArrayInputStream encodedIn = new ByteArrayInputStream(encoded);
Base64Decoder b64 = new Base64Decoder(encodedIn);
ByteArrayOutputStream decodedOut = new ByteArrayOutputStream();
transform(b64, decodedOut);
b64.close();
decodedOut.close();
// System.out.println(decodedOut.toString());
ByteArrayInputStream decodedIn = new ByteArrayInputStream(decodedOut.toByteArray());
ZipInputStream zippedIn = new ZipInputStream(new BufferedInputStream(decodedIn));
ZipEntry entry = zippedIn.getNextEntry();
if (entry != null) {
if (entry.getName().equalsIgnoreCase("data") && !entry.isDirectory()) {
byte[] decoded = toByteArray(zippedIn);
zippedIn.closeEntry();
zippedIn.close();
return decoded;
}
}
return new byte[] {};
}
use of de.janrufmonitor.util.io.Base64Decoder in project janrufmonitor by tbrandt77.
the class HsqldbMultiPhoneCallerDatabaseHandler method internalGetImageData.
private InputStream internalGetImageData(ICaller c) throws SQLException {
IAttribute img_ref = c.getAttribute(IJAMConst.ATTRIBUTE_NAME_IMAGEREF);
if (img_ref != null && img_ref.getValue().length() > 0) {
PreparedStatement ps = this.getStatement("SELECT_IMAGE");
ps.setString(1, img_ref.getValue());
ResultSet rs = ps.executeQuery();
String imgdata = null;
while (rs.next()) {
imgdata = rs.getString("value");
}
try {
ByteArrayInputStream encodedIn = new ByteArrayInputStream(imgdata.getBytes());
Base64Decoder b64 = new Base64Decoder(encodedIn);
ByteArrayOutputStream decodedOut = new ByteArrayOutputStream();
Stream.copy(b64, decodedOut);
b64.close();
decodedOut.close();
return new ByteArrayInputStream(decodedOut.toByteArray());
} catch (IOException e) {
this.m_logger.log(Level.SEVERE, e.getMessage(), e);
}
}
return null;
}
Aggregations