<?xml version="1.0" encoding="gb2312"?>
<!-- generator="FeedCreator 1.7.2" -->
<rss version="2.0">
    <channel>
        <title>海波无痕</title>
        <description>海波无痕</description>
        <link></link>
        <lastBuildDate>Thu, 11 Mar 2010 15:16:23 +0800</lastBuildDate>
        <generator>FeedCreator 1.7.2</generator>
        <copyright>海波无痕</copyright>
        <item>
            <title>xmlbeans 根据xml实例生成schema并生成java映射</title>
            <link>http://ziki.cn/q/index.php/q-b_uuid-24.html</link>
            <description>&lt;p&gt;inst2xsd -enumerations never test.xml&lt;/p&gt;&lt;p&gt;scomp -out test.jar schema0.xsd&lt;/p&gt;</description>
            <author>海波无痕</author>
            <pubDate>Wed, 17 Sep 2008 13:10:07 +0800</pubDate>
        </item>
        <item>
            <title>java如何获得当前方法名</title>
            <link>http://ziki.cn/q/index.php/q-b_uuid-22.html</link>
            <description>&lt;p&gt;String _methodName =&lt;/p&gt;&lt;p&gt;new Exception().getStackTrace()[1].getMethodName();// 获得调用者的方法名&lt;/p&gt;&lt;p&gt;String _thisMethodName =&lt;/p&gt;&lt;p&gt;new Exception().getStackTrace()[0].getMethodName();// 获得当前的方法名&lt;/p&gt;</description>
            <author>海波无痕</author>
            <pubDate>Thu, 14 Aug 2008 13:53:28 +0800</pubDate>
        </item>
        <item>
            <title>Get the Mime Type from a File[zz]</title>
            <link>http://ziki.cn/q/index.php/q-b_uuid-20.html</link>
            <description>&lt;p&gt;Using javax.activation.MimetypesFileTypeMap&lt;br /&gt;activation.jar is required, it can be downloaded from &lt;a href=&quot;http://java.sun.com/products/javabeans/glasgow/jaf.html&quot;&gt;http://java.sun.com/products/javabeans/glasgow/jaf.html&lt;/a&gt;. &lt;br /&gt;The MimetypesFileMap class is used to map a File to a Mime Type. Mime types supported are defined in a ressource file inside the activation.jar. &lt;/p&gt;&lt;p&gt;import javax.activation.MimetypesFileTypeMap; import java.io.File;&amp;nbsp; class GetMimeType {&amp;nbsp;&amp;nbsp; public static void main(String args[]) {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; File f = new File(&amp;quot;gumby.gif&amp;quot;);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(&amp;quot;Mime Type of &amp;quot; + f.getName() + &amp;quot; is &amp;quot; +&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; new MimetypesFileTypeMap().getContentType(f));&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // expected output :&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // &amp;quot;Mime Type of gumby.gif is image/gif&amp;quot;&amp;nbsp;&amp;nbsp; } }&lt;br /&gt;The built-in mime-type list is very limited but a mechanism is available to add very easily more Mime Types/extensions. &lt;br /&gt;The MimetypesFileTypeMap looks in various places in the user&amp;#39;s system for MIME types file entries. When requests are made to search for MIME types in the MimetypesFileTypeMap, it searches MIME types files in the following order: &lt;/p&gt;&lt;p&gt;Programmatically added entries to the MimetypesFileTypeMap instance. &lt;br /&gt;The file .mime.types in the user&amp;#39;s home directory. &lt;br /&gt;The file &amp;lt;java.home&amp;gt;/lib/mime.types. &lt;br /&gt;The file or resources named META-INF/mime.types. &lt;br /&gt;The file or resource named META-INF/mimetypes.default (usually found only in the activation.jar file). &lt;br /&gt;This method is interesting when you need to deal with incoming files with the filenames normalized. The result is very fast because only the extension is used to guess the nature of a given file. &lt;br /&gt;Using java.net.URL&lt;br /&gt;Warning : this method is very slow!. &lt;br /&gt;Like the above method a match is done with the extension. The mapping between the extension and the mime-type is defined in the file [jre_home]\lib\content-types.properties &lt;/p&gt;&lt;p&gt;import java.net.*;&amp;nbsp; public class FileUtils{&amp;nbsp;&amp;nbsp; public static String getMimeType(String fileUrl)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; throws java.io.IOException, MalformedURLException&amp;nbsp;&amp;nbsp;&amp;nbsp; {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; String type = null;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; URL u = new URL(fileUrl);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; URLConnection uc = null;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; uc = u.openConnection();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; type = uc.getContentType();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return type;&amp;nbsp;&amp;nbsp; }&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void main(String args[]) throws Exception {&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(FileUtils.getMimeType(&amp;quot;&lt;a href=&quot;file:///c:/temp/test.TXT&quot;&gt;file://c:/temp/test.TXT&lt;/a&gt;&amp;quot;));&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // output :&amp;nbsp; text/plain&amp;nbsp;&amp;nbsp; } } &lt;br /&gt;Using JMimeMagic&lt;br /&gt;Checking the file extension is not a very strong way to determine the file type. A more robust solution is possible with the JMimeMagic library. JMimeMagic is a Java library (LGLP licence) that retrieves file and stream mime types by checking magic headers. &lt;br /&gt;// snippet for JMimeMagic lib //&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href=&quot;http://sourceforge.net/projects/jmimemagic/&quot;&gt;http://sourceforge.net/projects/jmimemagic/&lt;/a&gt;&amp;nbsp; Magic parser = new Magic() ; // getMagicMatch accepts Files or byte[],&amp;nbsp; // which is nice if you want to test streams MagicMatch match = parser.getMagicMatch(new File(&amp;quot;gumby.gif&amp;quot;)); System.out.println(match.getMimeType()) ; &lt;br /&gt;Thanks to Jean-Marc Autexier and sygsix for the tip! &lt;br /&gt;Using mime-util&lt;br /&gt;Another tool is mime-util. This tool can detect using the file extension or the magic header technique. &lt;br /&gt;// snippet for mime-util lib //&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;a href=&quot;http://sourceforge.net/projects/mime-util&quot;&gt;http://sourceforge.net/projects/mime-util&lt;/a&gt;&amp;nbsp; public static final String UNKNOWN_MIME_TYPE=&amp;quot;application/x-unknown-mime-type&amp;quot;; ... String mimeType = MimeUtil.getMagicMimeType(file); if(mimeType == null) mimeType = UNKNOWN_MIME_TYPE; &lt;br /&gt;The nice thing about mime-util is that there is no dependency (with others Apache packages) so it is very lightweight. &lt;br /&gt;Using Droid&lt;br /&gt;DROID (Digital Record Object Identification) is a software tool to perform automated batch identification of file formats. &lt;br /&gt;DROID uses internal and external signatures to identify and report the specific file format versions of digital files. These signatures are stored in an XML signature file, generated from information recorded in the PRONOM technical registry. New and updated signatures are regularly added to PRONOM, and DROID can be configured to automatically download updated signature files from the PRONOM website via web services. &lt;/p&gt;&lt;p&gt;It can be invoked from two interfaces, a Java Swing GUI or a command line interface. &lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://droid.sourceforge.net/wiki/index.php/Introduction&quot;&gt;http://droid.sourceforge.net/wiki/index.php/Introduction&lt;/a&gt; &lt;/p&gt;&lt;p&gt;Aperture framework&lt;br /&gt;Aperture is an open source library and framework for crawling and indexing information sources such as file systems, websites and mail boxes. &lt;br /&gt;The Aperture code consists of a number of related but independently usable parts: &lt;/p&gt;&lt;p&gt;Crawling of information sources: file systems, websites, mail boxes &lt;br /&gt;MIME type identification &lt;br /&gt;Full-text and metadata extraction of various file formats &lt;br /&gt;Opening of crawled resources &lt;br /&gt;For each of these parts, a set of APIs has been developed and a number of implementations is provided. &lt;br /&gt;&lt;a href=&quot;http://aperture.wiki.sourceforge.net/Overview&quot;&gt;http://aperture.wiki.sourceforge.net/Overview&lt;/a&gt; &lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;a href=&quot;http://www.rgagnon.com/javadetails/java-0487.html&quot;&gt;http://www.rgagnon.com/javadetails/java-0487.html&lt;/a&gt;&lt;/p&gt;</description>
            <author>海波无痕</author>
            <pubDate>Tue, 26 Feb 2008 07:36:00 +0800</pubDate>
        </item>
        <item>
            <title>Caused by: java.lang.ClassNotFoundException: Class bytes found but defineClass()failed for:</title>
            <link>http://ziki.cn/q/index.php/q-b_uuid-17.html</link>
            <description>&lt;p&gt;Caused by: java.lang.ClassNotFoundException: Class bytes found but defineClass()failed for:&lt;/p&gt;&lt;p&gt;&lt;font face=&quot;宋体&quot; size=&quot;3&quot;&gt;高版本JDK编译的class在低版本JDK下无法运行&lt;/font&gt;&lt;/p&gt;</description>
            <author>海波无痕</author>
            <pubDate>Thu, 17 Jan 2008 08:29:51 +0800</pubDate>
        </item>
        <item>
            <title>JAVA根据日期获取星期几</title>
            <link>http://ziki.cn/q/index.php/q-b_uuid-4.html</link>
            <description>&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Date dat = new java.util.Date();&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;java.util.Calendar cal = java.util.Calendar.getInstance();&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;cal.setTime(dat);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;int w=cal.get(java.util.Calendar.DAY_OF_WEEK)-1;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;if(w==0)w=7;&lt;br /&gt;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;System.out.println(w);&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;  //out 1,2,3&lt;br /&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; //SimpleDateFormat&amp;nbsp;&amp;nbsp; sd&amp;nbsp;&amp;nbsp; &lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; =&amp;nbsp;&amp;nbsp; new&amp;nbsp;&amp;nbsp; SimpleDateFormat(&amp;quot;EEE&amp;quot;);&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; //System.out.println(sd.format(dat));&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;  //out 星期一 &lt;/p&gt;</description>
            <author>海波无痕</author>
            <pubDate>Thu, 15 Nov 2007 13:03:49 +0800</pubDate>
        </item>
        <item>
            <title>JAVA竖线转义符号</title>
            <link>http://ziki.cn/q/index.php/q-b_uuid-2.html</link>
            <description>&lt;span style=&quot;font-family: Georgia&quot;&gt;Java 竖线|的转义符 是 &amp;quot;\\|&amp;quot;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Georgia&quot;&gt;如下操作&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Georgia&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String a = &amp;quot;a|b|c|d&amp;quot;;&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Georgia&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; String[] b = a.split(&amp;quot;\\|&amp;quot;);//直接使用a.split(&amp;quot;|&amp;quot;)是错误的&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Georgia&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Georgia&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; for(int i=0;i&amp;lt;b.length;i++){&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Georgia&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; System.out.println(b[i]);&lt;/span&gt;&lt;br /&gt;&lt;span style=&quot;font-family: Georgia&quot;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/span&gt;</description>
            <author>海波无痕</author>
            <pubDate>Sun, 04 Nov 2007 13:59:52 +0800</pubDate>
        </item>
    </channel>
</rss>
