List of usage examples for java.io DataInputStream DataInputStream
public DataInputStream(InputStream in)
From source file:eu.stratosphere.pact.runtime.task.util.SerializationCopier.java
/** * Resets the array and write a serialized copy to the array. * If the array is not sufficiently large, a new array is created. * The new size is double of the required size for the current copy. * /*from w w w . ja v a 2s. c o m*/ * @param copy * Object from which a serialized copy is created. */ public void setCopy(T copy) { try { copy.write(dos); dos.flush(); baos.flush(); } catch (IOException e) { LOG.error(e); } if (baos.size() <= serializedCopy.length) { // copy System.arraycopy(baos.toByteArray(), 0, serializedCopy, 0, baos.size()); } else { // allocate larger array serializedCopy = new byte[baos.size() * 2]; System.arraycopy(baos.toByteArray(), 0, serializedCopy, 0, baos.size()); // create new input streams bais = new ByteArrayInputStream(serializedCopy); dis = new DataInputStream(bais); } baos.reset(); }
From source file:org.pdfgal.pdfgalweb.utils.impl.ZipUtilsImpl.java
@Override public boolean isZip(final InputStream inputStream) { boolean result = false; try {/* www .ja va2 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:edu.cornell.med.icb.goby.compression.FastBufferedMessageChunksReader.java
/** * Support for splitting the entries on the file system. * Seek the input to start and start looking for the beginning of a new collection. * When found, return all entries in the collection through hasNext, next(). * Will possibly return additional collection of entries, but will stop * returning new entries if the position in the input stream is past end. * * @param start The start index for the split * @param end The end index for the split * @param input The input stream containing the data * @throws IOException if there is a problem reading from the stream *///from www . j a va 2 s.co m public FastBufferedMessageChunksReader(final long start, long end, final FastBufferedInputStream input) throws IOException { super(); if (start < 0L) { throw new IllegalArgumentException("Start position (" + start + ") must not be less than zero"); } if (end != Long.MAX_VALUE && end < 0L) { throw new IllegalArgumentException("End position (" + end + ") must not be less than zero"); } if (start > end) { throw new IllegalArgumentException( "Start position (" + start + ") must not be greater than the end position (" + end + ")"); } if (end != Long.MAX_VALUE && start != end) { end += MessageChunksWriter.DELIMITER_LENGTH + 4; } startOffset = start; endOffset = end; this.input = input; this.in = new DataInputStream(input); supportedCodecRegistrationCodes = ChunkCodecHelper.registrationCodes(); reposition(start, end); }
From source file:mitm.common.security.password.PBEncryptionParameters.java
private void fromByteArray(byte[] encoded) throws IOException { ByteArrayInputStream bis = new ByteArrayInputStream(encoded); DataInputStream in = new DataInputStream(bis); long version = in.readLong(); if (version != serialVersionUID) { throw new SerializationException("Version expected '" + serialVersionUID + "' but got '" + version); }//from w w w . j a va 2 s .c om int saltSize = in.readInt(); this.salt = new byte[saltSize]; in.readFully(salt); this.iterationCount = in.readInt(); int encryptedSize = in.readInt(); this.encryptedData = new byte[encryptedSize]; in.readFully(encryptedData); }
From source file:com.bruce.study.demo.studydata.demos60.httpclient.MyHttpClientActivity.java
/** * ???/*from w ww . j av a 2s. c om*/ */ private void getNetInfo() { DataInputStream dataInputStream = null; try { URL url = new URL(ADDRESS); // ?? URLConnection urlConnection = url.openConnection(); // http // ?? dataInputStream = new DataInputStream(urlConnection.getInputStream()); // ?? // DataOutputStream dataOutputStream = new DataOutputStream(urlConnection.getOutputStream()) // ??? int temp = 0; byteArrayBuffer = new ByteArrayBuffer(1000); while ((temp = dataInputStream.read()) != -1) { byteArrayBuffer.append(temp); } // ?? MyHttpClientActivity.this.sendUIMessageEmpty(0x02); } catch (MalformedURLException e) { logE(e.toString()); } catch (IOException e) { logE(e.toString()); } finally { try { if (dataInputStream != null) { dataInputStream.close(); } } catch (IOException e) { logE(e.toString()); } } }
From source file:ffx.xray.CCP4MapFilter.java
/** * {@inheritDoc}//from ww w . j a v a 2 s.c o m */ @Override public Crystal getCrystal(String filename, CompositeConfiguration properties) { int imapdata; int sg = -1; double cella = -1.0; double cellb = -1.0; double cellc = -1.0; double cellalpha = -1.0; double cellbeta = -1.0; double cellgamma = -1.0; ByteOrder b = ByteOrder.nativeOrder(); FileInputStream fis; DataInputStream dis; // first determine byte order of file versus system try { fis = new FileInputStream(filename); dis = new DataInputStream(fis); dis.skipBytes(212); byte bytes[] = new byte[4]; dis.read(bytes, 0, 4); ByteBuffer bb = ByteBuffer.wrap(bytes); imapdata = bb.order(ByteOrder.BIG_ENDIAN).getInt(); String stampstr = Integer.toHexString(imapdata); // System.out.println("stamp: " + stampstr); switch (stampstr.charAt(0)) { case '1': case '3': if (b.equals(ByteOrder.LITTLE_ENDIAN)) { b = ByteOrder.BIG_ENDIAN; } break; case '4': if (b.equals(ByteOrder.BIG_ENDIAN)) { b = ByteOrder.LITTLE_ENDIAN; } break; } fis.close(); } catch (Exception e) { String message = "Fatal exception reading CCP4 map.\n"; logger.log(Level.SEVERE, message, e); System.exit(-1); } try { fis = new FileInputStream(filename); dis = new DataInputStream(fis); dis.skipBytes(40); byte bytes[] = new byte[80]; dis.read(bytes, 0, 80); ByteBuffer bb = ByteBuffer.wrap(bytes); cella = bb.order(b).getFloat(); cellb = bb.order(b).getFloat(); cellc = bb.order(b).getFloat(); cellalpha = bb.order(b).getFloat(); cellbeta = bb.order(b).getFloat(); cellgamma = bb.order(b).getFloat(); for (int i = 0; i < 3; i++) { bb.order(b).getInt(); } for (int i = 0; i < 3; i++) { bb.order(b).getFloat(); } sg = bb.order(b).getInt(); fis.close(); } catch (Exception e) { String message = "Fatal exception reading CCP4 map.\n"; logger.log(Level.SEVERE, message, e); System.exit(-1); } return new Crystal(cella, cellb, cellc, cellalpha, cellbeta, cellgamma, SpaceGroup.spaceGroupNames[sg - 1]); }
From source file:com.github.terma.m.server.Repo.java
public Map<String, Short> readMetricCodes() throws IOException { Map<String, Short> result = new HashMap<>(); DataInputStream ois = null;//w w w . ja v a2 s .c o m try { ois = new DataInputStream(new FileInputStream(eventCodesFile)); //noinspection InfiniteLoopStatement while (true) { result.put(ois.readUTF(), ois.readShort()); } } catch (EOFException | FileNotFoundException e) { // just end } finally { IOUtils.closeQuietly(ois); } return result; }
From source file:com.igormaznitsa.jhexed.hexmap.HexFieldLayer.java
public HexFieldLayer(final InputStream in) throws IOException { final DataInputStream din = in instanceof DataInputStream ? (DataInputStream) in : new DataInputStream(in); this.name = din.readUTF(); this.comments = din.readUTF(); final int valuesNum = din.readShort() & 0xFFFF; for (int i = 0; i < valuesNum; i++) { final HexFieldValue value = HexFieldValue.readValue(in); value.setIndex(i);//from w w w . j ava2s . c o m this.values.add(value); } this.columns = din.readInt(); this.rows = din.readInt(); this.visible = din.readBoolean(); final byte[] packedLayerData = new byte[din.readInt()]; IOUtils.readFully(din, packedLayerData); this.array = Utils.unpackArray(packedLayerData); if (this.array.length != (this.columns * this.rows)) throw new IOException("Wrong field size"); }
From source file:com.athena.chameleon.engine.core.analyzer.parser.Parser.java
/** * <pre>/*from www . ja v a2s . c o m*/ * ?? ? ? . * </pre> * @param file * @return * @throws IOException */ protected String fileToString(String file) throws IOException { // return IOUtils.toString(file.toURI()); String result = null; DataInputStream in = null; File f = new File(file); byte[] buffer = new byte[(int) f.length()]; in = new DataInputStream(new FileInputStream(f)); in.readFully(buffer); result = new String(buffer); IOUtils.closeQuietly(in); return result; }
From source file:ffx.realspace.CCP4MapFilter.java
/** * {@inheritDoc}//from w w w .ja v a2 s . co m */ @Override public Crystal getCrystal(String fileName, CompositeConfiguration properties) { int imapData; int spaceGroup = -1; double cellA = -1.0; double cellB = -1.0; double cellC = -1.0; double cellAlpha = -1.0; double cellBeta = -1.0; double cellGamma = -1.0; ByteOrder byteOrder = ByteOrder.nativeOrder(); FileInputStream fileInputStream; DataInputStream dataInputStream; // first determine byte order of file versus system try { fileInputStream = new FileInputStream(fileName); dataInputStream = new DataInputStream(fileInputStream); dataInputStream.skipBytes(212); byte bytes[] = new byte[4]; dataInputStream.read(bytes, 0, 4); ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); imapData = byteBuffer.order(ByteOrder.BIG_ENDIAN).getInt(); String stampString = Integer.toHexString(imapData); switch (stampString.charAt(0)) { case '1': case '3': if (byteOrder.equals(ByteOrder.LITTLE_ENDIAN)) { byteOrder = ByteOrder.BIG_ENDIAN; } break; case '4': if (byteOrder.equals(ByteOrder.BIG_ENDIAN)) { byteOrder = ByteOrder.LITTLE_ENDIAN; } break; } fileInputStream.close(); } catch (Exception e) { String message = " Fatal exception reading CCP4 map.\n"; logger.log(Level.SEVERE, message, e); } try { fileInputStream = new FileInputStream(fileName); dataInputStream = new DataInputStream(fileInputStream); dataInputStream.skipBytes(40); byte bytes[] = new byte[80]; dataInputStream.read(bytes, 0, 80); ByteBuffer byteBuffer = ByteBuffer.wrap(bytes); cellA = byteBuffer.order(byteOrder).getFloat(); cellB = byteBuffer.order(byteOrder).getFloat(); cellC = byteBuffer.order(byteOrder).getFloat(); cellAlpha = byteBuffer.order(byteOrder).getFloat(); cellBeta = byteBuffer.order(byteOrder).getFloat(); cellGamma = byteBuffer.order(byteOrder).getFloat(); for (int i = 0; i < 3; i++) { byteBuffer.order(byteOrder).getInt(); } for (int i = 0; i < 3; i++) { byteBuffer.order(byteOrder).getFloat(); } spaceGroup = byteBuffer.order(byteOrder).getInt(); fileInputStream.close(); } catch (Exception e) { String message = " Fatal exception reading CCP4 map.\n"; logger.log(Level.SEVERE, message, e); } return new Crystal(cellA, cellB, cellC, cellAlpha, cellBeta, cellGamma, SpaceGroup.spaceGroupNames[spaceGroup - 1]); }