Example usage for java.io DataInputStream close

List of usage examples for java.io DataInputStream close

Introduction

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

Prototype

public void close() throws IOException 

Source Link

Document

Closes this input stream and releases any system resources associated with the stream.

Usage

From source file:com.sforce.cd.apexUnit.client.fileReader.ApexManifestFileReader.java

private String[] readInputStreamAndConstructClassArray(InputStream inStr) throws IOException {
    String[] testClassesAsArray = null;
    ArrayList<String> testClassList = new ArrayList<String>();

    LOG.debug("Input stream: " + inStr);
    DataInputStream dataIS = new DataInputStream(inStr);
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(dataIS));
    String strLine = null;// www .j  a v a2  s. co m
    String newline = System.getProperty("line.separator");

    while ((strLine = bufferedReader.readLine()) != null) {
        if (!newline.equals(strLine) && !strLine.equals("") && strLine.length() > 0) {
            LOG.debug("The line says .... -  " + strLine);
            insertIntoTestClassesArray(strLine, testClassList);
        }
    }
    dataIS.close();

    Object[] apexClassesObjArr = testClassList.toArray();
    testClassesAsArray = (Arrays.copyOf(apexClassesObjArr, apexClassesObjArr.length, String[].class));
    if (LOG.isDebugEnabled()) {
        ApexClassFetcherUtils.logTheFetchedApexClasses(testClassesAsArray);
    }
    return testClassesAsArray;
}

From source file:de.hybris.platform.test.MediaTest.java

@Test
public void testSecureUrlNoRendererFound() throws Exception {
    final DataInputStream is1 = getStream(data1);
    secureMedia.setDataFromStream(is1);//from   w  w w. j a v a2  s  .c  om
    is1.close();

    assertNotNull(secureMedia.getPK());

    try {
        Config.setParameter("media.folder.root.secured", "true");
        MediaUtil.setCurrentSecureMediaURLRenderer(null);
        final String url = secureMedia.getURL();
        assertThat(url).isEmpty();
    } finally {
        Config.setParameter("media.folder.root.secured", "false");
    }
}

From source file:org.apache.hama.bsp.LocalBSPRunner.java

@Override
public JobStatus submitJob(BSPJobID jobID, String jobFile) throws IOException {
    this.jobFile = jobFile;

    if (fs == null) {
        this.fs = FileSystem.get(conf);
    }/*from   w w w.ja  va  2s. co  m*/

    // add the resource to the current configuration, because add resouce in
    // HamaConfigurations constructor (ID,FILE) does not take local->HDFS
    // connections into account. This leads to not serializing the
    // configuration, which yields into failure.
    conf.addResource(fs.open(new Path(jobFile)));

    conf.setClass(MessageManagerFactory.MESSAGE_MANAGER_CLASS, LocalMessageManager.class, MessageManager.class);
    conf.setClass(SyncServiceFactory.SYNC_PEER_CLASS, LocalSyncClient.class, SyncClient.class);

    BSPJob job = new BSPJob(new HamaConfiguration(conf), jobID);
    currentJobStatus = new JobStatus(jobID, System.getProperty("user.name"), 0L, JobStatus.RUNNING,
            globalCounters);

    int numBspTask = job.getNumBspTask();

    String jobSplit = conf.get("bsp.job.split.file");

    BSPJobClient.RawSplit[] splits = null;
    if (jobSplit != null) {

        DataInputStream splitFile = fs.open(new Path(jobSplit));

        try {
            splits = BSPJobClient.readSplitFile(splitFile);
        } finally {
            splitFile.close();
        }
    }

    threadPool = (ThreadPoolExecutor) Executors.newFixedThreadPool(numBspTask);
    @SuppressWarnings("rawtypes")
    ExecutorCompletionService<BSPPeerImpl> completionService = new ExecutorCompletionService<BSPPeerImpl>(
            threadPool);

    peerNames = new String[numBspTask];
    for (int i = 0; i < numBspTask; i++) {
        peerNames[i] = "local:" + i;
        completionService.submit(new BSPRunner(new HamaConfiguration(conf), job, i, splits));
        globalCounters.incrCounter(JobInProgress.JobCounter.LAUNCHED_TASKS, 1L);
    }

    new Thread(new ThreadObserver(numBspTask, completionService)).start();
    return currentJobStatus;
}

From source file:org.apache.oozie.workflow.lite.LiteWorkflowAppParser.java

/**
 * Read the GlobalSectionData from Base64 string.
 * @param globalStr//from w  w w.  java  2 s  .co  m
 * @return GlobalSectionData
 * @throws WorkflowException
 */
private GlobalSectionData getGlobalFromString(String globalStr) throws WorkflowException {
    GlobalSectionData globalSectionData = new GlobalSectionData();
    try {
        byte[] data = Base64.decodeBase64(globalStr);
        Inflater inflater = new Inflater();
        DataInputStream ois = new DataInputStream(
                new InflaterInputStream(new ByteArrayInputStream(data), inflater));
        globalSectionData.readFields(ois);
        ois.close();
    } catch (Exception ex) {
        throw new WorkflowException(ErrorCode.E0700, "Error while processing global section conf");
    }
    return globalSectionData;
}

From source file:HttpHEADMIDlet.java

