Search in sources :

Example 91 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project android_frameworks_base by ResurrectionRemix.

the class CustomPrinterIconCache method getIconFileName.

/**
     * Return the file name to be used for the icon of a printer
     *
     * @param printerId the id of the printer
     *
     * @return The file to be used for the icon of the printer
     */
@Nullable
private File getIconFileName(@NonNull PrinterId printerId) {
    StringBuffer sb = new StringBuffer(printerId.getServiceName().getPackageName());
    sb.append("-");
    try {
        MessageDigest md = MessageDigest.getInstance("SHA-1");
        md.update((printerId.getServiceName().getClassName() + ":" + printerId.getLocalId()).getBytes("UTF-16"));
        sb.append(String.format("%#040x", new java.math.BigInteger(1, md.digest())));
    } catch (UnsupportedEncodingException | NoSuchAlgorithmException e) {
        Log.e(LOG_TAG, "Could not compute custom printer icon file name", e);
        return null;
    }
    return new File(mCacheDirectory, sb.toString());
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) MessageDigest(java.security.MessageDigest) File(java.io.File) Nullable(android.annotation.Nullable)

Example 92 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project pratilipi by Pratilipi.

the class ImageSvgUtil method getHeight.

public static int getHeight(byte[] svgData) throws UnexpectedServerException {
    try {
        String svg = new String(svgData, "UTF-8");
        Pattern pattern = Pattern.compile(heightPattern, Pattern.DOTALL);
        Matcher mHeight = pattern.matcher(svg);
        mHeight.find();
        String heightStr = mHeight.group(1);
        return Integer.parseInt(heightStr.substring(heightStr.indexOf("\"") + 1, heightStr.lastIndexOf("\"")));
    } catch (UnsupportedEncodingException e) {
        throw new UnexpectedServerException();
    }
}
Also used : Pattern(java.util.regex.Pattern) UnexpectedServerException(com.pratilipi.common.exception.UnexpectedServerException) Matcher(java.util.regex.Matcher) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 93 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project android_frameworks_base by ResurrectionRemix.

the class LinkSpec method gatherMapLinks.

private static final void gatherMapLinks(ArrayList<LinkSpec> links, Spannable s) {
    String string = s.toString();
    String address;
    int base = 0;
    try {
        while ((address = WebView.findAddress(string)) != null) {
            int start = string.indexOf(address);
            if (start < 0) {
                break;
            }
            LinkSpec spec = new LinkSpec();
            int length = address.length();
            int end = start + length;
            spec.start = base + start;
            spec.end = base + end;
            string = string.substring(end);
            base += end;
            String encodedAddress = null;
            try {
                encodedAddress = URLEncoder.encode(address, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                continue;
            }
            spec.url = "geo:0,0?q=" + encodedAddress;
            links.add(spec);
        }
    } catch (UnsupportedOperationException e) {
        // in WebView.findAddress.
        return;
    }
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) SpannableString(android.text.SpannableString)

Example 94 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project yyl_example by Relucent.

the class Native2Ascii method getUnicodeString.

public String getUnicodeString(String value) {
    StringBuffer tempSb = new StringBuffer();
    try {
        Process pro = Runtime.getRuntime().exec("native2ascii");
        OutputStream out = pro.getOutputStream();
        out.write(value.getBytes());
        out.flush();
        out.close();
        InputStreamReader child_in = new InputStreamReader(pro.getInputStream());
        int c;
        while ((c = child_in.read()) != -1) {
            tempSb.append((char) c);
        }
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    return tempSb.toString();
}
Also used : InputStreamReader(java.io.InputStreamReader) OutputStream(java.io.OutputStream) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Example 95 with UnsupportedEncodingException

use of java.io.UnsupportedEncodingException in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiP2pSettings method utfToString.

private String utfToString(String utf) {
    int value;
    byte[] utfBytes = utf.getBytes();
    ByteBuffer decodedBytes = ByteBuffer.allocate(utf.length());
    int size = 0;
    for (int i = 0; i < utfBytes.length; i++) {
        if ((utfBytes[i] == '\\') && (utfBytes[i + 1] == 'x')) {
            value = Integer.parseInt(utf.substring(i + 2, i + 4), 16);
            decodedBytes.put((byte) value);
            i = i + 3;
        } else {
            decodedBytes.put(utfBytes[i]);
        }
        size++;
    }
    try {
        ByteBuffer sink = ByteBuffer.allocate(size);
        for (int j = 0; j < size; j++) {
            sink.put(decodedBytes.get(j));
        }
        return new String(sink.array(), "UTF-8");
    } catch (UnsupportedEncodingException uee) {
        uee.printStackTrace();
    }
    return null;
}
Also used : UnsupportedEncodingException(java.io.UnsupportedEncodingException) ByteBuffer(java.nio.ByteBuffer)

Aggregations

UnsupportedEncodingException (java.io.UnsupportedEncodingException)3108 IOException (java.io.IOException)878 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)284 InputStream (java.io.InputStream)275 ArrayList (java.util.ArrayList)268 InputStreamReader (java.io.InputStreamReader)243 File (java.io.File)234 ByteArrayInputStream (java.io.ByteArrayInputStream)209 ByteArrayOutputStream (java.io.ByteArrayOutputStream)201 FileNotFoundException (java.io.FileNotFoundException)198 HashMap (java.util.HashMap)182 MessageDigest (java.security.MessageDigest)180 BufferedReader (java.io.BufferedReader)150 URL (java.net.URL)150 Map (java.util.Map)148 OutputStreamWriter (java.io.OutputStreamWriter)145 FileOutputStream (java.io.FileOutputStream)120 MalformedURLException (java.net.MalformedURLException)110 FileInputStream (java.io.FileInputStream)107 List (java.util.List)105