public int addTitaniumFileAsPostData(String name, Object value) { try { if (value instanceof TiBaseFile) { TiBaseFile baseFile = (TiBaseFile) value; FileBody body = new FileBody( baseFile.getNativeFile(), TiMimeTypeHelper.getMimeType(baseFile.nativePath())); parts.put(name, body); return (int) baseFile.getNativeFile().length(); } else if (value instanceof TiBlob) { TiBlob blob = (TiBlob) value; String mimeType = blob.getMimeType(); File tmpFile = File.createTempFile( "tixhr", TiMimeTypeHelper.getFileExtensionFromMimeType(mimeType, ".txt")); FileOutputStream fos = new FileOutputStream(tmpFile); fos.write(blob.getBytes()); fos.close(); FileBody body = new FileBody(tmpFile, mimeType); parts.put(name, body); return blob.getLength(); } else { if (value != null) { Log.e(LCAT, name + " is a " + value.getClass().getSimpleName()); } else { Log.e(LCAT, name + " is null"); } } } catch (IOException e) { Log.e(LCAT, "Error adding post data (" + name + "): " + e.getMessage()); } return 0; }
private boolean mightBeHtml(String url) { String mime = TiMimeTypeHelper.getMimeType(url); if (mime.equals("text/html")) { return true; } else if (mime.equals("application/xhtml+xml")) { return true; } else { return false; } }
@Override public TiBlob read() throws IOException { ByteArrayOutputStream baos = null; InputStream in = null; try { baos = new ByteArrayOutputStream(); in = getInputStream(); byte buffer[] = new byte[4096]; while (true) { int count = in.read(buffer); if (count < 0) { break; } baos.write(buffer, 0, count); } } finally { if (in != null) { in.close(); } } return TiBlob.blobFromData( getTiContext(), baos.toByteArray(), TiMimeTypeHelper.getMimeType(toURL())); }