Example usage for java.lang RuntimeException toString

List of usage examples for java.lang RuntimeException toString

Introduction

In this page you can find the example usage for java.lang RuntimeException toString.

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:org.grouplens.lenskit.diffusion.MainTester.java

public static void main(String[] args) {
    MainTester hello = new MainTester(args);
    System.out.println("Hellooo");
    try {//from ww  w  .j  a v  a 2  s. c  om
        //runsingle();
        hello.run();
    } catch (RuntimeException e) {
        System.err.println(e.toString());
        e.printStackTrace(System.err);
        System.exit(1);
    }
}

From source file:the.bytecode.club.bytecodeviewer.decompilers.CFRDecompiler.java

public static void doJar(DCCommonState dcCommonState, Path input, Path output) throws Exception {
    SummaryDumper summaryDumper = new NopSummaryDumper();
    Dumper d = new ToStringDumper();
    Options options = dcCommonState.getOptions();
    IllegalIdentifierDump illegalIdentifierDump = IllegalIdentifierDump.Factory.get(options);

    final Predicate e = org.benf.cfr.reader.util.MiscUtils
            .mkRegexFilter(options.getOption(OptionsImpl.JAR_FILTER), true);

    List<JavaTypeInstance> err1 = dcCommonState.explicitlyLoadJar(input.toAbsolutePath().toString());
    err1 = Functional.filter(err1, new Predicate<JavaTypeInstance>() {
        public boolean test(JavaTypeInstance in) {
            return e.test(in.getRawName());
        }//ww  w . java 2  s . c o  m
    });
    if (options.getOption(OptionsImpl.RENAME_MEMBERS)) {
        MemberNameResolver.resolveNames(dcCommonState, err1);
    }

    for (JavaTypeInstance type : err1) {
        try {
            ClassFile e1 = dcCommonState.getClassFile(type);
            if (e1.isInnerClass()) {
                d = null;
            } else {
                if (options.getOption(OptionsImpl.DECOMPILE_INNER_CLASSES).booleanValue()) {
                    e1.loadInnerClasses(dcCommonState);
                }

                e1.analyseTop(dcCommonState);
                TypeUsageCollector collectingDumper = new TypeUsageCollector(e1);
                e1.collectTypeUsages(collectingDumper);
                d = new FileDumper(output.toAbsolutePath().toString(), e1.getClassType(), summaryDumper,
                        collectingDumper.getTypeUsageInformation(), options, illegalIdentifierDump);
                e1.dump(d);
                d.print("\n");
                d.print("\n");
            }
        } catch (Dumper.CannotCreate var25) {
            throw var25;
        } catch (RuntimeException var26) {
            d.print(var26.toString()).print("\n").print("\n").print("\n");
        } finally {
            if (d != null) {
                d.close();
            }
        }
    }
}

From source file:Main.java

/**
 * Obtains DOMImpementaton interface providing a number of methods for
 * performing operations that are independent of any particular DOM
 * instance./*from   w ww  . j a  v a  2 s  .  c  om*/
 *
 * @throw DOMException <code>NOT_SUPPORTED_ERR</code> if cannot get
 * DOMImplementation
 * @throw FactoryConfigurationError Application developers should never need
 * to directly catch errors of this type.
 *
 * @return DOMImplementation implementation
 */
private static DOMImplementation getDOMImplementation() throws DOMException { //can be made public

    DocumentBuilderFactory factory = getFactory(false, false);

    try {
        return factory.newDocumentBuilder().getDOMImplementation();
    } catch (ParserConfigurationException ex) {
        throw new DOMException(DOMException.NOT_SUPPORTED_ERR,
                "Cannot create parser satisfying configuration parameters"); //NOI18N
    } catch (RuntimeException e) {
        // E.g. #36578, IllegalArgumentException. Try to recover gracefully.
        throw (DOMException) new DOMException(DOMException.NOT_SUPPORTED_ERR, e.toString()).initCause(e);
    }
}

From source file:cn.suishen.email.LegacyConversions.java

