java.io.DataInputStream.readFully()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(606)

本文整理了Java中java.io.DataInputStream.readFully()方法的一些代码示例,展示了DataInputStream.readFully()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DataInputStream.readFully()方法的具体详情如下:
包路径:java.io.DataInputStream
类名称:DataInputStream
方法名:readFully

DataInputStream.readFully介绍

[英]See the general contract of the readFully method of DataInput.

Bytes for this operation are read from the contained input stream.
[中]参见readFully方法DataInput的总合同。
此操作的字节从包含的输入流中读取。

代码示例

代码示例来源:origin: redisson/redisson

protected AttributeInfo(ConstPool cp, int n, DataInputStream in)
  throws IOException
{
  constPool = cp;
  name = n;
  int len = in.readInt();
  info = new byte[len];
  if (len > 0)
    in.readFully(info);
}

代码示例来源:origin: jenkinsci/jenkins

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);
  }
}

代码示例来源:origin: stackoverflow.com

...
byte[] imgDataBa = new byte[(int)imgFile.length()];
DataInputStream dataIs = new DataInputStream(new FileInputStream(imgFile));
dataIs.readFully(imgDataBa);
...

代码示例来源:origin: jenkinsci/jenkins

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)) {

代码示例来源:origin: mpusher/mpush

@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();
}

代码示例来源:origin: spotbugs/spotbugs

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

代码示例来源:origin: stackoverflow.com

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;

代码示例来源:origin: h2oai/h2o-3

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();

代码示例来源:origin: stackoverflow.com

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));

代码示例来源:origin: stackoverflow.com

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;
}

代码示例来源:origin: kilim/kilim

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;
}

代码示例来源:origin: apache/tika

/**
 * 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();
}

代码示例来源:origin: org.apache.hadoop/hadoop-common

/**
 * 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();
 }
}

代码示例来源:origin: marytts/marytts

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);

代码示例来源:origin: stackoverflow.com

File file = new File("myFile");
 byte[] fileData = new byte[(int) file.length()];
 DataInputStream dis = new DataInputStream(new FileInputStream(file));
 dis.readFully(fileData);
 dis.close();

代码示例来源:origin: apache/usergrid

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 );
}

代码示例来源:origin: com.h2database/h2

DataInputStream in = new DataInputStream(new FileInputStream(classFile));
  in.readFully(data);
  in.close();
  return data;
} catch (Exception e) {

代码示例来源:origin: AsamK/signal-cli

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);

代码示例来源:origin: redisson/redisson

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);
  }
}

代码示例来源:origin: nutzam/nutz

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) {

相关文章