Search in sources :

Example 1 with Base64Decoder

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();
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Base64Decoder(de.janrufmonitor.util.io.Base64Decoder) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) ICallerList(de.janrufmonitor.framework.ICallerList) List(java.util.List) IOException(java.io.IOException) File(java.io.File)

Example 2 with Base64Decoder

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Base64Decoder(de.janrufmonitor.util.io.Base64Decoder) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) UUID(de.janrufmonitor.util.uuid.UUID)

Example 3 with Base64Decoder

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;
                }
            }
        }
    }
}
Also used : FritzBoxLoginException(de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException) ICall(de.janrufmonitor.framework.ICall) DataLine(javax.sound.sampled.DataLine) LineUnavailableException(javax.sound.sampled.LineUnavailableException) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) MessageBox(org.eclipse.swt.widgets.MessageBox) AudioInputStream(javax.sound.sampled.AudioInputStream) Clip(javax.sound.sampled.Clip) UnsupportedAudioFileException(javax.sound.sampled.UnsupportedAudioFileException) Shell(org.eclipse.swt.widgets.Shell) FirmwareManager(de.janrufmonitor.fritzbox.firmware.FirmwareManager) ByteArrayInputStream(java.io.ByteArrayInputStream) Base64Decoder(de.janrufmonitor.util.io.Base64Decoder) FileOutputStream(java.io.FileOutputStream) AudioFormat(javax.sound.sampled.AudioFormat) File(java.io.File) SWTExecuter(de.janrufmonitor.ui.swt.SWTExecuter)

Example 4 with Base64Decoder

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[] {};
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) BufferedInputStream(java.io.BufferedInputStream) Base64Decoder(de.janrufmonitor.util.io.Base64Decoder) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 5 with Base64Decoder

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Base64Decoder(de.janrufmonitor.util.io.Base64Decoder) IAttribute(de.janrufmonitor.framework.IAttribute) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

Base64Decoder (de.janrufmonitor.util.io.Base64Decoder)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 IAttribute (de.janrufmonitor.framework.IAttribute)1 ICall (de.janrufmonitor.framework.ICall)1 ICallerList (de.janrufmonitor.framework.ICallerList)1 FirmwareManager (de.janrufmonitor.fritzbox.firmware.FirmwareManager)1 FritzBoxLoginException (de.janrufmonitor.fritzbox.firmware.exception.FritzBoxLoginException)1 SWTExecuter (de.janrufmonitor.ui.swt.SWTExecuter)1 UUID (de.janrufmonitor.util.uuid.UUID)1 BufferedInputStream (java.io.BufferedInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ZipEntry (java.util.zip.ZipEntry)1