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.towerlabs.yildizyemek.ViewPagerDinner.java

public String readFile() throws IOException {

    FileInputStream fi;// w w w.j a  v a  2 s .  c o  m
    DataInputStream di;
    String result = null;

    fi = new FileInputStream(file);
    di = new DataInputStream(fi);

    result = di.readUTF();

    fi.close();
    di.close();

    fi = null;
    di = null;

    return result;

}

From source file:org.apache.hadoop.hbase.codec.TestCellMessageCodec.java

@Test
public void testOne() throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    CountingOutputStream cos = new CountingOutputStream(baos);
    DataOutputStream dos = new DataOutputStream(cos);
    MessageCodec cmc = new MessageCodec();
    Codec.Encoder encoder = cmc.getEncoder(dos);
    final KeyValue kv = new KeyValue(Bytes.toBytes("r"), Bytes.toBytes("f"), Bytes.toBytes("q"),
            Bytes.toBytes("v"));
    encoder.write(kv);/*from   w w  w .  j  a  v a2s .  c om*/
    encoder.flush();
    dos.close();
    long offset = cos.getCount();
    CountingInputStream cis = new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
    DataInputStream dis = new DataInputStream(cis);
    Codec.Decoder decoder = cmc.getDecoder(dis);
    assertTrue(decoder.advance()); // First read should pull in the KV
    assertFalse(decoder.advance()); // Second read should trip over the end-of-stream  marker and return false
    dis.close();
    assertEquals(offset, cis.getCount());
}

From source file:org.apache.lucene.replicator.http.HttpReplicator.java

@Override
public SessionToken checkForUpdate(String currVersion) throws IOException {
    String[] params = null;/*from  www .j  a  v  a 2s .c o  m*/
    if (currVersion != null) {
        params = new String[] { ReplicationService.REPLICATE_VERSION_PARAM, currVersion };
    }
    final HttpResponse response = executeGET(ReplicationAction.UPDATE.name(), params);
    return doAction(response, new Callable<SessionToken>() {
        @Override
        public SessionToken call() throws Exception {
            final DataInputStream dis = new DataInputStream(responseInputStream(response));
            try {
                if (dis.readByte() == 0) {
                    return null;
                } else {
                    return new SessionToken(dis);
                }
            } finally {
                dis.close();
            }
        }
    });
}

From source file:org.apache.flume.channel.file.TestEventQueueBackingStoreFactory.java

private void verify(EventQueueBackingStore backingStore, long expectedVersion, List<Long> expectedPointers)
        throws Exception {
    FlumeEventQueue queue = new FlumeEventQueue(backingStore, inflightTakes, inflightPuts);
    List<Long> actualPointers = Lists.newArrayList();
    FlumeEventPointer ptr;//w w  w .  j  a v  a 2s.  c  o m
    while ((ptr = queue.removeHead(0L)) != null) {
        actualPointers.add(ptr.toLong());
    }
    Assert.assertEquals(expectedPointers, actualPointers);
    Assert.assertEquals(10, backingStore.getCapacity());
    DataInputStream in = new DataInputStream(new FileInputStream(checkpoint));
    long actualVersion = in.readLong();
    Assert.assertEquals(expectedVersion, actualVersion);
    in.close();
}

From source file:noThreads.Playlist.java

public ArrayList<String> loadFromFile(String linksFile) throws IOException {
    String inputLine;// w  w  w  . j av a  2  s.c om
    // Open file
    FileInputStream fstream = new FileInputStream(linksFile);
    // Get the object of DataInputStream
    DataInputStream in = new DataInputStream(fstream);
    BufferedReader br = new BufferedReader(new InputStreamReader(in));

    //Read File Line By Line
    ArrayList<String> links = new ArrayList<>();
    while ((inputLine = br.readLine()) != null) {
        links.add(inputLine);
    }
    in.close();
    return links;
}

From source file:com.symbian.driver.remoting.master.TestResultSet.java

/**
 * Purpose : To open the zip file and read the contents into a byte array.
 * This will embed the bytes into this object
 * /*w  ww .j ava2  s .co  m*/
 * @throws IOException
 */
public void Embed() throws IOException {

    // Create stream to file
    FileInputStream lFis = new FileInputStream(zipFileName);
    DataInputStream lDis = new DataInputStream(lFis);

    // Create the buffer
    contents = new byte[MAX_SIZE];

    // Read contents into byte array
    numberOfBytes = new Integer(lDis.read(contents));

    // Close the stream
    lFis.close();
    lDis.close();
}

From source file:com.chinamobile.bcbsp.comm.DiskManager.java

/**
 *  Note Messages Coming Must Be Reinitialized. File Is Legal By Default.
 * @param messages MessageBytePoolPerPartition
 * @param f File//from  w w w  . j a v  a 2  s. c o m
 * @throws IOException e
 */
public void processMessageLoadFile(MessageBytePoolPerPartition messages, File f) throws IOException {
    FileInputStream fis;
    BufferedInputStream bis;
    DataInputStream dis;
    fis = new FileInputStream(f);
    bis = new BufferedInputStream(fis, MetaDataOfMessage.MESSAGE_IO_BYYES);
    dis = new DataInputStream(bis);
    messages.readFields(dis);
    dis.close();
}

From source file:org.apache.hama.bsp.message.compress.Bzip2Compressor.java

/**
 * Decompresses a BSPCompressedBundle and returns the corresponding
 * BSPMessageBundle./*from  w  ww .  ja v  a 2  s .co m*/
 * 
 * @param compressedBytes
 * @return The result after decompressing BSPMessageBundle.
 */
@Override
public byte[] decompress(byte[] compressedBytes) {
    ByteArrayInputStream bis = new ByteArrayInputStream(compressedBytes);
    DataInputStream in = new DataInputStream(bis);

    ByteArrayOutputStream outBuffer = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(outBuffer);
    try {

        final CompressorInputStream cin = new CompressorStreamFactory().createCompressorInputStream("bzip2",
                in);
        IOUtils.copy(cin, out);
        in.close();
    } catch (CompressorException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return outBuffer.toByteArray();
}

From source file:RetrieveAllMIDlet.java

public void changeFromByteArray(byte[] data) {
    try {//from w w  w .  j  av a2s. c  o m
        ByteArrayInputStream bais = new ByteArrayInputStream(data);
        DataInputStream dis = new DataInputStream(bais);

        name = dis.readUTF();
        chineseScore = dis.readInt();
        englishScore = dis.readInt();
        mathScore = dis.readInt();

        bais.close();
        dis.close();
    } catch (Exception e) {
    }
}

From source file:com.cuubez.visualizer.scanner.ClassScanner.java

public List<Class<?>> scan(String applicationPath) throws IOException {

    List<Class<?>> classes = new ArrayList<Class<?>>();

    URL resource = findResources(applicationPath);
    FileReader itr = getFileReader(resource, new ClassFileFilter());

    InputStream is;//from   w w w .  ja  v a 2s . co m
    while ((is = itr.next()) != null) {
        // make a data input stream
        DataInputStream dstream = new DataInputStream(new BufferedInputStream(is));

        try {
            // get java-assist class file
            ClassFile classFile = new ClassFile(dstream);
            classes.add(Class.forName(classFile.getName()));

        } catch (ClassNotFoundException e) {
            log.error(e);
        } finally {
            dstream.close();
            is.close();
        }
    }

    return classes;
}