Java Printer Usage lookupPrintServices()

Here you can find the source of lookupPrintServices()

Description

lookup Print Services

License

GNU General Public License

Declaration

public static PrintService[] lookupPrintServices() 

Method Source Code

//package com.java2s;
/*//from w  w w  .j  av  a  2 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 javax.print.*;

public class Main {
    private static boolean bWaitForPrinterServer = false;
    private static PrintService[] printSrvs = null;
    private static long lastQueryTime_all = 0;

    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;
    }
}

Related

  1. getSupportedAttrName(Class clazz)
  2. isValueSupported(PrintService ps, Attribute attr, DocFlavor flavor, AttributeSet attributes)
  3. lookupMediaSize(final Media media)
  4. lookupPrintNames(PrintService[] prtSrvs)
  5. lookupPrintService()
  6. notInArray(PrintService key, PrintService[] array)
  7. print(PrintService printService, byte[] pdf)
  8. refreshPrinterList()
  9. showAttributes(PrintRequestAttributeSet aset)