0

我们在获取 RHL 上的打印机列表时遇到了这个奇怪的问题。我写了一小段代码来演示发生了什么:

import java.io.File;
import java.io.FileInputStream;
import java.io.PrintStream;
import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocFlavor.INPUT_STREAM;
import javax.print.DocPrintJob;
import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.SimpleDoc;

public class PrintTest
{
  public static void main(String[] args)
  {
      PrintService[] pservices = PrintServiceLookup.lookupPrintServices(null, null);
      System.out.println(pservices.length);

      for( int y = 0; y < pservices.length; y++ ){
        System.out.print(y + " - " );
        System.out.println(pservices[y]);
      }
  }
}

这是结果:

0 - IPP Printer : PPR403_2
1 - IPP Printer : PPR413_2
2 - IPP Printer : PPR506_7
3 - IPP Printer : PPR509_7
4 - IPP Printer : PPR510_2
5 - IPP Printer : PPR516_1
6
0 - IPP Printer : PPR403_2
1 - IPP Printer : PPR413_2
2 - IPP Printer : PPR506_7
3 - IPP Printer : PPR509_7
4 - IPP Printer : PPR510_2
5 - IPP Printer : PPR516_1
6
0 - IPP Printer : PPR403_2
1 - IPP Printer : PPR413_2
2 - IPP Printer : PPR506_7
3 - IPP Printer : PPR509_7
4 - IPP Printer : PPR510_2
5 - IPP Printer : PPR516_1
6
0 - IPP Printer : PPR403_2
1 - IPP Printer : PPR413_2
2 - IPP Printer : PPR506_7
3 - IPP Printer : PPR509_7
4 - IPP Printer : PPR510_2
5 - IPP Printer : PPR516_1
6
0 - IPP Printer : PPR403_2
1 - IPP Printer : PPR413_2
2 - IPP Printer : PPR506_7
3 - IPP Printer : PPR509_7
4 - IPP Printer : PPR510_2
5 - IPP Printer : PPR516_1
6
0 - IPP Printer : PPR403_2
1 - IPP Printer : PPR413_2
2 - IPP Printer : PPR506_7
3 - IPP Printer : PPR509_7
4 - IPP Printer : PPR510_2
5 - IPP Printer : PPR516_1
6
0 - IPP Printer : PPR403_2
1 - IPP Printer : PPR413_2
2 - IPP Printer : PPR506_7
3 - IPP Printer : PPR509_7
4 - IPP Printer : PPR510_2
5 - IPP Printer : PPR516_1
6
0 - null
1 - null
2 - null
3 - null
4 - null
5 - null
6
0 - IPP Printer : PPR403_2
1 - IPP Printer : PPR413_2
2 - IPP Printer : PPR506_7
3 - IPP Printer : PPR509_7
4 - IPP Printer : PPR510_2
5 - IPP Printer : PPR516_1
6
0 - IPP Printer : PPR403_2
1 - IPP Printer : PPR413_2
2 - IPP Printer : PPR506_7
3 - IPP Printer : PPR509_7
4 - IPP Printer : PPR510_2
5 - IPP Printer : PPR516_1
6
0 - null
1 - null
2 - null
3 - null
4 - null
5 - null

(我连续多次运行代码)。

如您所见,有时我们可以得到一个打印机列表(系统上配置了 6 个),有时我们得到一个长度为 6 的数组,但没有对象,只有空值:/。

请帮我诊断一下我在谷歌上快速搜索过的问题,但似乎没有什么适合这个。

这是服务器上的 java 版本: java 版本 "1.5.0_30" Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_30-b03) Java HotSpot(TM) 64-Bit Server VM (build 1.5.0_30-b03) , 混合模式)

不幸的是,我无法改变这一点。

编辑:这是来自 CUPS 的日志(不知道是否重要):

D [04/Jan/2013:16:31:25 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:25 +0100] cupsdAcceptClient: 8 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:25 +0100] cupsdCloseClient: 8
D [04/Jan/2013:16:31:25 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:25 +0100] cupsdAcceptClient: 8 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:25 +0100] cupsdCloseClient: 8
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 8 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdReadClient: 8 POST / HTTP/1.1
D [04/Jan/2013:16:31:26 +0100] cupsdAuthorize: No authentication data provided.
D [04/Jan/2013:16:31:26 +0100] CUPS-Get-Default
D [04/Jan/2013:16:31:26 +0100] CUPS-Get-Default client-error-not-found: No default printer
D [04/Jan/2013:16:31:26 +0100] cupsdProcessIPPRequest: 8 status_code=406 (client-error-not-found)
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 10 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 10
D [04/Jan/2013:16:31:26 +0100] cupsdReadClient: 8 POST / HTTP/1.1
D [04/Jan/2013:16:31:26 +0100] cupsdAuthorize: No authentication data provided.
D [04/Jan/2013:16:31:26 +0100] CUPS-Get-Printers
D [04/Jan/2013:16:31:26 +0100] cupsdProcessIPPRequest: 8 status_code=0 (successful-ok)
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 10 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 10
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 10 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 10
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 10 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 10
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 10 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 10
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 10 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 10
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 10 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 10
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 10 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 10
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 10 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 10
D [04/Jan/2013:16:31:26 +0100] cupsdReadClient: 8 POST / HTTP/1.1
D [04/Jan/2013:16:31:26 +0100] cupsdAuthorize: No authentication data provided.
D [04/Jan/2013:16:31:26 +0100] CUPS-Get-Default
D [04/Jan/2013:16:31:26 +0100] CUPS-Get-Default client-error-not-found: No default printer
D [04/Jan/2013:16:31:26 +0100] cupsdProcessIPPRequest: 8 status_code=406 (client-error-not-found)
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: skipping getpeercon()
D [04/Jan/2013:16:31:26 +0100] cupsdAcceptClient: 10 from localhost:631 (IPv4)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 10
D [04/Jan/2013:16:31:26 +0100] cupsdReadClient: 8 POST / HTTP/1.1
D [04/Jan/2013:16:31:26 +0100] cupsdAuthorize: No authentication data provided.
D [04/Jan/2013:16:31:26 +0100] CUPS-Get-Printers
D [04/Jan/2013:16:31:26 +0100] cupsdProcessIPPRequest: 8 status_code=0 (successful-ok)
D [04/Jan/2013:16:31:26 +0100] cupsdCloseClient: 8
4

1 回答 1

0

unix/linux 平台上的 CUPS 和 java jre 存在问题,要查看更多信息,您可以设置sun.print.ippdebugtrue. 在您的情况下,它看起来像jre 中的这个错误,因此设置sun.java2d.print.pollingtrue应该会有所帮助。

于 2013-04-26T10:56:23.300 回答