Path: blob/master/src/java.desktop/share/classes/javax/print/attribute/standard/JobKOctets.java
41171 views
/*1* Copyright (c) 2000, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.print.attribute.standard;2627import java.io.Serial;2829import javax.print.attribute.Attribute;30import javax.print.attribute.IntegerSyntax;31import javax.print.attribute.PrintJobAttribute;32import javax.print.attribute.PrintRequestAttribute;3334/**35* Class {@code JobKOctets} is an integer valued printing attribute class that36* specifies the total size of the document(s) in K octets, i.e., in units of37* 1024 octets requested to be processed in the job. The value must be rounded38* up, so that a job between 1 and 1024 octets must be indicated as being 1K39* octets, 1025 to 2048 must be 2K octets, etc. For a multidoc print job (a job40* with multiple documents), the {@code JobKOctets} value is computed by adding41* up the individual documents' sizes in octets, then rounding up to the next K42* octets value.43* <p>44* The {@code JobKOctets} attribute describes the size of the job. This45* attribute is not intended to be a counter; it is intended to be useful46* routing and scheduling information if known. The printer may try to compute47* the {@code JobKOctets} attribute's value if it is not supplied in the Print48* Request. Even if the client does supply a value for the {@code JobKOctets}49* attribute in the Print Request, the printer may choose to change the value if50* the printer is able to compute a value which is more accurate than the client51* supplied value. The printer may be able to determine the correct value for52* the {@code JobKOctets} attribute either right at job submission time or at53* any later point in time.54* <p>55* The {@code JobKOctets} value must not include the multiplicative factors56* contributed by the number of copies specified by the {@link Copies Copies}57* attribute, independent of whether the device can process multiple copies58* without making multiple passes over the job or document data and independent59* of whether the output is collated or not. Thus the value is independent of60* the implementation and indicates the size of the document(s) measured in K61* octets independent of the number of copies.62* <p>63* The {@code JobKOctets} value must also not include the multiplicative factor64* due to a copies instruction embedded in the document data. If the document65* data actually includes replications of the document data, this value will66* include such replication. In other words, this value is always the size of67* the source document data, rather than a measure of the hardcopy output to be68* produced.69* <p>70* The size of a doc is computed based on the print data representation class as71* specified by the doc's {@link javax.print.DocFlavor DocFlavor}, as shown in72* the table below.73*74* <table class="striped">75* <caption>Table showing computation of doc sizes</caption>76* <thead>77* <tr>78* <th scope="col">Representation Class79* <th scope="col">Document Size80* </thead>81* <tbody>82* <tr>83* <th scope="row">{@code byte[]}84* <td>Length of the byte array85* <tr>86* <th scope="row">{@code java.io.InputStream}87* <td>Number of bytes read from the stream88* <tr>89* <th scope="row">{@code char[]}90* <td>Length of the character array x 291* <tr>92* <th scope="row">{@code java.lang.String}93* <td>Length of the string x 294* <tr>95* <th scope="row">{@code java.io.Reader}96* <td>Number of characters read from the stream x 297* <tr>98* <th scope="row">{@code java.net.URL}99* <td>Number of bytes read from the file at the given {@code URL} address100* <tr>101* <th scope="row">{@code java.awt.image.renderable.RenderableImage}102* <td>Implementation dependent*103* <tr>104* <th scope="row">{@code java.awt.print.Printable}105* <td>Implementation dependent*106* <tr>107* <th scope="row">{@code java.awt.print.Pageable}108* <td>Implementation dependent*109* </tbody>110* </table>111* <p>112* * In these cases the Print Service itself generates the print data sent113* to the printer. If the Print Service supports the {@code JobKOctets}114* attribute, for these cases the Print Service itself must calculate the size115* of the print data, replacing any {@code JobKOctets} value the client116* specified.117* <p>118* <b>IPP Compatibility:</b> The integer value gives the IPP integer value. The119* category name returned by {@code getName()} gives the IPP attribute name.120*121* @author Alan Kaminsky122* @see JobKOctetsSupported123* @see JobKOctetsProcessed124* @see JobImpressions125* @see JobMediaSheets126*/127public final class JobKOctets extends IntegerSyntax128implements PrintRequestAttribute, PrintJobAttribute {129130/**131* Use serialVersionUID from JDK 1.4 for interoperability.132*/133@Serial134private static final long serialVersionUID = -8959710146498202869L;135136/**137* Construct a new job K octets attribute with the given integer value.138*139* @param value Integer value140* @throws IllegalArgumentException if {@code value} is negative141*/142public JobKOctets(int value) {143super (value, 0, Integer.MAX_VALUE);144}145146/**147* Returns whether this job K octets attribute is equivalent to the passed148* in object. To be equivalent, all of the following conditions must be149* true:150* <ol type=1>151* <li>{@code object} is not {@code null}.152* <li>{@code object} is an instance of class {@code JobKOctets}.153* <li>This job K octets attribute's value and {@code object}'s value are154* equal.155* </ol>156*157* @param object {@code Object} to compare to158* @return {@code true} if {@code object} is equivalent to this job K octets159* attribute, {@code false} otherwise160*/161public boolean equals(Object object) {162return super.equals(object) && object instanceof JobKOctets;163}164165/**166* Get the printing attribute class which is to be used as the "category"167* for this printing attribute value.168* <p>169* For class {@code JobKOctets}, the category is class170* {@code JobKOctets} itself.171*172* @return printing attribute class (category), an instance of class173* {@link Class java.lang.Class}174*/175public final Class<? extends Attribute> getCategory() {176return JobKOctets.class;177}178179/**180* Get the name of the category of which this attribute value is an181* instance.182* <p>183* For class {@code JobKOctets}, the category name is184* {@code "job-k-octets"}.185*186* @return attribute category name187*/188public final String getName() {189return "job-k-octets";190}191}192193194