List of usage examples for java.io DataInputStream read
public int read() throws IOException
From source file:Main.java
public static void main(String[] args) throws IOException { byte[] b = { 1, 2, 3, 4, 5, 6, 7, 8, 9 }; FileOutputStream fos = new FileOutputStream("c:\\test.txt"); DataOutputStream dos = new DataOutputStream(fos); for (byte j : b) { dos.writeByte(j);/*from ww w .ja v a 2 s . c o m*/ } dos.flush(); InputStream is = new FileInputStream("c:\\test.txt"); DataInputStream dis = new DataInputStream(is); while (dis.available() > 0) { int k = dis.read(); System.out.print(k); dis.skipBytes(1); } }
From source file:Main.java
public static String readNullableString(DataInputStream in) throws IOException { if (in.read() != 0) { return in.readUTF(); } else {//from www. j av a 2 s . c om return null; } }
From source file:Main.java
public static long uint64FromStream(DataInputStream stream) throws IOException { return ((stream.read() & 0xFFL) << 0) | ((stream.read() & 0xFFL) << 8) | ((stream.read() & 0xFFL) << 16) | ((stream.read() & 0xFFL) << 24) | ((stream.read() & 0xFFL) << 32) | ((stream.read() & 0xFFL) << 40) | ((stream.read() & 0xFFL) << 48) | ((stream.read() & 0xFFL) << 56); }
From source file:Main.java
public static int uint16FromStream(DataInputStream stream) throws IOException { return (int) (((stream.read() & 0xFFL) << 0) | ((stream.read() & 0xFFL) << 8)); }
From source file:Main.java
public static int uint16FromStreamBE(DataInputStream stream) throws IOException { return (int) (((stream.read() & 0xFFL) << 8) | ((stream.read() & 0xFFL) << 0)); }
From source file:Main.java
public static int uint32FromStream(DataInputStream stream) throws IOException { return (int) (((stream.read() & 0xFFL) << 0) | ((stream.read() & 0xFFL) << 8) | ((stream.read() & 0xFFL) << 16) | ((stream.read() & 0xFFL) << 24)); }
From source file:net.timewalker.ffmq4.storage.data.impl.journal.JournalRecovery.java
public static AbstractJournalOperation readJournalOperation(DataInputStream in) { try {/*from w ww . j a v a 2s. c om*/ int operationType = in.read(); if (operationType == -1) return null; // EOF switch (operationType) { case 0: // Padding return null; case AbstractJournalOperation.TYPE_META_DATA_WRITE: return readMetaDataWriteOperation(in); case AbstractJournalOperation.TYPE_META_DATA_BLOCK_WRITE: return readMetaDataBlockWriteOperation(in); case AbstractJournalOperation.TYPE_DATA_BLOCK_WRITE: return readDataBlockWriteOperation(in); case AbstractJournalOperation.TYPE_STORE_EXTEND: return readStoreExtendOperation(in); case AbstractJournalOperation.TYPE_COMMIT: return readCommitOperation(in); default: throw new IllegalArgumentException("Invalid operation type : " + operationType); } } catch (Exception e) { log.error("Corrupted or truncated journal operation, skipping.", e); return null; } }
From source file:org.beanfuse.archiver.ZipUtils.java
public static File zip(List fileNames, String zipPath, String encoding) { try {// w ww . ja va2s.c om FileOutputStream f = new FileOutputStream(zipPath); ZipOutputStream out = new ZipOutputStream(new DataOutputStream(f)); out.setEncoding(encoding); for (int i = 0; i < fileNames.size(); i++) { DataInputStream in = new DataInputStream(new FileInputStream(fileNames.get(i).toString())); out.putNextEntry(new org.apache.tools.zip.ZipEntry( StringUtils.substringAfterLast(fileNames.get(i).toString(), File.separator))); int c; while ((c = in.read()) != -1) { out.write(c); } in.close(); } out.close(); return new File(zipPath); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:Main.java
private static boolean isRootOk(DataOutputStream output, DataInputStream input, final DataInputStream errInput) { if (output != null) { try {//from ww w .j a v a 2 s. c o m output.writeBytes("id\n"); output.flush(); String a = input.readLine(); if (a.contains("root") || a.contains("uid=0")) { return true; } new Thread() { @Override public void run() { try { errInput.read(); } catch (IOException e) { e.printStackTrace(); } }; }.start(); } catch (IOException e) { e.printStackTrace(); } } return false; }
From source file:com.android.hierarchyviewerlib.device.DeviceBridge.java
private static boolean readLayer(DataInputStream in, PsdFile psd) { try {// w w w.j av a 2 s. co m if (in.read() == 2) { return false; } String name = in.readUTF(); boolean visible = in.read() == 1; int x = in.readInt(); int y = in.readInt(); int dataSize = in.readInt(); byte[] data = new byte[dataSize]; int read = 0; while (read < dataSize) { read += in.read(data, read, dataSize - read); } ByteArrayInputStream arrayIn = new ByteArrayInputStream(data); BufferedImage chunk = ImageIO.read(arrayIn); // Ensure the image is in the right format BufferedImage image = new BufferedImage(chunk.getWidth(), chunk.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g = image.createGraphics(); g.drawImage(chunk, null, 0, 0); g.dispose(); psd.addLayer(name, image, new Point(x, y), visible); return true; } catch (Exception e) { return false; } }