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:de.avanux.livetracker.admin.Configuration.java

private Properties parsePropertiesFromString(String propertiesString) throws IOException {
    Properties properties = null;
    if (propertiesString != null) {
        if (propertiesString.charAt(0) == '<') {
            throw new IOException("Reveived HTML instead of properties!");
        }/* w w  w .j  a v  a 2  s .c  o m*/

        ByteArrayInputStream input = null;
        try {
            input = new ByteArrayInputStream(propertiesString.getBytes());
            properties = new Properties();
            properties.load(input);
        } catch (IOException e) {
            log.error(e);
        } finally {
            if (input != null) {
                try {
                    input.close();
                } catch (IOException e) {
                    log.error(e);
                }
            }
        }
    } else {
        throw new IOException("Properties string must not be null!");
    }
    return properties;
}

From source file:org.carlspring.strongbox.artifact.generator.NugetPackageGenerator.java

private void createMetadata(String id, String version, ZipOutputStream zos) throws IOException {
    ZipEntry ze = new ZipEntry("package/services/metadata/core-properties/metadata.psmdcp");
    zos.putNextEntry(ze);//from w w  w  .ja v a  2 s . co m

    ByteArrayInputStream is = new ByteArrayInputStream(String.format(PSMDCP_CONTENT, id, version).getBytes());
    byte[] buffer = new byte[4096];
    int len;
    while ((len = is.read(buffer)) > 0) {
        zos.write(buffer, 0, len);
    }

    is.close();
    zos.closeEntry();
}

From source file:com.servioticy.queueclient.KestrelThriftClient.java

protected Object deserialize(byte[] in) {
    Object rv = null;// w  ww . j  av  a 2  s  . com
    ByteArrayInputStream bis = null;
    ObjectInputStream is = null;
    try {
        if (in != null) {
            bis = new ByteArrayInputStream(in);
            is = new ObjectInputStream(bis);
            rv = is.readObject();
            is.close();
            bis.close();
        }
    } catch (IOException e) {
        logger.warn("Caught IOException decoding %d bytes of data", in == null ? 0 : in.length, e);
    } catch (ClassNotFoundException e) {
        logger.warn("Caught CNFE decoding %d bytes of data", in == null ? 0 : in.length, e);
    }
    return rv;
}

From source file:com.ewcms.publication.freemarker.generator.GeneratorBaseTest.java

private String getContent(byte[] content) throws Exception {
    ByteArrayInputStream in = new ByteArrayInputStream(content);
    BufferedReader reader = new BufferedReader(new InputStreamReader(in, "utf-8"));
    StringBuilder builder = new StringBuilder();
    String line;//from w  w w.ja va  2  s . co  m
    while ((line = reader.readLine()) != null) {
        builder.append(line);
    }
    reader.close();
    in.close();
    return builder.toString();
}

From source file:org.eclipse.skalli.testutil.StorageServiceTestBase.java

@Test
public void testUpdate() throws Exception {
    final String TEST_CATEGORY = "test_update";

    writeContent(TEST_CATEGORY, TEST_ID, TEST_CONTENT);

    //update the same key with TEST_CONTENT_UPDATED
    ByteArrayInputStream is = new ByteArrayInputStream(TEST_CONTENT_UPDATED.getBytes("UTF-8"));

    StorageService storageService = getStorageService();
    storageService.write(TEST_CATEGORY, TEST_ID, is);

    InputStream stream = storageService.read(TEST_CATEGORY, TEST_ID);
    String outputText = IOUtils.toString(stream, "UTF-8");

    assertEquals(TEST_CONTENT_UPDATED, outputText);
    is.close();
    stream.close();/*from w w  w  .  j  av a  2  s  .  com*/
}

From source file:com.ikon.ws.endpoint.DocumentService.java

@WebMethod
public Document createSimple(@WebParam(name = "token") String token, @WebParam(name = "docPath") String docPath,
        @WebParam(name = "content") byte[] content)
        throws IOException, UnsupportedMimeTypeException, FileSizeExceededException, UserQuotaExceededException,
        VirusDetectedException, ItemExistsException, PathNotFoundException, AccessDeniedException,
        RepositoryException, DatabaseException, ExtensionException, AutomationException {
    log.debug("createSimple({})", docPath);
    DocumentModule dm = ModuleManager.getDocumentModule();
    ByteArrayInputStream bais = new ByteArrayInputStream(content);
    Document doc = new Document();
    doc.setPath(docPath);/*from www  .  j ava2s  .  c o  m*/
    Document newDocument = dm.create(token, doc, bais);
    bais.close();
    log.debug("createSimple: {}", newDocument);
    return newDocument;
}

