Here you can find the source of lookupPrintNames(PrintService[] prtSrvs)
public static String[] lookupPrintNames(PrintService[] prtSrvs)
//package com.java2s; /*//from w w w . j a va2 s . c o m * Copyright (C) 2015 University of Oregon * * You may distribute under the terms of either the GNU General Public * License or the Apache License, as specified in the LICENSE file. * * For more information, see the LICENSE file. */ import java.io.*; import javax.print.*; public class Main { private static String[] psList; private static boolean bWaitForPrinterServer = false; private static PrintService[] printSrvs = null; private static long lastQueryTime_all = 0; public static String[] lookupPrintNames(PrintService[] prtSrvs) { int i, n; int total = 0; String[] psnames; int nums = 6; String name; if (prtSrvs != null) { nums += prtSrvs.length; } psnames = new String[nums]; if (prtSrvs != null) { for (n = 0; n < prtSrvs.length; n++) { if (prtSrvs[n] != null) { name = prtSrvs[n].getName(); if (name != null) { if (isGoodPrinterName(name)) psnames[total++] = name; } } } } String cupsPath = new StringBuffer().append(File.separator) .append("etc").append(File.separator).append("cups") .append(File.separator).append("ppd").toString(); File dir = new File(cupsPath); File files[] = null; if (dir.exists() && dir.isDirectory()) if (dir.canRead()) files = dir.listFiles(); if (files != null) { for (i = 0; i < files.length; i++) { if (files[i].isFile()) { String fname = files[i].getName(); if (fname.endsWith(".ppd")) { name = fname.substring(0, fname.indexOf(".ppd")); if (name.length() > 0) { for (n = 0; n < nums; n++) { if (psnames[n] != null) { if (name.equals(psnames[n])) { name = null; break; } } } if (name != null && total < nums) { psnames[total++] = name; } } } if (total >= nums) break; } } } if (total > 0) { psList = new String[total]; for (i = 0; i < total; i++) psList[i] = psnames[i]; } return psList; } public static String[] lookupPrintNames() { lookupPrintServices(); return lookupPrintNames(printSrvs); } public static boolean isGoodPrinterName(String name) { if (name == null) return false; if (name.equals("jeff_pl") || name.equals("jeff_pr")) return false; if (name.equals("steve_pl") || name.equals("steve_pr")) return false; return true; } public static PrintService[] lookupPrintServices() { if (bWaitForPrinterServer) return printSrvs; bWaitForPrinterServer = true; if (printSrvs == null || printSrvs.length < 1) { long t = System.currentTimeMillis() / 1000; if ((t - lastQueryTime_all) < 120) { bWaitForPrinterServer = false; return printSrvs; } printSrvs = PrintServiceLookup.lookupPrintServices(null, null); lastQueryTime_all = System.currentTimeMillis() / 1000; } bWaitForPrinterServer = false; return printSrvs; } }