Search in sources :

Example 61 with ProcessingException

use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.

the class SunSecurityProvider method createHash.

@Override
public byte[] createHash(InputStream data, byte[] salt, int iterations) {
    if (data == null) {
        throw new AssertionException("no data provided");
    }
    try {
        MessageDigest digest = MessageDigest.getInstance(getDigestAlgorithm(), getDigestAlgorithmProvider());
        digest.reset();
        if (salt != null && salt.length > 0) {
            digest.update(salt);
        }
        int n;
        byte[] buf = new byte[BUF_SIZE];
        while ((n = data.read(buf)) >= 0) {
            digest.update(buf, 0, n);
        }
        byte[] key = digest.digest();
        for (int i = 1; i < iterations; i++) {
            key = digest.digest(key);
            digest.reset();
        }
        return key;
    } catch (NoSuchAlgorithmException | NoSuchProviderException | IOException e) {
        throw new ProcessingException("Unable to hash.", e);
    }
}
Also used : AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) MessageDigest(java.security.MessageDigest) NoSuchProviderException(java.security.NoSuchProviderException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 62 with ProcessingException

use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.

the class SunSecurityProvider method createMac.

@Override
public byte[] createMac(byte[] password, InputStream data) {
    Assertions.assertGreater(Assertions.assertNotNull(password, "no password provided").length, 0, "empty password not allowed");
    if (data == null) {
        throw new AssertionException("no data provided");
    }
    try {
        String algorithm = getMacAlgorithm();
        SecretKeySpec key = new SecretKeySpec(password, 0, password.length, algorithm);
        Mac mac = Mac.getInstance(algorithm, getMacAlgorithmProvider());
        mac.init(key);
        int n;
        byte[] buf = new byte[BUF_SIZE];
        while ((n = data.read(buf)) >= 0) {
            mac.update(buf, 0, n);
        }
        return mac.doFinal();
    } catch (NoSuchAlgorithmException | InvalidKeyException | IllegalStateException | IOException | NoSuchProviderException e) {
        throw new ProcessingException("unable to create signature.", e);
    }
}
Also used : AssertionException(org.eclipse.scout.rt.platform.util.Assertions.AssertionException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) InvalidKeyException(java.security.InvalidKeyException) Mac(javax.crypto.Mac) SecretKeySpec(javax.crypto.spec.SecretKeySpec) NoSuchProviderException(java.security.NoSuchProviderException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 63 with ProcessingException

use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.

the class IOUtility method readString.

/**
 * Reads string.
 * <p>
 * Stream is <em>not</em> closed. Use resource-try on streams created by caller.
 *
 * @param in
 * @param maxLen
 *          max number of characters to read or -1 if the whole stream should be read.
 * @return the content string
 */
public static String readString(Reader in, int maxLen) {
    if (maxLen >= 0) {
        try {
            char[] buf = new char[maxLen];
            int count = 0;
            int nRead = in.read(buf, 0, maxLen);
            while (nRead != -1 && count < maxLen) {
                count += nRead;
                nRead = in.read(buf, count, maxLen - count);
            }
            return new String(buf, 0, count);
        } catch (IOException e) {
            throw new ProcessingException("input: " + in, e);
        }
    } else {
        try (StringWriter buffer = new StringWriter()) {
            char[] b = new char[BUFFER_SIZE];
            int k;
            while ((k = in.read(b)) > 0) {
                buffer.write(b, 0, k);
            }
            return buffer.toString();
        } catch (IOException e) {
            throw new ProcessingException("input: " + in, e);
        }
    }
}
Also used : StringWriter(java.io.StringWriter) IOException(java.io.IOException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 64 with ProcessingException

use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.

the class IOUtility method createTempDirectory.

/**
 * creates a temporary directory with a random name and the given suffix
 */
public static File createTempDirectory(String dirSuffix) {
    try {
        if (dirSuffix != null) {
            dirSuffix = dirSuffix.replaceAll("[:*?\\\"<>|]*", "");
        }
        File tmp = File.createTempFile("dir", dirSuffix);
        tmp.delete();
        tmp.mkdirs();
        tmp.deleteOnExit();
        return tmp;
    } catch (IOException e) {
        throw new ProcessingException("dir: " + dirSuffix, e);
    }
}
Also used : IOException(java.io.IOException) File(java.io.File) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Example 65 with ProcessingException

use of org.eclipse.scout.rt.platform.exception.ProcessingException in project scout.rt by eclipse.

the class IOUtility method writeString.

/**
 * Write string.
 * <p>
 * Stream is <em>not</em> closed. Use resource-try on streams created by caller.
 *
 * @param out
 * @param charset
 * @param s
 */
public static void writeString(OutputStream out, String charset, String s) {
    try {
        OutputStreamWriter w = new OutputStreamWriter(out, charset);
        w.write(s);
        w.flush();
    } catch (IOException e) {
        throw new ProcessingException("output: " + out, e);
    }
}
Also used : OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) ProcessingException(org.eclipse.scout.rt.platform.exception.ProcessingException)

Aggregations

ProcessingException (org.eclipse.scout.rt.platform.exception.ProcessingException)142 IOException (java.io.IOException)48 MessagingException (javax.mail.MessagingException)21 Test (org.junit.Test)19 ArrayList (java.util.ArrayList)17 File (java.io.File)14 VetoException (org.eclipse.scout.rt.platform.exception.VetoException)12 Folder (javax.mail.Folder)10 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)9 RemoteFile (org.eclipse.scout.rt.shared.services.common.file.RemoteFile)9 NoSuchProviderException (java.security.NoSuchProviderException)8 AssertionException (org.eclipse.scout.rt.platform.util.Assertions.AssertionException)8 FileInputStream (java.io.FileInputStream)7 InputStream (java.io.InputStream)7 UnsupportedEncodingException (java.io.UnsupportedEncodingException)7 FileOutputStream (java.io.FileOutputStream)6 Message (javax.mail.Message)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 OutputStream (java.io.OutputStream)5 HashMap (java.util.HashMap)5