List of usage examples for java.io DataInputStream readFully
public final void readFully(byte b[]) throws IOException
From source file:com.sshtools.appframework.ui.IconStore.java
private Icon get(String name, int size, String cacheKey, FileObject file) throws FileSystemException, IOException { Icon icon;//from w ww. j av a 2s .c o m if (file.getName().getBaseName().toLowerCase().endsWith(".svg")) { InputStream in = file.getContent().getInputStream(); try { icon = new SVGIcon(name + "-" + size, in, size, size); } finally { in.close(); } } else { DataInputStream din = new DataInputStream(file.getContent().getInputStream()); try { byte[] imgData = new byte[(int) file.getContent().getSize()]; din.readFully(imgData); icon = new ImageIcon(imgData); } finally { din.close(); } } if (icon.getIconWidth() != size && icon instanceof ImageIcon) { Image img = ((ImageIcon) icon).getImage(); img = img.getScaledInstance(size, size, Image.SCALE_SMOOTH); icon = new ImageIcon(img); } cache.put(cacheKey, icon); return icon; }
From source file:org.apache.hadoop.hdfs.TestDataTransferProtocol.java
private void sendRecvData(String testDescription, boolean eofExpected) throws IOException { /* Opens a socket to datanode * sends the data in sendBuf.//w ww .j a v a2 s. c om * If there is data in expectedBuf, expects to receive the data * from datanode that matches expectedBuf. * If there is an exception while recieving, throws it * only if exceptionExcepted is false. */ Socket sock = null; try { if (testDescription != null) { LOG.info("Testing : " + testDescription); } sock = new Socket(); sock.connect(dnAddr, HdfsConstants.READ_TIMEOUT); sock.setSoTimeout(HdfsConstants.READ_TIMEOUT); OutputStream out = sock.getOutputStream(); // Should we excuse byte[] retBuf = new byte[recvBuf.size()]; DataInputStream in = new DataInputStream(sock.getInputStream()); out.write(sendBuf.toByteArray()); try { in.readFully(retBuf); } catch (EOFException eof) { if (eofExpected) { LOG.info("Got EOF as expected."); return; } throw eof; } for (int i = 0; i < retBuf.length; i++) { System.out.print(retBuf[i]); } System.out.println(":"); if (eofExpected) { throw new IOException("Did not recieve IOException when an exception " + "is expected while reading from " + datanode.getName()); } byte[] needed = recvBuf.toByteArray(); for (int i = 0; i < retBuf.length; i++) { System.out.print(retBuf[i]); assertEquals("checking byte[" + i + "]", needed[i], retBuf[i]); } } finally { IOUtils.closeSocket(sock); } }
From source file:it.jnrpe.net.JNRPEProtocolPacket.java
/** * Loads the packet from the given input stream. * /*from w ww . j a va2 s .c o m*/ * @param in the packet input stream * @throws IOException on any error */ protected void fromInputStream(final InputStream in) throws IOException { DataInputStream din = new DataInputStream(in); packetVersion = din.readShort(); packetTypeCode = din.readShort(); crcValue = din.readInt(); resultCode = din.readShort(); din.readFully(byteBufferAry); din.readFully(dummyBytesAry); }
From source file:org.apache.nifi.distributed.cache.client.DistributedMapCacheClientService.java
private byte[] readLengthDelimitedResponse(final DataInputStream dis) throws IOException { final int responseLength = dis.readInt(); final byte[] responseBuffer = new byte[responseLength]; dis.readFully(responseBuffer); return responseBuffer; }
From source file:com.jivesoftware.os.amza.service.replication.http.endpoints.AmzaReplicationRestEndpoints.java
@POST @Consumes(MediaType.APPLICATION_OCTET_STREAM) @Produces(MediaType.APPLICATION_OCTET_STREAM) @Path("/ackBatch") public Response ackBatch(InputStream is) { try {/*from w ww .j a v a 2 s .co m*/ DataInputStream in = new DataInputStream(is); try { while (in.readByte() == 1) { int length = in.readShort(); byte[] bytes = new byte[length]; in.readFully(bytes); VersionedPartitionName versionedPartitionName = amzaInterner.internVersionedPartitionName(bytes, 0, length); length = in.readShort(); bytes = new byte[length]; in.readFully(bytes); RingMember ringMember = amzaInterner.internRingMember(bytes, 0, length); long takeSessionId = in.readLong(); long takeSharedKey = in.readLong(); long txId = in.readLong(); long leadershipToken = in.readLong(); amzaInstance.rowsTaken(ringMember, takeSessionId, takeSharedKey, versionedPartitionName, txId, leadershipToken); } if (in.readByte() == 1) { int length = in.readShort(); byte[] bytes = new byte[length]; in.readFully(bytes); RingMember ringMember = amzaInterner.internRingMember(bytes, 0, length); long takeSessionId = in.readLong(); long takeSharedKey = in.readLong(); amzaInstance.pong(ringMember, takeSessionId, takeSharedKey); } return Response.ok(conf.asByteArray(Boolean.TRUE)).build(); } finally { try { in.close(); } catch (Exception x) { LOG.error("Failed to close input stream", x); } } } catch (Exception x) { LOG.warn("Failed ackBatch", x); return ResponseHelper.INSTANCE.errorResponse("Failed ackBatch.", x); } finally { amzaStats.pongsReceived.increment(); } }
From source file:org.veronicadb.core.memorygraph.storage.SimpleLocalFileStorageSink.java
protected String readElementLabel(DataInputStream stream) throws IOException { int val = stream.readInt(); if (val == -1) { return null; } else {//from w ww . j a v a 2s .c o m byte[] label = new byte[val]; stream.readFully(label); return new String(label); } }
From source file:org.apache.jackrabbit.core.journal.FileRecordLog.java
/** * Read signature and major/minor version of file and verify. * * @param in input stream//from w ww. ja v a2 s.c o m * @throws java.io.IOException if an I/O error occurs or the file does * not have a valid header. */ private void readHeader(DataInputStream in) throws IOException { byte[] signature = new byte[SIGNATURE.length]; in.readFully(signature); for (int i = 0; i < SIGNATURE.length; i++) { if (signature[i] != SIGNATURE[i]) { String msg = "Record log '" + logFile.getPath() + "' has wrong signature: " + toHexString(signature); throw new IOException(msg); } } major = in.readShort(); if (major != MAJOR_VERSION) { String msg = "Record log '" + logFile.getPath() + "' has incompatible major version: " + major; throw new IOException(msg); } minor = in.readShort(); }
From source file:com.axelor.apps.account.service.payment.PayboxService.java
/** Chargement de la cle AU FORMAT der * Utliser la commande suivante pour 'convertir' la cl 'pem' en 'der' * openssl rsa -inform PEM -in pubkey.pem -outform DER -pubin -out pubkey.der */*w w w.j a v a2 s. c o m*/ * @param pubKeyFile * @return * @throws Exception */ @Deprecated private PublicKey getPubKeyDer(String pubKeyPath) throws Exception { FileInputStream fis = new FileInputStream(pubKeyPath); DataInputStream dis = new DataInputStream(fis); byte[] pubKeyBytes = new byte[fis.available()]; dis.readFully(pubKeyBytes); fis.close(); dis.close(); KeyFactory keyFactory = KeyFactory.getInstance(this.ENCRYPTION_ALGORITHM); // extraction cle X509EncodedKeySpec pubSpec = new X509EncodedKeySpec(pubKeyBytes); return keyFactory.generatePublic(pubSpec); }
From source file:com.bonsai.wallet32.WalletApplication.java
public List<WalletEntry> loadWalletDirectory() { File walletDirFile = new File(getFilesDir(), getWalletPrefix() + ".walletdir"); try {/*from w ww. j a v a2s . c o m*/ int len = (int) walletDirFile.length(); DataInputStream dis = new DataInputStream(new FileInputStream(walletDirFile)); byte[] jsondata = new byte[len]; dis.readFully(jsondata); String jsonstr = new String(jsondata); mLogger.info("loading: " + jsonstr); JSONObject rootobj = new JSONObject(jsonstr); JSONArray listobj = rootobj.getJSONArray("wallets"); ArrayList<WalletEntry> wallets = new ArrayList<WalletEntry>(); for (int ii = 0; ii < listobj.length(); ++ii) wallets.add(WalletEntry.loadJSON(listobj.getJSONObject(ii))); return wallets; } catch (Exception ex) { mLogger.error("loadWalletDirectory failed: " + ex.toString()); throw new RuntimeException(ex); } }
From source file:org.dspace.installer_edm.InstallerCrosswalk.java
/** * Aade contenido archivo class a nuevo archivo class en el jar * * @param jarOutputStream flujo de escritura para el jar * @throws IOException/*from www .ja v a 2s .co m*/ */ protected void addClass2Jar(JarOutputStream jarOutputStream) throws IOException { File file = new File(myInstallerWorkDirPath + fileSeparator + edmCrossWalkClass); byte[] fileData = new byte[(int) file.length()]; DataInputStream dis = new DataInputStream(new FileInputStream(file)); dis.readFully(fileData); dis.close(); jarOutputStream.putNextEntry(new JarEntry(edmCrossWalkClass)); jarOutputStream.write(fileData); jarOutputStream.closeEntry(); }