List of usage examples for java.io DataInputStream readInt
public final int readInt() throws IOException
readInt
method of DataInput
. From source file:Main.java
protected static int deserialiseLength(DataInputStream is, int max_length) throws IOException { int len;//from w ww . j a v a2 s . c o m if (max_length < 256) { len = is.readByte() & 0xff; } else if (max_length < 65536) { len = is.readShort() & 0xffff; } else { len = is.readInt(); } if (len > max_length) { throw (new IOException("Invalid DHT data length: max=" + max_length + ",actual=" + len)); } return (len); }
From source file:org.digidoc4j.utils.Helper.java
/** * @param stream aa//from w ww . j a va 2 s. co m * @return aa * @throws IOException aa */ public static boolean isZipFile(InputStream stream) throws IOException { DataInputStream in = new DataInputStream(stream); if (stream.markSupported()) stream.mark(INT_LENGTH); int test = in.readInt(); if (stream.markSupported()) stream.reset(); final int zipVerificationCode = ZIP_VERIFICATION_CODE; return test == zipVerificationCode; }
From source file:net.timewalker.ffmq4.storage.data.impl.journal.JournalRecovery.java
private static DataBlockWriteOperation readDataBlockWriteOperation(DataInputStream in) throws IOException { long transactionId = in.readLong(); long blockOffset = in.readLong(); int len = in.readInt(); byte[] dataBlock = new byte[len]; in.readFully(dataBlock);//from ww w .ja v a2s . c om return new DataBlockWriteOperation(transactionId, -1, blockOffset, dataBlock); }
From source file:net.timewalker.ffmq4.storage.data.impl.journal.JournalRecovery.java
private static MetaDataWriteOperation readMetaDataWriteOperation(DataInputStream in) throws IOException { long transactionId = in.readLong(); long metaDataOffset = in.readLong(); int metaData = in.readInt(); return new MetaDataWriteOperation(transactionId, metaDataOffset, metaData); }
From source file:org.geoserver.wps.ppio.ZipArchivePPIO.java
/** * This method tells us if the provided {@link File} is a Zip File. * /*ww w . ja v a2s. c om*/ * <p> * It throws {@link IllegalArgumentException} in case the provided file does not exists or is not a readable file. * * @param file the {@link File} to check for zip * @throws IOException in case something bad happen */ public static boolean isZpFile(File file) { if (file == null || !file.exists() || !file.canRead()) { throw new IllegalArgumentException( "Provided File is not valid and/or reqadable! --> File:" + file != null ? file.getAbsolutePath() : "null"); } // Check if the file is a directory if (file.isDirectory()) { return false; } // Check on the path length if (file.length() < 4) { return false; } // Check on the first Integer DataInputStream in = null; try { in = new DataInputStream(new FileInputStream(file)); int test = in.readInt(); return test == 0x504b0304; } catch (IOException e) { if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e); } return false; } finally { if (in != null) { org.apache.commons.io.IOUtils.closeQuietly(in); } } }
From source file:net.timewalker.ffmq4.storage.data.impl.journal.JournalRecovery.java
private static MetaDataBlockWriteOperation readMetaDataBlockWriteOperation(DataInputStream in) throws IOException { long transactionId = in.readLong(); long metaDataOffset = in.readLong(); int len = in.readInt(); byte[] metaData = new byte[len]; in.readFully(metaData);/*from ww w. j av a 2s .c o m*/ return new MetaDataBlockWriteOperation(transactionId, metaDataOffset, metaData); }
From source file:org.eclipse.swt.snippets.Snippet319.java
static MyType restoreFromByteArray(byte[] bytes) { DataInputStream dataInStream = null; try {//from w w w . j a va 2s .c om ByteArrayInputStream byteInStream = new ByteArrayInputStream(bytes); dataInStream = new DataInputStream(byteInStream); int size = dataInStream.readInt(); byte[] name = new byte[size]; dataInStream.read(name); MyType result = new MyType(); result.name = new String(name); result.time = dataInStream.readLong(); return result; } catch (IOException ex) { return null; } finally { if (dataInStream != null) { try { dataInStream.close(); } catch (IOException e) { } } } }
From source file:com.adaptris.security.StdOutput.java
private static byte[] read(DataInputStream in) throws IOException { byte[] bytes = new byte[in.readInt()]; if (bytes.length > 0) { in.read(bytes, 0, bytes.length); } else {//from ww w.ja va 2s .c o m bytes = null; } return bytes; }
From source file:hudson.console.ConsoleNote.java
/** * Skips the encoded console note./* www . ja v a2s .co m*/ */ public static void skip(DataInputStream in) throws IOException { byte[] preamble = new byte[PREAMBLE.length]; in.readFully(preamble); if (!Arrays.equals(preamble, PREAMBLE)) return; // not a valid preamble DataInputStream decoded = new DataInputStream(new UnbufferedBase64InputStream(in)); int sz = decoded.readInt(); IOUtils.skip(decoded, sz); byte[] postamble = new byte[POSTAMBLE.length]; in.readFully(postamble); }
From source file:ja.lingo.engine.mergedindex.ChannelMergedIndex.java
private static Map<Integer, IDictionaryIndex> _deserializeReaderIdToReaderMap(DataInputStream dis, Map<String, IDictionaryIndex> indexFileNameToReaderMap) throws IOException { Map<Integer, IDictionaryIndex> readerIdToReaderMap = new HashMap<Integer, IDictionaryIndex>(); int readerCount = dis.readInt(); for (int i = 0; i < readerCount; i++) { int readerId = dis.readInt(); String indexFileName = dis.readUTF(); IDictionaryIndex reader = indexFileNameToReaderMap.get(indexFileName); if (reader == null) { throw new IOException("Unable to retrieve reader with readerId=\"" + readerId + "\" and indexFileName=\"" + indexFileName + "\""); }/*from w ww. ja v a 2 s.co m*/ readerIdToReaderMap.put(readerId, reader); } return readerIdToReaderMap; }