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());
}
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();
}
}
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;
}
}
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();
}
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;
}
Aggregations