2011-08-15 145 views
-1

Ubuntu的10.4 JRE 1.6.0_26
SaxonHE9.3.0.5撒克遜投擲java.net.SocketException異常:

我有一個非常簡單的腳本,它可以提取有效的HTML文件中的文本內容

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     xmlns:html="http://www.w3.org/1999/html" 
     version="2.0"> 
    <xsl:output method="text" encoding="utf-8"/> 
</xsl:stylesheet> 

在氧氣中運行此腳本會產生預期的輸出。

用java相同版本和薩克森像這樣

的java命令行上在同一臺PC上運行這個罐子的lib/saxonHE-9.3.0.5.jar -o:建立/ etemp/html_1.txt -s:構建/電子書/ epub_sh-tei.html -xsl:XSLT/htm2text.xsl

輸出下列錯誤

錯誤 java.net.SocketException異常:從服務器 變換意外的文件結尾失敗:報告運行時錯誤

下面

是從Java

[Loaded net.sf.saxon.tinytree.TinyProcInstImpl from file:/home/scott/workspace/books_changes2/lib/saxonHE-9.3.0.5.jar] 
[Loaded net.sf.saxon.tinytree.LargeStringBuffer from file:/home/scott/workspace/books_changes2/lib/saxonHE-9.3.0.5.jar] 
[Loaded java.lang.ArrayIndexOutOfBoundsException from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded com.sun.org.apache.xerces.internal.impl.io.ASCIIReader from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded com.sun.org.apache.xerces.internal.impl.validation.EntityState from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded com.sun.org.apache.xerces.internal.xni.grammars.Grammar from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded com.sun.org.apache.xerces.internal.impl.dtd.DTDGrammar from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded com.sun.org.apache.xerces.internal.impl.dtd.models.ContentModelValidator from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded com.sun.org.apache.xerces.internal.impl.dtd.DTDGrammar$QNameHashtable from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded com.sun.org.apache.xerces.internal.impl.dtd.XMLContentSpec from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$DTDDriver from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded com.sun.xml.internal.stream.StaxXMLInputSource from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.www.protocol.http.Handler from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.www.protocol.http.HttpURLConnection from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.logging.Logger from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.logging.Handler from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.logging.Level from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.logging.LogManager from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.logging.LogManager$1 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.beans.PropertyChangeSupport from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.logging.LogManager$LogNode from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.logging.LoggingPermission from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.logging.LogManager$Cleaner from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.lang.ApplicationShutdownHooks from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.lang.ApplicationShutdownHooks$1 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.lang.Shutdown from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.lang.Shutdown$Lock from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.IdentityHashMap from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.logging.LogManager$RootLogger from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.logging.LogManager$2 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.Hashtable$Enumerator from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.EventObject from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.beans.PropertyChangeEvent from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.logging.LogManager$3 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.security.action.GetIntegerAction from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.www.protocol.http.AuthCacheValue from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.www.protocol.http.AuthenticationInfo from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.www.protocol.http.NTLMAuthentication from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.www.protocol.http.AuthCache from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.www.protocol.http.AuthCacheImpl from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.www.protocol.http.NTLMAuthenticationCallback from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.www.protocol.http.NTLMAuthenticationCallback$DefaultNTLMAuthenticationCallback from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.www.protocol.http.NTLMAuthentication$1 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.www.protocol.http.HttpURLConnection$TunnelState from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.www.protocol.http.HttpURLConnection$2 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.CookieHandler from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.www.protocol.http.HttpURLConnection$3 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.ResponseCache from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded com.sun.org.apache.xerces.internal.util.HTTPInputSource from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.www.protocol.http.HttpURLConnection$5 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.ProxySelector from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.spi.DefaultProxySelector from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.spi.DefaultProxySelector$1 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.NetProperties from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.NetProperties$1 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.spi.DefaultProxySelector$NonProxyInfo from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.spi.DefaultProxySelector$2 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.spi.DefaultProxySelector$3 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.Proxy from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.Proxy$Type from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.NetworkClient from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.www.http.HttpClient from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.NetworkClient$1 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.www.http.KeepAliveCache from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.www.http.HttpClient$1 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.www.http.HttpClient$2 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.www.http.KeepAliveKey from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.www.http.HttpClient$3 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.Socket from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.SocksConsts from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.SocketOptions from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.SocketImpl from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.PlainSocketImpl from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.SocksSocketImpl from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.security.action.LoadLibraryAction from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.SocketAddress from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.InetSocketAddress from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.InetAddress from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.InetAddress$Cache from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.InetAddress$Cache$Type from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.InetAddressImplFactory from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.InetAddressImpl from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.Inet6AddressImpl from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.spi.nameservice.NameService from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.InetAddress$1 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.Inet4AddressImpl from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.Inet4Address from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.InetAddressCachePolicy from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.InetAddressCachePolicy$1 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded sun.net.InetAddressCachePolicy$2 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.Queue from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.Deque from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.AbstractSequentialList from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.LinkedList from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.LinkedList$Entry from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.LinkedHashMap$KeyIterator from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.LinkedList$ListItr from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.InetAddress$CacheEntry from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.Inet6Address from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.SocketException from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.SocksSocketImpl$5 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.Socket$3 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.SocketOutputStream from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.Socket$2 from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.SocketInputStream from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.io.InterruptedIOException from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.net.SocketTimeoutException from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.io.EOFException from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded com.sun.org.apache.xerces.internal.xni.parser.XMLParseException from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
Error 
    java.net.SocketException: Unexpected end of file from server 
Transformation failed: Run-time errors were reported 
[Loaded java.util.IdentityHashMap$KeySet from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.IdentityHashMap$IdentityHashMapIterator from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 
[Loaded java.util.IdentityHashMap$KeyIterator from /usr/lib/jvm/java-6-sun-1.6.0.26/jre/lib/rt.jar] 

回答

1

對於那些尋找一個答案:

的這個問題的答案是,解析器試圖從這裏http://www.w3.org/1999/html的HTML DTD的聲明在樣式表中。

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     xmlns:html="http://www.w3.org/1999/html" 
     version="2.0"> 
    <xsl:output method="text" encoding="utf-8"/> 
</xsl:stylesheet> 

W3忽略了請求,java拋出異常。解析器沒有表明它正在請求dtd,也沒有收到dtd。關於爲什麼轉換失敗,將用戶留在外面的黑暗中。解析器的行爲非常糟糕!

解決的辦法是告訴解析器使用本地的DTD,通過目錄,像這樣,這是從ant腳本:

<macrodef name="saxon_use_catalog"> 
    <attribute name="input"/> 
    <attribute name="stylesheet"/> 
    <attribute name="output"/> 
    <sequential> 
     <echo>Transforming @{input} to @{output} using @{stylesheet} </echo> 
     <java classname="net.sf.saxon.Transform" fork="true" failonerror="true"> 
      <jvmarg value="-Dxml.catalog.files=lib/xhtml11/dtd/xhtmlcatalog.xml" /> 
      <classpath> 
       <pathelement location="lib/saxonHE-9.3.0.5.jar"/> 
       <pathelement location="lib/resolver.jar"/> 
       <pathelement location="lib/xhtml11/dtd/xhtmlcatalog.xml"/> 
      </classpath> 
      <arg value="-r:org.apache.xml.resolver.tools.CatalogResolver"/> 
      <arg value="-x:org.apache.xml.resolver.tools.ResolvingXMLReader"/> 
      <arg value="-y:org.apache.xml.resolver.tools.ResolvingXMLReader"/> 
      <arg value="-s:@{input}"/> 
      <arg value="-xsl:@{stylesheet}"/> 
      <arg value="-o:@{output}"/> 
     </java> 
    </sequential> 
</macrodef> 

我所使用的解析器的jar和目錄包裝中的氧氣。

斯科特

1

請不要問你能想到的每一個論壇同樣的問題輸出的詳細。選擇最合適的,在那裏詢問,如果沒有迴應,只能轉向別處。在多個地方詢問正在浪費自願幫助你的人的時間,因爲他們看不到這個問題已經在別處得到解答。由於這個原因降低了這個問題。

+0

邁克爾,這很容易讓你說。但是當你按照一個時間表,你試圖儘快得到答案。它可以張貼到2或3個網站,希望其中一個會提出正確的答案,你這樣做。 – Scott

+2

那麼,如果你想疏遠那些有時間回答問題的有幫助的人的小社區,這取決於你。但是我發現人們不認識到需要在現實生活中自動接觸到的電子交互中表現出相同的禮貌。 –