/**
 * Read a complete Provider message into a legacy message (for IMAP upload).  This
 * is basically the equivalent of LocalFolder.getMessages() + LocalFolder.fetch().
 *///from ww w .  j  a  v  a 2s  .  c o m
public static Message makeMessage(Context context, EmailContent.Message localMessage)
        throws MessagingException {
    MimeMessage message = new MimeMessage();

    // LocalFolder.getMessages() equivalent:  Copy message fields
    message.setSubject(localMessage.mSubject == null ? "" : localMessage.mSubject);
    Address[] from = Address.unpack(localMessage.mFrom);
    if (from.length > 0) {
        message.setFrom(from[0]);
    }
    message.setSentDate(new Date(localMessage.mTimeStamp));
    message.setUid(localMessage.mServerId);
    message.setFlag(Flag.DELETED, localMessage.mFlagLoaded == EmailContent.Message.FLAG_LOADED_DELETED);
    message.setFlag(Flag.SEEN, localMessage.mFlagRead);
    message.setFlag(Flag.FLAGGED, localMessage.mFlagFavorite);
    //      message.setFlag(Flag.DRAFT, localMessage.mMailboxKey == draftMailboxKey);
    message.setRecipients(RecipientType.TO, Address.unpack(localMessage.mTo));
    message.setRecipients(RecipientType.CC, Address.unpack(localMessage.mCc));
    message.setRecipients(RecipientType.BCC, Address.unpack(localMessage.mBcc));
    message.setReplyTo(Address.unpack(localMessage.mReplyTo));
    message.setInternalDate(new Date(localMessage.mServerTimeStamp));
    message.setMessageId(localMessage.mMessageId);

    // LocalFolder.fetch() equivalent: build body parts
    message.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "multipart/mixed");
    MimeMultipart mp = new MimeMultipart();
    mp.setSubType("mixed");
    message.setBody(mp);

    try {
        addTextBodyPart(mp, "text/html", null,
                EmailContent.Body.restoreBodyHtmlWithMessageId(context, localMessage.mId));
    } catch (RuntimeException rte) {
        Log.d(Logging.LOG_TAG, "Exception while reading html body " + rte.toString());
    }

    try {
        addTextBodyPart(mp, "text/plain", null,
                EmailContent.Body.restoreBodyTextWithMessageId(context, localMessage.mId));
    } catch (RuntimeException rte) {
        Log.d(Logging.LOG_TAG, "Exception while reading text body " + rte.toString());
    }

    boolean isReply = (localMessage.mFlags & EmailContent.Message.FLAG_TYPE_REPLY) != 0;
    boolean isForward = (localMessage.mFlags & EmailContent.Message.FLAG_TYPE_FORWARD) != 0;

    // If there is a quoted part (forwarding or reply), add the intro first, and then the
    // rest of it.  If it is opened in some other viewer, it will (hopefully) be displayed in
    // the same order as we've just set up the blocks:  composed text, intro, replied text
    if (isReply || isForward) {
        try {
            addTextBodyPart(mp, "text/plain", BODY_QUOTED_PART_INTRO,
                    EmailContent.Body.restoreIntroTextWithMessageId(context, localMessage.mId));
        } catch (RuntimeException rte) {
            Log.d(Logging.LOG_TAG, "Exception while reading text reply " + rte.toString());
        }

        String replyTag = isReply ? BODY_QUOTED_PART_REPLY : BODY_QUOTED_PART_FORWARD;
        try {
            addTextBodyPart(mp, "text/html", replyTag,
                    EmailContent.Body.restoreReplyHtmlWithMessageId(context, localMessage.mId));
        } catch (RuntimeException rte) {
            Log.d(Logging.LOG_TAG, "Exception while reading html reply " + rte.toString());
        }

        try {
            addTextBodyPart(mp, "text/plain", replyTag,
                    EmailContent.Body.restoreReplyTextWithMessageId(context, localMessage.mId));
        } catch (RuntimeException rte) {
            Log.d(Logging.LOG_TAG, "Exception while reading text reply " + rte.toString());
        }
    }

    // Attachments
    // TODO: Make sure we deal with these as structures and don't accidentally upload files
    //        Uri uri = ContentUris.withAppendedId(Attachment.MESSAGE_ID_URI, localMessage.mId);
    //        Cursor attachments = context.getContentResolver().query(uri, Attachment.CONTENT_PROJECTION,
    //                null, null, null);
    //        try {
    //
    //        } finally {
    //            attachments.close();
    //        }

    return message;
}