From source file:com.openkm.ws.endpoint.OKMDocument.java

@WebMethod
public Document createSimple(@WebParam(name = "token") String token, @WebParam(name = "docPath") String docPath,
        @WebParam(name = "content") byte[] content)
        throws IOException, UnsupportedMimeTypeException, FileSizeExceededException, UserQuotaExceededException,
        VirusDetectedException, ItemExistsException, PathNotFoundException, AccessDeniedException,
        RepositoryException, DatabaseException, ExtensionException {
    log.debug("createSimple({})", docPath);
    DocumentModule dm = ModuleManager.getDocumentModule();
    ByteArrayInputStream bais = new ByteArrayInputStream(content);
    Document doc = new Document();
    doc.setPath(docPath);//from  w  ww .j  a  va2 s .  co m
    Document newDocument = dm.create(token, doc, bais);
    bais.close();
    log.debug("createSimple: {}", newDocument);
    return newDocument;
}

From source file:imc.jettyserver.servlets.Log4jInit.java

private void convertLogFile(File srcConfig, File destConfig, File logDir) {

    // Step 1 read config file into memory
    String srcDoc = "not initialized";
    try {//from ww  w  .  j  a  va 2 s. c o m
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        FileInputStream is = new FileInputStream(srcConfig);

        byte[] buf = new byte[1024];
        int len;
        while ((len = is.read(buf)) > 0) {
            baos.write(buf, 0, len);
        }

        is.close();
        baos.close();
        srcDoc = new String(baos.toByteArray());
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    }

    // Step 2 ; substitute Patterns
    String destDoc = srcDoc.replaceAll("loggerdir", logDir.getAbsolutePath().replaceAll("\\\\", "/"));

    // Step 3 ; write back to file
    try {
        ByteArrayInputStream bais = new ByteArrayInputStream(destDoc.getBytes());
        FileOutputStream fos = new FileOutputStream(destConfig);
        byte[] buf = new byte[1024];
        int len;
        while ((len = bais.read(buf)) > 0) {
            fos.write(buf, 0, len);
        }
        fos.close();
        bais.close();
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
}

From source file:com.hurence.logisland.engine.SparkRecordStreamProcessingTest.java

private Collection<Record> readMessages(String topic) {

    List<Record> outputRecords = new ArrayList<>();
    // starting consumer
    Map<String, Integer> topicCountMap = new HashMap<>();
    topicCountMap.put(topic, 1);/*from  w ww .j av a2 s. co m*/
    Map<String, List<KafkaStream<byte[], byte[]>>> consumerMap = consumer.createMessageStreams(topicCountMap);
    KafkaStream<byte[], byte[]> stream = consumerMap.get(topic).get(0);
    ConsumerIterator<byte[], byte[]> iterator = stream.iterator();

    // verify the integrity of the retrieved event
    if (iterator.hasNext()) {
        final KryoSerializer deserializer = new KryoSerializer(true);

        ByteArrayInputStream bais = new ByteArrayInputStream(iterator.next().message());
        Record deserializedRecord = deserializer.deserialize(bais);
        logger.info(deserializedRecord.toString());
        outputRecords.add(deserializedRecord);
        try {
            bais.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    } else {
        fail();
    }
    return outputRecords;
}

From source file:com.gs.tools.doc.extractor.core.html.HTMLDocumentExtractor.java

private void writeTo(byte[] data, OutputStream outputStream) throws IOException {
    try {/*from   ww  w .j a va  2  s.  co m*/
        ByteArrayInputStream bais = new ByteArrayInputStream(data);
        byte[] buffer = new byte[1024 * 1024];
        int count = 0;
        while ((count = bais.read(buffer, 0, 1024 * 1024)) > 0) {
            outputStream.write(buffer, 0, count);
        }
        bais.close();
    } finally {
        outputStream.close();
    }

}