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.csipsimple.backup.SipProfilesHelper.java

/**
 * Read data from the input stream/*w ww  .  j av  a 2 s.c  om*/
 * 
 * @param data the input stream
 * @return the data
 * @throws IOException I/O error
 */
private String readData(BackupDataInputStream data) throws IOException {
    String dataS;
    byte[] buf = new byte[data.size()];
    data.read(buf, 0, buf.length);
    ByteArrayInputStream bais = new ByteArrayInputStream(buf);
    DataInputStream dis = new DataInputStream(bais);
    dataS = dis.readUTF();
    dis.close();
    bais.close();
    return dataS;
}

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

@Test
public void testEmptyWorks() 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);
    encoder.flush();/*w  ww  . j a  va  2  s.c  om*/
    dos.close();
    long offset = cos.getCount();
    assertEquals(0, offset);
    CountingInputStream cis = new CountingInputStream(new ByteArrayInputStream(baos.toByteArray()));
    DataInputStream dis = new DataInputStream(cis);
    Codec.Decoder decoder = cmc.getDecoder(dis);
    assertFalse(decoder.advance());
    dis.close();
    assertEquals(0, cis.getCount());
}

From source file:com.alphabetbloc.accessmrs.tasks.CheckConnectivityTask.java

@Override
protected String doInBackground(SyncResult... values) {
    sSyncResult = values[0];//from   w  w  w . j  a  v a  2s.co m
    boolean connected = false;

    try {
        getServerCredentials();
        httpClient = NetworkUtils.getHttpClient();
        DataInputStream dis = getServerStream();
        if (dis != null) {
            dis.close();
            connected = true;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }

    return String.valueOf(connected);
}

From source file:isl.FIMS.utils.Utils.java

public static ArrayList readFile(File f) {
    ArrayList content = new ArrayList();
    try {/*from   ww w . ja va2s.c o m*/
        // Open the file that is the first 
        // command line parameter
        FileInputStream fstream = new FileInputStream(f);
        // Get the object of DataInputStream
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;
        //Read File Line By Line
        while ((strLine = br.readLine()) != null) {
            // Print the content on the console
            content.add(strLine.trim());
        }
        //Close the input stream
        in.close();
    } catch (Exception e) {//Catch exception if any
        System.err.println("Error: " + e.getMessage());
    }
    return content;
}

From source file:com.xperia64.timidityae.Globals.java

public static boolean cfgIsAuto(String path) {
    String firstLine = "";
    try {/*w w  w  . j a v  a  2s . c  om*/
        FileInputStream fstream = new FileInputStream(path);
        DataInputStream in = new DataInputStream(fstream);
        BufferedReader br = new BufferedReader(new InputStreamReader(in));
        firstLine = br.readLine();

        in.close();
    } catch (Exception e) {
    }
    if (firstLine != null)
        return firstLine.contains(autoSoundfontHeader);
    return false;
}

From source file:Main.java

public String downloadWWWPage(URL pageURL) throws Exception {
    String host, file;//from  w ww .j av  a  2s.  c  o m
    host = pageURL.getHost();
    file = pageURL.getFile();

    InputStream pageStream = getWWWPageStream(host, file);
    if (pageStream == null) {
        return "";
    }

    DataInputStream in = new DataInputStream(pageStream);
    StringBuffer pageBuffer = new StringBuffer();
    String line;

    while ((line = in.readUTF()) != null) {
        pageBuffer.append(line);
    }
    in.close();
    return pageBuffer.toString();
}

From source file:com.csipsimple.backup.SipProfilesHelper.java

@Override
public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) {
    boolean forceBackup = (oldState == null);

    long fileModified = databaseFile.lastModified();
    try {/*from w w w  . ja va2 s .co  m*/
        if (!forceBackup) {
            FileInputStream instream = new FileInputStream(oldState.getFileDescriptor());
            DataInputStream in = new DataInputStream(instream);
            long lastModified = in.readLong();
            in.close();

            if (lastModified < fileModified) {
                forceBackup = true;
            }
        }
    } catch (IOException e) {
        Log.e(THIS_FILE, "Cannot manage previous local backup state", e);
        forceBackup = true;
    }

    Log.d(THIS_FILE, "Will backup profiles ? " + forceBackup);
    if (forceBackup) {
        JSONArray accountsSaved = SipProfileJson.serializeSipProfiles(mContext);
        try {
            writeData(data, accountsSaved.toString());
        } catch (IOException e) {
            Log.e(THIS_FILE, "Cannot manage remote backup", e);
        }
    }

    try {
        FileOutputStream outstream = new FileOutputStream(newState.getFileDescriptor());
        DataOutputStream out = new DataOutputStream(outstream);
        out.writeLong(fileModified);
        out.close();
    } catch (IOException e) {
        Log.e(THIS_FILE, "Cannot manage final local backup state", e);
    }
}

From source file:org.pdfgal.pdfgalweb.utils.impl.ZipUtilsImpl.java

@Override
public boolean isZip(final InputStream inputStream) {

    boolean result = false;

    try {// w w w  .j a  v  a2 s.c  o  m
        final DataInputStream dataInputStream = new DataInputStream(new BufferedInputStream(inputStream));
        final int test = dataInputStream.readInt();
        dataInputStream.close();
        result = (test == 0x504b0304);
    } catch (final IOException e) {
        result = false;
    }

    return result;
}

From source file:org.cloudata.core.tablet.backup.RestoreBinaryMap.java

@Override
public void map(BytesWritable key, BytesWritable value, OutputCollector<Text, Text> output, Reporter reporter)
        throws IOException {
    if (confErr != null) {
        throw confErr;
    }//ww  w.j a va 2  s . c o  m
    ByteArrayInputStream bin = new ByteArrayInputStream(key.get(), 0, key.getSize());
    DataInputStream in = new DataInputStream(bin);
    Row row = new Row();
    row.readFields(in);

    uploader.put(row);
    count++;
    if (count % 10000 == 0) {
        LOG.info(count + " cells restored");
    }
    in.close();
}

From source file:com.csipsimple.backup.SipSharedPreferencesHelper.java

@Override
public void performBackup(ParcelFileDescriptor oldState, BackupDataOutput data, ParcelFileDescriptor newState) {
    boolean forceBackup = (oldState == null);

    long fileModified = 1;
    if (prefsFiles != null) {
        fileModified = prefsFiles.lastModified();
    }//from ww w . j a  va2 s. c  o m
    try {
        if (!forceBackup) {
            FileInputStream instream = new FileInputStream(oldState.getFileDescriptor());
            DataInputStream in = new DataInputStream(instream);
            long lastModified = in.readLong();
            in.close();

            if (lastModified < fileModified) {
                forceBackup = true;
            }
        }
    } catch (IOException e) {
        Log.e(THIS_FILE, "Cannot manage previous local backup state", e);
        forceBackup = true;
    }

    Log.d(THIS_FILE, "Will backup profiles ? " + forceBackup);
    if (forceBackup) {
        JSONObject settings = SipProfileJson.serializeSipSettings(mContext);
        try {
            writeData(data, settings.toString());
        } catch (IOException e) {
            Log.e(THIS_FILE, "Cannot manage remote backup", e);
        }
    }

    try {
        FileOutputStream outstream = new FileOutputStream(newState.getFileDescriptor());
        DataOutputStream out = new DataOutputStream(outstream);
        out.writeLong(fileModified);
        out.close();
    } catch (IOException e) {
        Log.e(THIS_FILE, "Cannot manage final local backup state", e);
    }

}