From source file:com.android.email_ee.LegacyConversions.java

/**
 * Read a complete Provider message into a legacy message (for IMAP upload).  This
 * is basically the equivalent of LocalFolder.getMessages() + LocalFolder.fetch().
 *///from ww w.ja va 2  s  .com
public static Message makeMessage(Context context, EmailContent.Message localMessage)
        throws MessagingException {
    MimeMessage message = new MimeMessage();

    // LocalFolder.getMessages() equivalent:  Copy message fields
    message.setSubject(localMessage.mSubject == null ? "" : localMessage.mSubject);
    Address[] from = Address.unpack(localMessage.mFrom);
    if (from.length > 0) {
        message.setFrom(from[0]);
    }
    message.setSentDate(new Date(localMessage.mTimeStamp));
    message.setUid(localMessage.mServerId);
    message.setFlag(Flag.DELETED, localMessage.mFlagLoaded == EmailContent.Message.FLAG_LOADED_DELETED);
    message.setFlag(Flag.SEEN, localMessage.mFlagRead);
    message.setFlag(Flag.FLAGGED, localMessage.mFlagFavorite);
    //      message.setFlag(Flag.DRAFT, localMessage.mMailboxKey == draftMailboxKey);
    message.setRecipients(RecipientType.TO, Address.unpack(localMessage.mTo));
    message.setRecipients(RecipientType.CC, Address.unpack(localMessage.mCc));
    message.setRecipients(RecipientType.BCC, Address.unpack(localMessage.mBcc));
    message.setReplyTo(Address.unpack(localMessage.mReplyTo));
    message.setInternalDate(new Date(localMessage.mServerTimeStamp));
    message.setMessageId(localMessage.mMessageId);

    // LocalFolder.fetch() equivalent: build body parts
    message.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "multipart/mixed");
    MimeMultipart mp = new MimeMultipart();
    mp.setSubType("mixed");
    message.setBody(mp);

    try {
        addTextBodyPart(mp, "text/html", null,
                EmailContent.Body.restoreBodyHtmlWithMessageId(context, localMessage.mId));
    } catch (RuntimeException rte) {
        LogUtils.d(Logging.LOG_TAG, "Exception while reading html body " + rte.toString());
    }

    try {
        addTextBodyPart(mp, "text/plain", null,
                EmailContent.Body.restoreBodyTextWithMessageId(context, localMessage.mId));
    } catch (RuntimeException rte) {
        LogUtils.d(Logging.LOG_TAG, "Exception while reading text body " + rte.toString());
    }

    boolean isReply = (localMessage.mFlags & EmailContent.Message.FLAG_TYPE_REPLY) != 0;
    boolean isForward = (localMessage.mFlags & EmailContent.Message.FLAG_TYPE_FORWARD) != 0;

    // If there is a quoted part (forwarding or reply), add the intro first, and then the
    // rest of it.  If it is opened in some other viewer, it will (hopefully) be displayed in
    // the same order as we've just set up the blocks:  composed text, intro, replied text
    if (isReply || isForward) {
        try {
            addTextBodyPart(mp, "text/plain", BODY_QUOTED_PART_INTRO,
                    EmailContent.Body.restoreIntroTextWithMessageId(context, localMessage.mId));
        } catch (RuntimeException rte) {
            LogUtils.d(Logging.LOG_TAG, "Exception while reading text reply " + rte.toString());
        }

        String replyTag = isReply ? BODY_QUOTED_PART_REPLY : BODY_QUOTED_PART_FORWARD;
        try {
            addTextBodyPart(mp, "text/html", replyTag,
                    EmailContent.Body.restoreReplyHtmlWithMessageId(context, localMessage.mId));
        } catch (RuntimeException rte) {
            LogUtils.d(Logging.LOG_TAG, "Exception while reading html reply " + rte.toString());
        }

        try {
            addTextBodyPart(mp, "text/plain", replyTag,
                    EmailContent.Body.restoreReplyTextWithMessageId(context, localMessage.mId));
        } catch (RuntimeException rte) {
            LogUtils.d(Logging.LOG_TAG, "Exception while reading text reply " + rte.toString());
        }
    }

    // Attachments
    // TODO: Make sure we deal with these as structures and don't accidentally upload files
    //        Uri uri = ContentUris.withAppendedId(Attachment.MESSAGE_ID_URI, localMessage.mId);
    //        Cursor attachments = context.getContentResolver().query(uri, Attachment.CONTENT_PROJECTION,
    //                null, null, null);
    //        try {
    //
    //        } finally {
    //            attachments.close();
    //        }

    return message;
}

