private static String readPemFile(File f) throws IOException{ try (InputStream is = Files.newInputStream(f.toPath()); DataInputStream dis = new DataInputStream(is)) { byte[] bytes = new byte[(int) f.length()]; dis.readFully(bytes); return new String(bytes); } catch (InvalidPathException e) { throw new IOException(e); } }
... byte[] imgDataBa = new byte[(int)imgFile.length()]; DataInputStream dataIs = new DataInputStream(new FileInputStream(imgFile)); dataIs.readFully(imgDataBa); ...
try { byte[] preamble = new byte[PREAMBLE.length]; in.readFully(preamble); if (!Arrays.equals(preamble,PREAMBLE)) return null; // not a valid preamble DataInputStream decoded = new DataInputStream(new UnbufferedBase64InputStream(in)); int macSz = - decoded.readInt(); byte[] mac; int sz; if (macSz > 0) { // new format mac = new byte[macSz]; decoded.readFully(mac); sz = decoded.readInt(); } else { mac = null; decoded.readFully(buf); in.readFully(postamble); if (!Arrays.equals(postamble,POSTAMBLE)) return null; // not a valid postamble try (ObjectInputStream ois = new ObjectInputStreamEx(new GZIPInputStream(new ByteArrayInputStream(buf)), jenkins != null ? jenkins.pluginManager.uberClassLoader : ConsoleNote.class.getClassLoader(), ClassFilter.DEFAULT)) {
@SuppressWarnings("unchecked") private <T> T asObject(byte[] bytes) throws Exception { ByteArrayInputStream byteIn = new ByteArrayInputStream(bytes); DataInputStream in = new DataInputStream(byteIn); byte[] body = new byte[in.available()]; in.readFully(body); ObjectInputStream objectIn = new ObjectInputStream(new ByteArrayInputStream(body)); return (T) objectIn.readObject(); }
public static byte[] getByteFileFixed(String byteFileName, int n) { File f = new File(byteFileName); if (!(f.exists() && f.isFile() && f.canRead() && f.length() == n)) return null; DataInputStream ds; try { ds = new DataInputStream(new FileInputStream(f)); } catch (FileNotFoundException e) { return null; } try { byte[] bytes = new byte[n]; ds.readFully(bytes); return bytes; } catch (IOException e) { return null; } finally { try { ds.close(); } catch (IOException e) { assert true; // nothing to do at this point } } } // end getByteFile
FileInputStream is = new FileInputStream("yourKeyStore.keystore"); FileInputStream in = new FileInputStream(keystoreFile); keystore.load(in, password); in.close(); FileInputStream fis = new FileInputStream(fname); DataInputStream dis = new DataInputStream(fis); byte[] bytes = new byte[dis.available()]; dis.readFully(bytes); ByteArrayInputStream bais = new ByteArrayInputStream(bytes); return bais;
DataInputStream pixels = new DataInputStream(new GZIPInputStream(new FileInputStream(new File( home + "/train-images-idx3-ubyte.gz")))); DataInputStream labels = new DataInputStream(new GZIPInputStream(new FileInputStream(new File( home + "/train-labels-idx1-ubyte.gz")))); pixels.readInt(); // Magic int count = pixels.readInt(); pixels.readInt(); // Rows pixels.readInt(); // Cols byte[] rawL = new byte[count]; for (int i = 0; i < count; i++) { pixels.readFully(rawI[i]); rawL[i] = labels.readByte();
ByteArrayInputStream headerIn = new ByteArrayInputStream(headerBytes); Properties props = new Properties(); props.load(headerIn); reset(); byte[] header = new byte[headerLen]; readFully(header); try { mContentLength = parseContentLength(header); byte[] frameData = new byte[mContentLength]; skipBytes(headerLen); readFully(frameData); return BitmapFactory.decodeStream(new ByteArrayInputStream(frameData));
public byte[] readBytes() throws IOException { // Again, probably better to store these objects references in the support class InputStream in = socket.getInputStream(); DataInputStream dis = new DataInputStream(in); int len = dis.readInt(); byte[] data = new byte[len]; if (len > 0) { dis.readFully(data); } return data; }
public static byte[] readFully(FileLister.Entry fe) throws IOException { DataInputStream in = new DataInputStream(fe.getInputStream()); byte[] contents = new byte[(int)fe.getSize()]; in.readFully(contents); in.close(); return contents; }
/** * Deserializes an object from the given stream. The serialized object * is expected to be preceded by a size integer, that is used for reading * the entire serialization into a memory before deserializing it. * * @param input input stream from which the serialized object is read * @param loader class loader to be used for loading referenced classes * @throws IOException if the object could not be deserialized * @throws ClassNotFoundException if a referenced class is not found */ public static Object readObject(DataInputStream input, ClassLoader loader) throws IOException, ClassNotFoundException { int n = input.readInt(); byte[] data = new byte[n]; input.readFully(data); ObjectInputStream deserializer = new ForkObjectInputStream(new ByteArrayInputStream(data), loader); return deserializer.readObject(); }
/** * Writing the value to the output stream. This method avoids copying * value data from Scanner into user buffer, then writing to the output * stream. It does not require the value length to be known. * * @param out * The output stream * @return the length of the value * @throws IOException */ public long writeValue(OutputStream out) throws IOException { DataInputStream dis = getValueStream(); long size = 0; try { int chunkSize; while ((chunkSize = valueBufferInputStream.getRemain()) > 0) { chunkSize = Math.min(chunkSize, MAX_VAL_TRANSFER_BUF_SIZE); valTransferBuffer.setSize(chunkSize); dis.readFully(valTransferBuffer.getBytes(), 0, chunkSize); out.write(valTransferBuffer.getBytes(), 0, chunkSize); size += chunkSize; } return size; } finally { dis.close(); } }
private void loadHeaderless(InputStream inStream, String encoding, boolean verbose) throws IOException, UnsupportedEncodingException { int i; DataInputStream in = new DataInputStream(new BufferedInputStream(inStream)); int nArcs = in.readInt(); int thisArc = in.readInt(); int nPairs = in.readInt(); offsets = new short[2 * nPairs]; for (i = 0; i < 2 * nPairs; i++) mapping = new int[nBytes]; bytes = new byte[nBytes]; in.readFully(bytes); if (verbose) { System.err.println("FST (" + fileSize + " Bytes, " + nArcs + " Arcs, " + nPairs + " Labels)" + " loaded"); in.close(); createMapping(mapping, bytes, encoding);
File file = new File("myFile"); byte[] fileData = new byte[(int) file.length()]; DataInputStream dis = new DataInputStream(new FileInputStream(file)); dis.readFully(fileData); dis.close();
private static InputStream getCertificateStream () throws IOException { InputStream in = ChopUtils.class.getClassLoader().getResourceAsStream( "runner.cer" ); DataInputStream dis = new DataInputStream( in ); byte[] bytes = new byte[ dis.available() ]; dis.readFully( bytes ); return new ByteArrayInputStream( bytes ); }
DataInputStream in = new DataInputStream(new FileInputStream(classFile)); in.readFully(data); in.close(); return data; } catch (Exception e) {
static SignalServiceEnvelope loadEnvelope(File file) throws IOException { try (FileInputStream f = new FileInputStream(file)) { DataInputStream in = new DataInputStream(f); int version = in.readInt(); if (version > 2) { return null; int type = in.readInt(); String source = in.readUTF(); int sourceDevice = in.readInt(); if (version == 1) { if (contentLen > 0) { content = new byte[contentLen]; in.readFully(content); if (legacyMessageLen > 0) { legacyMessage = new byte[legacyMessageLen]; in.readFully(legacyMessage);
public static SnappyCodec readHeader(InputStream in) throws IOException { DataInputStream d = new DataInputStream(in); byte[] magic = new byte[MAGIC_LEN]; d.readFully(magic, 0, MAGIC_LEN); int version = d.readInt(); int compatibleVersion = d.readInt(); return new SnappyCodec(magic, version, compatibleVersion); } }
DataInputStream dis = new DataInputStream(new BufferedInputStream(in)); Map<Integer, String> strs = new HashMap<Integer, String>(); Map<Integer, Integer> classes = new HashMap<Integer, Integer>(); int len = dis.readUnsignedShort(); byte[] data = new byte[len]; dis.readFully(data); strs.put(i + 1, new String(data, Encoding.UTF8));//必然是UTF8的 break; if (name != null) name = name.replace('/', '.'); dis.close(); return name; } catch (Throwable e) {