Java by API/javax.print.attribute/Attribute
Версия от 17:43, 31 мая 2010; (обсуждение)
Attribute: getName()
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.lang.reflect.Array;
import javax.print.DocFlavor;
import javax.print.StreamPrintService;
import javax.print.StreamPrintServiceFactory;
import javax.print.attribute.Attribute;
public class Main {
public static void main(String[] argv) throws Exception {
OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps"));
DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
StreamPrintServiceFactory[] factories = StreamPrintServiceFactory
.lookupStreamPrintServiceFactories(flavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType());
StreamPrintService service = factories[0].getPrintService(fos);
Class[] cats = service.getSupportedAttributeCategories();
for (int j = 0; j < cats.length; j++) {
Attribute attr = (Attribute) service.getDefaultAttributeValue(cats[j]);
if (attr != null) {
String attrName = attr.getName();
String attrValue = attr.toString();
Object o = service.getSupportedAttributeValues(attr.getCategory(), null, null);
if (o.getClass().isArray()) {
for (int k = 0; k < Array.getLength(o); k++) {
Object o2 = Array.get(o, k);
System.out.println(o2);
}
}
}
}
}
}