From source file:com.tct.email.LegacyConversions.java

/**
 * Read a complete Provider message into a legacy message (for IMAP upload).  This
 * is basically the equivalent of LocalFolder.getMessages() + LocalFolder.fetch().
 *///from w  w  w.j  a  v a2s  . c  o m
public static Message makeMessage(final Context context, final EmailContent.Message localMessage)
        throws MessagingException {
    final MimeMessage message = new MimeMessage();

    // LocalFolder.getMessages() equivalent:  Copy message fields
    message.setSubject(localMessage.mSubject == null ? "" : localMessage.mSubject);
    final Address[] from = Address.fromHeader(localMessage.mFrom);
    if (from.length > 0) {
        message.setFrom(from[0]);
    }
    message.setSentDate(new Date(localMessage.mTimeStamp));
    message.setUid(localMessage.mServerId);
    message.setFlag(Flag.DELETED, localMessage.mFlagLoaded == EmailContent.Message.FLAG_LOADED_DELETED);
    message.setFlag(Flag.SEEN, localMessage.mFlagRead);
    message.setFlag(Flag.FLAGGED, localMessage.mFlagFavorite);
    //      message.setFlag(Flag.DRAFT, localMessage.mMailboxKey == draftMailboxKey);
    message.setRecipients(RecipientType.TO, Address.fromHeader(localMessage.mTo));
    message.setRecipients(RecipientType.CC, Address.fromHeader(localMessage.mCc));
    message.setRecipients(RecipientType.BCC, Address.fromHeader(localMessage.mBcc));
    message.setReplyTo(Address.fromHeader(localMessage.mReplyTo));
    message.setInternalDate(new Date(localMessage.mServerTimeStamp));
    message.setMessageId(localMessage.mMessageId);
    message.setPriority(localMessage.mPriority);//[FEATURE]-Add-BEGIN by TCTNj.fu.zhang,04/03/2014,622697
    // LocalFolder.fetch() equivalent: build body parts
    message.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "multipart/mixed");
    final MimeMultipart mp = new MimeMultipart();
    mp.setSubType("mixed");
    message.setBody(mp);

    try {
        addTextBodyPart(mp, "text/html",
                EmailContent.Body.restoreBodyHtmlWithMessageId(context, localMessage.mId));
    } catch (RuntimeException rte) {
        LogUtils.d(Logging.LOG_TAG, "Exception while reading html body " + rte.toString());
    }

    try {
        addTextBodyPart(mp, "text/plain",
                EmailContent.Body.restoreBodyTextWithMessageId(context, localMessage.mId));
    } catch (RuntimeException rte) {
        LogUtils.d(Logging.LOG_TAG, "Exception while reading text body " + rte.toString());
    }

    // Attachments
    final Uri uri = ContentUris.withAppendedId(Attachment.MESSAGE_ID_URI, localMessage.mId);
    final Cursor attachments = context.getContentResolver().query(uri, Attachment.CONTENT_PROJECTION, null,
            null, null);

    try {
        while (attachments != null && attachments.moveToNext()) {
            final Attachment att = new Attachment();
            att.restore(attachments);
            try {
                final InputStream content;
                if (att.mContentBytes != null) {
                    // This is generally only the case for synthetic attachments, such as those
                    // generated by unit tests or calendar invites
                    content = new ByteArrayInputStream(att.mContentBytes);
                } else {
                    String contentUriString = att.getCachedFileUri();
                    if (TextUtils.isEmpty(contentUriString)) {
                        contentUriString = att.getContentUri();
                    }
                    if (TextUtils.isEmpty(contentUriString)) {
                        content = null;
                    } else {
                        final Uri contentUri = Uri.parse(contentUriString);
                        content = context.getContentResolver().openInputStream(contentUri);
                    }
                }
                final String mimeType = att.mMimeType;
                final Long contentSize = att.mSize;
                final String contentId = att.mContentId;
                final String filename = att.mFileName;
                if (content != null) {
                    addAttachmentPart(mp, mimeType, contentSize, filename, contentId, content);
                } else {
                    LogUtils.e(LogUtils.TAG, "Could not open attachment file for upsync");
                }
            } catch (final FileNotFoundException e) {
                LogUtils.e(LogUtils.TAG, "File Not Found error on %s while upsyncing message",
                        att.getCachedFileUri());
            }
        }
    } finally {
        if (attachments != null) {
            attachments.close();
        }
    }

    return message;
}