private String requestUsingGET(String URLString) throws IOException {
    HttpConnection hpc = null;/* ww  w  .j a  v  a 2s  . c o  m*/
    DataInputStream dis = null;

    String content = "";
    try {
        hpc = (HttpConnection) Connector.open(URLString);
        hpc.setRequestMethod(HttpConnection.HEAD);

        dis = new DataInputStream(hpc.openInputStream());
        int i = 1;
        String key = "";
        String value = "";

        while ((value = hpc.getHeaderField(i)) != null) {
            key = hpc.getHeaderFieldKey(i++);
            content += key + ":" + value + "\n";
        }
        if (hpc != null)
            hpc.close();
        if (dis != null)
            dis.close();
    } catch (IOException e2) {
    }

    return content;
}

From source file:de.hybris.platform.test.MediaTest.java

@Test
public void testSecureUrlWithRenderer() throws Exception {
    assertNotNull(secureMedia.getPK());//from   w ww. j  a va2s.c  om
    final String pkAsStr = secureMedia.getPK().toString();

    //create custom renderer
    MediaUtil.setCurrentSecureMediaURLRenderer(new SecureMediaURLRenderer() {
        @Override
        public String renderSecureMediaURL(final MediaSource mediaSource) {
            return "/securemedias?mediaPK=" + mediaSource.getMediaPk();
        }
    });

    final DataInputStream is1 = getStream(data1);
    secureMedia.setDataFromStream(is1);
    is1.close();

    try {
        Config.setParameter("media.folder.root.secured", "true");
        final String url = secureMedia.getURL();
        assertEquals("/securemedias?mediaPK=" + pkAsStr, url);
    } finally {
        Config.setParameter("media.folder.root.secured", "false");
    }
}

From source file:com.linkedin.pinot.core.segment.index.SegmentMetadataImpl.java

private void loadCreationMeta(File crcFile) throws IOException {
    if (crcFile.exists()) {
        final DataInputStream ds = new DataInputStream(new FileInputStream(crcFile));
        _crc = ds.readLong();//ww w . ja v  a  2  s.c  o  m
        _creationTime = ds.readLong();
        ds.close();
    }
}

From source file:org.apache.hadoop.hashtable.HashTableBenchmark.java

private void readBlockFile() {
    try {/*from w  w  w  . j  av a 2  s.c  o m*/
        LOG.info("----> READ BLOCK FILE : START");
        initArray();
        FileInputStream fstream = new FileInputStream(blockFile);
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(new DataInputStream(fstream)));
        String strLine;
        NUM_NODES = 0;
        while ((strLine = br.readLine()) != null) {
            if (NUM_NODES % divider == 0)
                LOG.info("Processed : " + NUM_NODES);
            updateArray(NUM_NODES, Long.parseLong(strLine));
            NUM_NODES++;
        }
        in.close();
        LOG.info("----> READ BLOCK FILE : DONE: Read " + NUM_NODES + " block ids");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:de.hybris.platform.test.MediaTest.java

@Test
public void testMediaData() throws Exception {
    m.setMime("major1/minor1");
    assertEquals("major1/minor1", m.getMime());
    final DataInputStream is1 = getStream(data1);
    m.setDataFromStream(is1);//from ww  w.j  av  a  2s .c o  m
    is1.close();

    assertEqualsByteArray(data1, m.getData());
    final InputStream is2 = m.getDataFromStream();
    assertEqualsByteArray(data1, getBytes(is2));
    is2.close();

    final DataInputStream is3 = getStream(data2);
    m.setDataFromStream(is3);
    is3.close();

    final InputStream is4 = m.getDataFromStream();
    assertEqualsByteArray(data2, getBytes(is4));
    is4.close();

    assertEqualsByteArray(data2, m.getData());
    final InputStream is5 = m.getDataFromStream();
    assertEqualsByteArray(data2, getBytes(is5));
    is5.close();

    m.setMime("major2/minor2");
    assertEquals("major2/minor2", m.getMime());
    assertEqualsByteArray(data2, m.getData());
    assertEqualsByteArray(data2, getBytes(m.getDataFromStream()));

    // test setting the same mime type
    m.setMime("major2/minor2");
    assertEquals("major2/minor2", m.getMime());
    assertEqualsByteArray(data2, m.getData());
    assertEqualsByteArray(data2, getBytes(m.getDataFromStream()));

    m.setDataFromStream(getStream(data3));

    assertEqualsByteArray(data3, m.getData());
    assertEqualsByteArray(data3, getBytes(m.getDataFromStream()));

    m.setData(data1);
    assertEqualsByteArray(data1, m.getData());
    assertEqualsByteArray(data1, getBytes(m.getDataFromStream()));
}

From source file:org.apache.helix.manager.zk.ZKHelixAdmin.java

private static byte[] readFile(String filePath) throws IOException {
    File file = new File(filePath);

    int size = (int) file.length();
    byte[] bytes = new byte[size];
    DataInputStream dis = null;
    try {//from  w ww.  j a v a  2s .c o m
        dis = new DataInputStream(new FileInputStream(file));
        int read = 0;
        int numRead = 0;
        while (read < bytes.length && (numRead = dis.read(bytes, read, bytes.length - read)) >= 0) {
            read = read + numRead;
        }
        return bytes;
    } finally {
        if (dis != null) {
            dis.close();
        }
    }
}