Example usage for java.io BufferedOutputStream BufferedOutputStream

List of usage examples for java.io BufferedOutputStream BufferedOutputStream

Introduction

In this page you can find the example usage for java.io BufferedOutputStream BufferedOutputStream.

Prototype

public BufferedOutputStream(OutputStream out) 

Source Link

Document

Creates a new buffered output stream to write data to the specified underlying output stream.

Usage

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Junk obj1 = new Junk("A");
    Junk obj2 = new Junk("B");
    Junk obj3 = new Junk("V");
    ObjectOutputStream objectOut = new ObjectOutputStream(
            new BufferedOutputStream(new FileOutputStream("C:/JunkObjects.bin")));

    objectOut.writeObject(obj1); // Write object
    objectOut.writeObject(obj2); // Write object
    objectOut.writeObject(obj3); // Write object
    System.out.println("\n\nobj1:\n" + obj1 + "\n\nobj2:\n" + obj2 + "\n\nobj3:\n" + obj3);
    objectOut.close(); // Close the output stream

}

From source file:Main.java

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);
                }//w  ww  .  j  a  v a2 s.  co m
            }
        }
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String fromFileName = "from.txt";
    String toFileName = "to.txt";
    BufferedInputStream in = new BufferedInputStream(new FileInputStream(fromFileName));
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(toFileName));
    byte[] buff = new byte[32 * 1024];
    int len;/* ww  w .  j  a  va  2  s.  c o  m*/
    while ((len = in.read(buff)) > 0)
        out.write(buff, 0, len);
    in.close();
    out.close();
}

From source file:Main.java

public static void main(String[] argv) throws Exception {

    StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(null,
            null);/*from  w ww  .  j  a v  a  2  s .  c  om*/

    OutputStream fos = new BufferedOutputStream(new FileOutputStream("outfile.ps"));
    StreamPrintService service = factories[0].getPrintService(fos);

}

From source file:Main.java

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

    Attribute attr = (Attribute) service.getDefaultAttributeValue(Destination.class);

    // attr == null if the attribute is not supported
    if (attr != null) {
        String attrName = attr.getName();
        // Get string representation of default value
        String attrValue = attr.toString();

    }/*w  ww . j a va  2 s. com*/

}

From source file:Main.java

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 category = OrientationRequested.class;
    Object o = service.getSupportedAttributeValues(category, null, null);
    if (o == null) {
        System.out.println("Attribute is not supported");
    } else if (o.getClass() == category) {
        System.out.println("irrelevant");
    } else if (o.getClass().isArray()) {
        System.out.println("array");
        for (int i = 0; i < Array.getLength(o); i++) {
            Object v = Array.get(o, i);
            System.out.println(v);
        }/*from  w  w w .ja  va2s . c o  m*/
    }
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Item bean = new Item();
    bean.setId(new Long(1));
    bean.setItemName("a");
    bean.setItemColour("Red");
    bean.setItemQuantities(new Integer(100));

    XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(new FileOutputStream("Bean.xml")));

    encoder.writeObject(bean);/* w ww  .j a  v  a 2  s  .  c o  m*/
    encoder.close();
}

From source file:Main.java

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

    DocPrintJob job = service.createPrintJob();
    job.addPrintJobListener(new MyPrintJobListener());
}

From source file:Main.java

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);
    Attribute[] attrs = service.getAttributes().toArray();
    for (int j = 0; j < attrs.length; j++) {
        String attrName = attrs[j].getName();
        String attrValue = attrs[j].toString();
        System.out.println(attrName);
        System.out.println(attrValue);
    }// w  w w.j a v  a2s.c o  m
}

From source file:Main.java

public static void main(String[] args) throws Exception {

    FileInputStream is = new FileInputStream("c:/test.txt");

    BufferedInputStream bis = new BufferedInputStream(is);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();

    BufferedOutputStream bos = new BufferedOutputStream(baos);

    int value;/*from www .j  a v  a2  s.  co  m*/

    while ((value = bis.read()) != -1) {
        bos.write(value);
    }

    bos.flush();

    for (byte b : baos.toByteArray()) {

        char c = (char) b;
        System.out.println(c);
    }

}