From source file:com.android.email.LegacyConversions.java

/**
 * Read a complete Provider message into a legacy message (for IMAP upload).  This
 * is basically the equivalent of LocalFolder.getMessages() + LocalFolder.fetch().
 *//*from ww w  . ja v  a 2 s  .c om*/
public static Message makeMessage(Context context, EmailContent.Message localMessage)
        throws MessagingException {
    MimeMessage message = new MimeMessage();

    // LocalFolder.getMessages() equivalent:  Copy message fields
    message.setSubject(localMessage.mSubject == null ? "" : localMessage.mSubject);
    Address[] from = Address.unpack(localMessage.mFrom);
    if (from.length > 0) {
        message.setFrom(from[0]);
    }
    message.setSentDate(new Date(localMessage.mTimeStamp));
    message.setUid(localMessage.mServerId);
    message.setFlag(Flag.DELETED, localMessage.mFlagLoaded == EmailContent.Message.FLAG_LOADED_DELETED);
    message.setFlag(Flag.SEEN, localMessage.mFlagRead);
    message.setFlag(Flag.FLAGGED, localMessage.mFlagFavorite);
    //      message.setFlag(Flag.DRAFT, localMessage.mMailboxKey == draftMailboxKey);
    message.setRecipients(RecipientType.TO, Address.unpack(localMessage.mTo));
    message.setRecipients(RecipientType.CC, Address.unpack(localMessage.mCc));
    message.setRecipients(RecipientType.BCC, Address.unpack(localMessage.mBcc));
    message.setReplyTo(Address.unpack(localMessage.mReplyTo));
    message.setInternalDate(new Date(localMessage.mServerTimeStamp));
    message.setMessageId(localMessage.mMessageId);

    // LocalFolder.fetch() equivalent: build body parts
    message.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "multipart/mixed");
    MimeMultipart mp = new MimeMultipart();
    mp.setSubType("mixed");
    message.setBody(mp);

    try {
        addTextBodyPart(mp, "text/html", null,
                EmailContent.Body.restoreBodyHtmlWithMessageId(context, localMessage.mId));
    } catch (RuntimeException rte) {
        Log.d(Email.LOG_TAG, "Exception while reading html body " + rte.toString());
    }

    try {
        addTextBodyPart(mp, "text/plain", null,
                EmailContent.Body.restoreBodyTextWithMessageId(context, localMessage.mId));
    } catch (RuntimeException rte) {
        Log.d(Email.LOG_TAG, "Exception while reading text body " + rte.toString());
    }

    boolean isReply = (localMessage.mFlags & EmailContent.Message.FLAG_TYPE_REPLY) != 0;
    boolean isForward = (localMessage.mFlags & EmailContent.Message.FLAG_TYPE_FORWARD) != 0;

    // If there is a quoted part (forwarding or reply), add the intro first, and then the
    // rest of it.  If it is opened in some other viewer, it will (hopefully) be displayed in
    // the same order as we've just set up the blocks:  composed text, intro, replied text
    if (isReply || isForward) {
        try {
            addTextBodyPart(mp, "text/plain", BODY_QUOTED_PART_INTRO,
                    EmailContent.Body.restoreIntroTextWithMessageId(context, localMessage.mId));
        } catch (RuntimeException rte) {
            Log.d(Email.LOG_TAG, "Exception while reading text reply " + rte.toString());
        }

        String replyTag = isReply ? BODY_QUOTED_PART_REPLY : BODY_QUOTED_PART_FORWARD;
        try {
            addTextBodyPart(mp, "text/html", replyTag,
                    EmailContent.Body.restoreReplyHtmlWithMessageId(context, localMessage.mId));
        } catch (RuntimeException rte) {
            Log.d(Email.LOG_TAG, "Exception while reading html reply " + rte.toString());
        }

        try {
            addTextBodyPart(mp, "text/plain", replyTag,
                    EmailContent.Body.restoreReplyTextWithMessageId(context, localMessage.mId));
        } catch (RuntimeException rte) {
            Log.d(Email.LOG_TAG, "Exception while reading text reply " + rte.toString());
        }
    }

    // Attachments
    // TODO: Make sure we deal with these as structures and don't accidentally upload files
    //        Uri uri = ContentUris.withAppendedId(Attachment.MESSAGE_ID_URI, localMessage.mId);
    //        Cursor attachments = context.getContentResolver().query(uri, Attachment.CONTENT_PROJECTION,
    //                null, null, null);
    //        try {
    //
    //        } finally {
    //            attachments.close();
    //        }

    return message;
}

