Example usage for java.io ByteArrayInputStream close

List of usage examples for java.io ByteArrayInputStream close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closing a ByteArrayInputStream has no effect.

Usage

From source file:Main.java

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

    byte[] buf = { 65, 66, 67, 68, 69 };

    ByteArrayInputStream bais = new ByteArrayInputStream(buf);

    bais.close();

    int count = bais.available();
}

From source file:org.iff.demo.dddallinone.ws.WeatherSpringRPCClient.java

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

    {/*from  w  w  w . j a v a2  s .c  o m*/
        FileInputStream fos = new FileInputStream("f:\\test.test");
        HessianInput in = new HessianInput(fos);
        Object obj = in.readObject(null);
        System.out.println(obj);
        fos.close();
        if (true) {
            return;
        }
    }

    MyUserDTO myUser = new MyUserDTO();
    myUser.setName("3?web????tomcat");
    EJBFacadeDTO ejbFacadeDTO = new EJBFacadeDTO("org.iff.demo.dddallinone.application.MyUserApplication",
            "myUserApplication", "saveMyUser", new Object[] { myUser });
    {
        try {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            HessianOutput out = new HessianOutput(os);
            out.writeObject(ejbFacadeDTO);
            os.close();
            System.out.println(new String(os.toByteArray(), "UTF-8") + "\nlength:" + os.size());
            ByteArrayInputStream is = new ByteArrayInputStream(
                    new String(os.toByteArray(), "UTF-8").getBytes());
            HessianInput in = new HessianInput(is);
            Object obj = in.readObject(null);
            System.out.println(obj);
            is.close();
            {
                FileOutputStream fos = new FileOutputStream("f:\\test.test");
                fos.write(os.toByteArray());
                fos.flush();
                fos.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (true) {
            return;
        }
    }

    RPCServiceClient serviceClient = new RPCServiceClient();

    Options options = serviceClient.getOptions();

    EndpointReference targetEPR = new EndpointReference("http://localhost:8080/services/AllInOneEJBFacadeWS");

    options.setTo(targetEPR);

    // Get the weather (no setting, the Spring Framework has already initialized it for us)
    QName saveMyUser = new QName("http://application.dddallinone.demo.iff.org", "invoke");
    Object[] opGetWeatherArgs = new Object[] { ejbFacadeDTO };
    Class[] returnTypes = new Class[] { EJBFacadeDTO.class };

    Object[] response = serviceClient.invokeBlocking(saveMyUser, opGetWeatherArgs, returnTypes);
    System.out.println(response);

    EJBFacadeDTO result = (EJBFacadeDTO) response[0];

    // display results
    if (result == null) {
        System.out.println("Weather didn't initialize!");
    } else {
        System.out.println("Temperature               : " + result.getResult());

    }
}

From source file:Main.java

static public byte[] gzip(byte src[], byte default_value[]) {
    try {//from  ww  w  .  ja v  a  2 s. c om
        if (src == null)
            return default_value;

        ByteArrayOutputStream out_raw = new ByteArrayOutputStream();
        GZIPOutputStream out = new GZIPOutputStream(out_raw);

        ByteArrayInputStream in = new ByteArrayInputStream(src);

        IOUtils.copy(in, out);

        in.close();
        out.close();

        return out_raw.toByteArray();
    } catch (Exception e) {
        return default_value;
    }
}

From source file:Main.java

public static Object getObject(byte[] bytes) throws IOException, ClassNotFoundException {
    ByteArrayInputStream bi = new ByteArrayInputStream(bytes);
    ObjectInputStream oi = new ObjectInputStream(bi);
    Object obj = oi.readObject();
    bi.close();
    oi.close();/*from w  w  w .j a  v  a  2 s.  co m*/
    return obj;
}

From source file:Main.java

public static Object ByteToObject(byte[] bytes) {
    Object obj = null;//w w  w  .j  av a 2s  . c o m
    try {
        // bytearray to object
        ByteArrayInputStream bi = new ByteArrayInputStream(bytes);
        ObjectInputStream oi = new ObjectInputStream(bi);

        obj = oi.readObject();
        bi.close();
        oi.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return obj;
}

From source file:Main.java

public static Object deserializable(byte[] bytes) {
    Object obj = null;//from w  ww . j a  v  a2s . c  om
    try {
        ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(bis);

        obj = ois.readObject();
        bis.close();
        ois.close();
    } catch (Exception e) {
        System.out.println("tanslation " + e.getMessage());
        e.printStackTrace();
    }

    return obj;
}

From source file:com.aqnote.shared.cryptology.asymmetric.dsa.DSAKeyPairGenTest.java

public static void generator() throws NoSuchAlgorithmException, FileNotFoundException, IOException {
    KeyPairGenerator keygen = KeyPairGenerator.getInstance(ALGORITHM);

    // ???//from   w ww.  j  ava  2 s  .c  o m
    SecureRandom secrand = new SecureRandom();
    secrand.setSeed(seed); // ??
    // ??, ??keysize ?. 512  1024  64 ?
    keygen.initialize(512, secrand);
    // ?pubkey?prikey
    KeyPair keys = keygen.generateKeyPair(); // ?
    PublicKey pubkey = keys.getPublic();
    PrivateKey prikey = keys.getPrivate();

    byte[] pubkeyByteArray = Base64.encodeBase64(pubkey.getEncoded());
    OutputStream os = new FileOutputStream(new File(PUBKEY_FILE_NAME));
    ByteArrayInputStream bais = new ByteArrayInputStream(pubkeyByteArray);
    StreamUtil.io(bais, os);
    bais.close();
    os.close();

    byte[] prikeyByteArray = Base64.encodeBase64(prikey.getEncoded());
    os = new FileOutputStream(new File(PRIKEY_FILE_NAME));
    bais = new ByteArrayInputStream(prikeyByteArray);
    StreamUtil.io(bais, os);
    bais.close();
    os.close();
}

From source file:Main.java

public static Document parseXML(String xml) throws ParserConfigurationException, SAXException, IOException {
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);/*  w ww .  ja  va2  s. co  m*/
    DocumentBuilder db = factory.newDocumentBuilder();

    ByteArrayInputStream sr = new ByteArrayInputStream(xml.getBytes());
    try {
        Document document = db.parse(sr);
        return document;
    } finally {
        sr.close();
    }
}

From source file:AkashApplications.src.GenerateBarcode.java

public static BufferedImage decodeToImage(String imageString) {

    BufferedImage image = null;//from  www  .j  a v a2s.  c o  m
    byte[] imageByte;
    try {
        BASE64Decoder decoder = new BASE64Decoder();
        imageByte = decoder.decodeBuffer(imageString);
        ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
        image = ImageIO.read(bis);
        bis.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return image;
}

From source file:Main.java

public static <T> T xmlToObj(Class<T> t, String xml, String encoding) {
    try {/* w w  w . j ava2s  .  com*/
        JAXBContext jaxbContext = JAXBContext.newInstance(t);
        Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
        ByteArrayInputStream bais = new ByteArrayInputStream(xml.getBytes(encoding));
        @SuppressWarnings("unchecked")
        T obj = (T) unmarshaller.unmarshal(bais);
        bais.close();
        return obj;
    } catch (JAXBException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}