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  *
  73  * <table class="striped">
  74  * <caption>Table showing computation of doc sizes</caption>
  75  * <thead>
  76  *   <tr>
  77  *     <th scope="col">Representation Class
  78  *     <th scope="col">Document Size
  79  * </thead>
  80  * <tbody>
  81  *   <tr>
  82  *     <th scope="row">{@code byte[]}
  83  *     <td>Length of the byte array
  84  *   <tr>
  85  *     <th scope="row">{@code java.io.InputStream}
  86  *     <td>Number of bytes read from the stream
  87  *   <tr>
  88  *     <th scope="row">{@code char[]}
  89  *     <td>Length of the character array x 2
  90  *   <tr>
  91  *     <th scope="row">{@code java.lang.String}
  92  *     <td>Length of the string x 2
  93  *   <tr>
  94  *     <th scope="row">{@code java.io.Reader}
  95  *     <td>Number of characters read from the stream x 2
  96  *   <tr>
  97  *     <th scope="row">{@code java.net.URL}
  98  *     <td>Number of bytes read from the file at the given {@code URL} address
  99  *   <tr>
 100  *     <th scope="row">{@code java.awt.image.renderable.RenderableImage}
 101  *     <td>Implementation dependent*
 102  *   <tr>
 103  *     <th scope="row">{@code java.awt.print.Printable}
 104  *     <td>Implementation dependent*
 105  *   <tr>
 106  *     <th scope="row">{@code java.awt.print.Pageable}
 107  *     <td>Implementation dependent*
 108  * </tbody>
 109  * </table>
 110  * <p>
 111  * * In these cases the Print Service itself generates the print data sent
 112  * to the printer. If the Print Service supports the {@code JobKOctets}
 113  * attribute, for these cases the Print Service itself must calculate the size
 114  * of the print data, replacing any {@code JobKOctets} value the client
 115  * specified.
 116  * <p>
 117  * <b>IPP Compatibility:</b> The integer value gives the IPP integer value. The
 118  * category name returned by {@code getName()} gives the IPP attribute name.
 119  *
 120  * @author Alan Kaminsky
 121  * @see JobKOctetsSupported
 122  * @see JobKOctetsProcessed
 123  * @see JobImpressions
 124  * @see JobMediaSheets
 125  */
 126 public final class JobKOctets   extends IntegerSyntax
 127         implements PrintRequestAttribute, PrintJobAttribute {
 128 
 129     /**
 130      * Use serialVersionUID from JDK 1.4 for interoperability.
 131      */
 132     private static final long serialVersionUID = -8959710146498202869L;
 133 
 134     /**
 135      * Construct a new job K octets attribute with the given integer value.
 136      *
 137      * @param  value Integer value
 138      * @throws IllegalArgumentException if {@code value} is negative
 139      */
 140     public JobKOctets(int value) {
 141         super (value, 0, Integer.MAX_VALUE);
 142     }
 143 
 144     /**
 145      * Returns whether this job K octets attribute is equivalent to the passed
 146      * in object. To be equivalent, all of the following conditions must be
 147      * true:
 148      * <ol type=1>
 149      *   <li>{@code object} is not {@code null}.
 150      *   <li>{@code object} is an instance of class {@code JobKOctets}.
 151      *   <li>This job K octets attribute's value and {@code object}'s value are
 152      *   equal.
 153      * </ol>
 154      *
 155      * @param  object {@code Object} to compare to
 156      * @return {@code true} if {@code object} is equivalent to this job K octets
 157      *         attribute, {@code false} otherwise
 158      */
 159     public boolean equals(Object object) {
 160         return super.equals(object) && object instanceof JobKOctets;
 161     }
 162 
 163     /**
 164      * Get the printing attribute class which is to be used as the "category"
 165      * for this printing attribute value.
 166      * <p>
 167      * For class {@code JobKOctets}, the category is class
 168      * {@code JobKOctets} itself.
 169      *
 170      * @return printing attribute class (category), an instance of class
 171      *         {@link Class java.lang.Class}
 172      */
 173     public final Class<? extends Attribute> getCategory() {
 174         return JobKOctets.class;
 175     }
 176 
 177     /**
 178      * Get the name of the category of which this attribute value is an
 179      * instance.
 180      * <p>
 181      * For class {@code JobKOctets}, the category name is
 182      * {@code "job-k-octets"}.
 183      *
 184      * @return attribute category name
 185      */
 186     public final String getName() {
 187         return "job-k-octets";
 188     }
 189 }