From source file:com.mail163.email.LegacyConversions.java

/**
 * Read a complete Provider message into a legacy message (for IMAP upload).  This
 * is basically the equivalent of LocalFolder.getMessages() + LocalFolder.fetch().
 *///w w w .j  a v a  2s . co m
public static Message makeMessage(Context context, EmailContent.Message localMessage)
        throws MessagingException {
    MimeMessage message = new MimeMessage();

    // LocalFolder.getMessages() equivalent:  Copy message fields
    message.setSubject(localMessage.mSubject == null ? "" : localMessage.mSubject);
    message.setPriority(localMessage.mPriority == null ? "" : localMessage.mPriority);
    Address[] from = Address.unpack(localMessage.mFrom);
    if (from.length > 0) {
        message.setFrom(from[0]);
    }
    message.setSentDate(new Date(localMessage.mTimeStamp));
    message.setUid(localMessage.mServerId);
    message.setFlag(Flag.DELETED, localMessage.mFlagLoaded == EmailContent.Message.FLAG_LOADED_DELETED);
    message.setFlag(Flag.SEEN, localMessage.mFlagRead);
    message.setFlag(Flag.FLAGGED, localMessage.mFlagFavorite);
    //      message.setFlag(Flag.DRAFT, localMessage.mMailboxKey == draftMailboxKey);
    message.setRecipients(RecipientType.TO, Address.unpack(localMessage.mTo));
    message.setRecipients(RecipientType.CC, Address.unpack(localMessage.mCc));
    message.setRecipients(RecipientType.BCC, Address.unpack(localMessage.mBcc));
    message.setReplyTo(Address.unpack(localMessage.mReplyTo));
    message.setInternalDate(new Date(localMessage.mServerTimeStamp));
    message.setMessageId(localMessage.mMessageId);

    // LocalFolder.fetch() equivalent: build body parts
    message.setHeader(MimeHeader.HEADER_CONTENT_TYPE, "multipart/mixed");
    MimeMultipart mp = new MimeMultipart();
    mp.setSubType("mixed");
    message.setBody(mp);

    try {
        addTextBodyPart(mp, "text/html", null,
                EmailContent.Body.restoreBodyHtmlWithMessageId(context, localMessage.mId));
    } catch (RuntimeException rte) {
        Log.d(Email.LOG_TAG, "Exception while reading html body " + rte.toString());
    }

    try {
        addTextBodyPart(mp, "text/plain", null,
                EmailContent.Body.restoreBodyTextWithMessageId(context, localMessage.mId));
    } catch (RuntimeException rte) {
        Log.d(Email.LOG_TAG, "Exception while reading text body " + rte.toString());
    }

    boolean isReply = (localMessage.mFlags & EmailContent.Message.FLAG_TYPE_REPLY) != 0;
    boolean isForward = (localMessage.mFlags & EmailContent.Message.FLAG_TYPE_FORWARD) != 0;

    // If there is a quoted part (forwarding or reply), add the intro first, and then the
    // rest of it.  If it is opened in some other viewer, it will (hopefully) be displayed in
    // the same order as we've just set up the blocks:  composed text, intro, replied text
    if (isReply || isForward) {
        try {
            addTextBodyPart(mp, "text/plain", BODY_QUOTED_PART_INTRO,
                    EmailContent.Body.restoreIntroTextWithMessageId(context, localMessage.mId));
        } catch (RuntimeException rte) {
            Log.d(Email.LOG_TAG, "Exception while reading text reply " + rte.toString());
        }

        String replyTag = isReply ? BODY_QUOTED_PART_REPLY : BODY_QUOTED_PART_FORWARD;
        try {
            addTextBodyPart(mp, "text/html", replyTag,
                    EmailContent.Body.restoreReplyHtmlWithMessageId(context, localMessage.mId));
        } catch (RuntimeException rte) {
            Log.d(Email.LOG_TAG, "Exception while reading html reply " + rte.toString());
        }

        try {
            addTextBodyPart(mp, "text/plain", replyTag,
                    EmailContent.Body.restoreReplyTextWithMessageId(context, localMessage.mId));
        } catch (RuntimeException rte) {
            Log.d(Email.LOG_TAG, "Exception while reading text reply " + rte.toString());
        }
    }

    // Attachments
    // TODO: Make sure we deal with these as structures and don't accidentally upload files
    //        Uri uri = ContentUris.withAppendedId(Attachment.MESSAGE_ID_URI, localMessage.mId);
    //        Cursor attachments = context.getContentResolver().query(uri, Attachment.CONTENT_PROJECTION,
    //                null, null, null);
    //        try {
    //
    //        } finally {
    //            attachments.close();
    //        }

    return message;
}

