1 /*
   2  * Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package javax.print.attribute.standard;
  27 
  28 import javax.print.attribute.Attribute;
  29 import javax.print.attribute.IntegerSyntax;
  30 import javax.print.attribute.PrintJobAttribute;
  31 import javax.print.attribute.PrintRequestAttribute;
  32 
  33 /**
  34  * Class {@code JobKOctets} is an integer valued printing attribute class that
  35  * specifies the total size of the document(s) in K octets, i.e., in units of
  36  * 1024 octets requested to be processed in the job. The value must be rounded
  37  * up, so that a job between 1 and 1024 octets must be indicated as being 1K
  38  * octets, 1025 to 2048 must be 2K octets, etc. For a multidoc print job (a job
  39  * with multiple documents), the {@code JobKOctets} value is computed by adding
  40  * up the individual documents' sizes in octets, then rounding up to the next K
  41  * octets value.
  42  * <p>
  43  * The {@code JobKOctets} attribute describes the size of the job. This
  44  * attribute is not intended to be a counter; it is intended to be useful
  45  * routing and scheduling information if known. The printer may try to compute
  46  * the {@code JobKOctets} attribute's value if it is not supplied in the Print
  47  * Request. Even if the client does supply a value for the {@code JobKOctets}
  48  * attribute in the Print Request, the printer may choose to change the value if
  49  * the printer is able to compute a value which is more accurate than the client
  50  * supplied value. The printer may be able to determine the correct value for
  51  * the {@code JobKOctets} attribute either right at job submission time or at
  52  * any later point in time.
  53  * <p>
  54  * The {@code JobKOctets} value must not include the multiplicative factors
  55  * contributed by the number of copies specified by the {@link Copies Copies}
  56  * attribute, independent of whether the device can process multiple copies
  57  * without making multiple passes over the job or document data and independent
  58  * of whether the output is collated or not. Thus the value is independent of
  59  * the implementation and indicates the size of the document(s) measured in K
  60  * octets independent of the number of copies.
  61  * <p>
  62  * The {@code JobKOctets} value must also not include the multiplicative factor
  63  * due to a copies instruction embedded in the document data. If the document
  64  * data actually includes replications of the document data, this value will
  65  * include such replication. In other words, this value is always the size of
  66  * the source document data, rather than a measure of the hardcopy output to be
  67  * produced.
  68  * <p>
  69  * The size of a doc is computed based on the print data representation class as
  70  * specified by the doc's {@link javax.print.DocFlavor DocFlavor}, as shown in
  71  * the table below.
  72  * <table class="striped">
  73  * <caption>Table showing computation of doc sizes</caption>
  74  * <thead>
  75  *   <tr>
  76  *     <th>Representation Class
  77  *     <th>Document Size
  78  * </thead>
  79  * <tbody>
  80  *   <tr>
  81  *     <td>{@code byte[]}
  82  *     <td>Length of the byte array
  83  *   <tr>
  84  *     <td>{@code java.io.InputStream}
  85  *     <td>Number of bytes read from the stream
  86  *   <tr>
  87  *     <td>{@code char[]}
  88  *     <td>Length of the character array x 2
  89  *   <tr>
  90  *     <td>{@code java.lang.String}
  91  *     <td>Length of the string x 2
  92  *   <tr>
  93  *     <td>{@code java.io.Reader}
  94  *     <td>Number of characters read from the stream x 2
  95  *   <tr>
  96  *     <td>{@code java.net.URL}
  97  *     <td>Number of bytes read from the file at the given {@code URL} address
  98  *   <tr>
  99  *     <td>{@code java.awt.image.renderable.RenderableImage}
 100  *     <td>Implementation dependent*
 101  *   <tr>
 102  *     <td>{@code java.awt.print.Printable}
 103  *     <td>Implementation dependent*
 104  *   <tr>
 105  *     <td>{@code java.awt.print.Pageable}
 106  *     <td>Implementation dependent*
 107  * </tbody>
 108  * </table>
 109  * <p>
 110  * * In these cases the Print Service itself generates the print data sent
 111  * to the printer. If the Print Service supports the {@code JobKOctets}
 112  * attribute, for these cases the Print Service itself must calculate the size
 113  * of the print data, replacing any {@code JobKOctets} value the client
 114  * specified.
 115  * <p>
 116  * <b>IPP Compatibility:</b> The integer value gives the IPP integer value. The
 117  * category name returned by {@code getName()} gives the IPP attribute name.
 118  *
 119  * @author Alan Kaminsky
 120  * @see JobKOctetsSupported
 121  * @see JobKOctetsProcessed
 122  * @see JobImpressions
 123  * @see JobMediaSheets
 124  */
 125 public final class JobKOctets   extends IntegerSyntax
 126         implements PrintRequestAttribute, PrintJobAttribute {
 127 
 128     /**
 129      * Use serialVersionUID from JDK 1.4 for interoperability.
 130      */
 131     private static final long serialVersionUID = -8959710146498202869L;
 132 
 133     /**
 134      * Construct a new job K octets attribute with the given integer value.
 135      *
 136      * @param  value Integer value
 137      * @throws IllegalArgumentException if {@code value} is negative
 138      */
 139     public JobKOctets(int value) {
 140         super (value, 0, Integer.MAX_VALUE);
 141     }
 142 
 143     /**
 144      * Returns whether this job K octets attribute is equivalent to the passed
 145      * in object. To be equivalent, all of the following conditions must be
 146      * true:
 147      * <ol type=1>
 148      *   <li>{@code object} is not {@code null}.
 149      *   <li>{@code object} is an instance of class {@code JobKOctets}.
 150      *   <li>This job K octets attribute's value and {@code object}'s value are
 151      *   equal.
 152      * </ol>
 153      *
 154      * @param  object {@code Object} to compare to
 155      * @return {@code true} if {@code object} is equivalent to this job K octets
 156      *         attribute, {@code false} otherwise
 157      */
 158     public boolean equals(Object object) {
 159         return super.equals(object) && object instanceof JobKOctets;
 160     }
 161 
 162     /**
 163      * Get the printing attribute class which is to be used as the "category"
 164      * for this printing attribute value.
 165      * <p>
 166      * For class {@code JobKOctets}, the category is class
 167      * {@code JobKOctets} itself.
 168      *
 169      * @return printing attribute class (category), an instance of class
 170      *         {@link Class java.lang.Class}
 171      */
 172     public final Class<? extends Attribute> getCategory() {
 173         return JobKOctets.class;
 174     }
 175 
 176     /**
 177      * Get the name of the category of which this attribute value is an
 178      * instance.
 179      * <p>
 180      * For class {@code JobKOctets}, the category name is
 181      * {@code "job-k-octets"}.
 182      *
 183      * @return attribute category name
 184      */
 185     public final String getName() {
 186         return "job-k-octets";
 187     }
 188 }