@Test public void testContentTypeOf() throws IOException { MailHandler instance = new MailHandler(createInitProperties("")); InternalErrorManager em = new InternalErrorManager(); instance.setErrorManager(em); instance.setEncoding((String) null); String head = instance.contentTypeOf(new XMLFormatter().getHead(instance)); assertEquals("application/xml", head); instance.setEncoding("US-ASCII"); head = instance.contentTypeOf(new XMLFormatter().getHead(instance)); assertEquals("application/xml", head); instance.setEncoding((String) null); head = instance.contentTypeOf(new SimpleFormatter().getHead(instance)); assertNull(head); instance.setEncoding("US-ASCII"); head = instance.contentTypeOf(new SimpleFormatter().getHead(instance)); assertNull(head); instance.setEncoding((String) null); head = instance.contentTypeOf(new HeadFormatter("<HTML><BODY>").getHead(instance)); assertEquals("text/html", head); instance.setEncoding((String) null); head = instance.contentTypeOf(new HeadFormatter("<html><body>").getHead(instance)); assertEquals("text/html", head); instance.setEncoding("US-ASCII"); head = instance.contentTypeOf(new HeadFormatter("<HTML><BODY>").getHead(instance)); assertEquals("text/html", head); instance.setEncoding("US-ASCII"); head = instance.contentTypeOf(new HeadFormatter("<HTML><HEAD></HEAD>" + "<BODY></BODY></HTML>").getHead(instance)); assertEquals("text/html", head); instance.setEncoding((String) null); head = instance.contentTypeOf(new HeadFormatter("Head").getHead(instance)); if (head != null) { assertEquals("text/plain", head); } instance.setEncoding("US-ASCII"); head = instance.contentTypeOf(new HeadFormatter("Head").getHead(instance)); if (head != null) { assertEquals("text/plain", head); } instance.setEncoding("US-ASCII"); head = instance.contentTypeOf(new HeadFormatter("Head.......Neck.......Body").getHead(instance)); if (head != null) { assertEquals("text/plain", head); } instance.close(); for (int i = 0; i < em.exceptions.size(); i++) { fail(em.exceptions.get(i).toString()); } }
final String contentTypeOf(String head) { if (!isEmpty(head)) { final int MAX_CHARS = 25; if (head.length() > MAX_CHARS) { head = head.substring(0, MAX_CHARS); } try { final String encoding = getEncodingName(); final ByteArrayInputStream in = new ByteArrayInputStream(head.getBytes(encoding)); assert in.markSupported() : in.getClass().getName(); return URLConnection.guessContentTypeFromStream(in); } catch (final IOException IOE) { reportError(IOE.getMessage(), IOE, ErrorManager.FORMAT_FAILURE); } } return null; }
MailHandler extends Handler { final String contentTypeOf(String head) { if (!isEmpty(head)) { final int MAX_CHARS = 25; if (head.length() > MAX_CHARS) { head = head.substring(0, MAX_CHARS); } try { final String encoding = getEncodingName(); final ByteArrayInputStream in = new ByteArrayInputStream(head.getBytes(encoding)); assert in.markSupported() : in.getClass().getName(); return URLConnection.guessContentTypeFromStream(in); } catch (final IOException IOE) { reportError(IOE.getMessage(), IOE, ErrorManager.FORMAT_FAILURE); } } return null; } }
MailHandler extends Handler { final String contentTypeOf(String head) { if (!isEmpty(head)) { final int MAX_CHARS = 25; if (head.length() > MAX_CHARS) { head = head.substring(0, MAX_CHARS); } try { final String encoding = getEncodingName(); final ByteArrayInputStream in = new ByteArrayInputStream(head.getBytes(encoding)); assert in.markSupported() : in.getClass().getName(); return URLConnection.guessContentTypeFromStream(in); } catch (final IOException IOE) { reportError(IOE.getMessage(), IOE, ErrorManager.FORMAT_FAILURE); } } return null; } MailHandler();  MailHandler(final int capacity);  MailHandler(final Properties props); }
MailHandler extends Handler { final String contentTypeOf(String head) { if (!isEmpty(head)) { final int MAX_CHARS = 25; if (head.length() > MAX_CHARS) { head = head.substring(0, MAX_CHARS); } try { final String encoding = getEncodingName(); final ByteArrayInputStream in = new ByteArrayInputStream(head.getBytes(encoding)); assert in.markSupported() : in.getClass().getName(); return URLConnection.guessContentTypeFromStream(in); } catch (final IOException IOE) { reportError(IOE.getMessage(), IOE, ErrorManager.FORMAT_FAILURE); } } return null; } MailHandler();  MailHandler(final int capacity);  MailHandler(final Properties props); @Override boolean isLoggable(final LogRecord record); void publish(final LogRecord record); void push(); void flush(); void close(); @Override synchronized void setLevel(final Level newLevel); final synchronized Level getPushLevel(); final synchronized void setPushLevel(final Level level); final synchronized Filter getPushFilter(); final synchronized void setPushFilter(final Filter filter); final synchronized Comparator<? super LogRecord> getComparator(); final synchronized void setComparator(Comparator<? super LogRecord> c); final synchronized int getCapacity(); final synchronized Authenticator getAuthenticator(); final void setAuthenticator(final Authenticator auth); final void setAuthenticator(final char... password); final void setMailProperties(Properties props); final Properties getMailProperties(); final Filter[] getAttachmentFilters(); final void setAttachmentFilters(Filter... filters); final Formatter[] getAttachmentFormatters(); final void setAttachmentFormatters(Formatter... formatters); final Formatter[] getAttachmentNames(); final void setAttachmentNames(final String... names); final void setAttachmentNames(Formatter... formatters); final synchronized Formatter getSubject(); final void setSubject(final String subject); final void setSubject(final Formatter format); }
MailHandler extends Handler { final String contentTypeOf(String head) { if (!isEmpty(head)) { final int MAX_CHARS = 25; if (head.length() > MAX_CHARS) { head = head.substring(0, MAX_CHARS); } try { final String encoding = getEncodingName(); final ByteArrayInputStream in = new ByteArrayInputStream(head.getBytes(encoding)); assert in.markSupported() : in.getClass().getName(); return URLConnection.guessContentTypeFromStream(in); } catch (final IOException IOE) { reportError(IOE.getMessage(), IOE, ErrorManager.FORMAT_FAILURE); } } return null; } MailHandler();  MailHandler(final int capacity);  MailHandler(final Properties props); @Override boolean isLoggable(final LogRecord record); void publish(final LogRecord record); void push(); void flush(); void close(); @Override synchronized void setLevel(final Level newLevel); final synchronized Level getPushLevel(); final synchronized void setPushLevel(final Level level); final synchronized Filter getPushFilter(); final synchronized void setPushFilter(final Filter filter); final synchronized Comparator<? super LogRecord> getComparator(); final synchronized void setComparator(Comparator<? super LogRecord> c); final synchronized int getCapacity(); final synchronized Authenticator getAuthenticator(); final void setAuthenticator(final Authenticator auth); final void setAuthenticator(final char... password); final void setMailProperties(Properties props); final Properties getMailProperties(); final Filter[] getAttachmentFilters(); final void setAttachmentFilters(Filter... filters); final Formatter[] getAttachmentFormatters(); final void setAttachmentFormatters(Formatter... formatters); final Formatter[] getAttachmentNames(); final void setAttachmentNames(final String... names); final void setAttachmentNames(Formatter... formatters); final synchronized Formatter getSubject(); final void setSubject(final String subject); final void setSubject(final Formatter format);  }