From source file:it.unimi.di.big.mg4j.query.InputStreamItem.java

protected void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
    try {//w  ww.  j a v  a  2  s.  c  o m
        if (request.getParameter("m") != null && request.getParameter("doc") != null) {
            DocumentCollection collection = (DocumentCollection) getServletContext().getAttribute("collection");
            if (collection == null)
                LOGGER.error("The servlet context does not contain a document collection.");
            response.setContentType(request.getParameter("m"));
            response.setCharacterEncoding("UTF-8");
            InputStream rawContent = collection.stream(Long.parseLong(request.getParameter("doc")));
            for (int i = skip; i-- != 0;)
                rawContent.reset();
            IOUtils.copy(rawContent, response.getOutputStream());
        }
    } catch (RuntimeException e) {
        e.printStackTrace();
        LOGGER.error(e.toString());
        throw e;
    }
}

From source file:com.android.unit_tests.GoogleHttpClientTest.java

@LargeTest
public void testThreadCheck() throws Exception {
    ContentResolver resolver = getContext().getContentResolver();
    GoogleHttpClient client = new GoogleHttpClient(resolver, "Test");

    try {//from w  ww . j  a  va 2 s .c om
        // Note: we must test against a real server, because the connection
        // gets established before the interceptor can crash the request.
        HttpGet method = new HttpGet(mServerUrl);

        // This is actually an AndroidHttpClient feature...
        // TODO: somehow test that Activity threads have the flag set?
        AndroidHttpClient.setThreadBlocked(true);

        try {
            client.execute(method);
            fail("\"thread forbids HTTP requests\" exception expected");
        } catch (RuntimeException e) {
            if (!e.toString().contains("forbids HTTP requests"))
                throw e;
        } finally {
            AndroidHttpClient.setThreadBlocked(false);
        }

        HttpResponse response = client.execute(method);
        assertEquals("/", EntityUtils.toString(response.getEntity()));
    } finally {
        client.close();
    }
}