hudson.util.IOUtils.skip()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(4.3k)|赞(0)|评价(0)|浏览(114)

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

IOUtils.skip介绍

[英]Fully skips the specified size from the given input stream.

InputStream#skip(long) has two problems. One is that it doesn't let us reliably differentiate "hit EOF" case vs "inpustream just returning 0 since there's no data currently available at hand", and some subtypes (such as FileInputStream#skip(long) returning -1.

So to reliably skip just the N bytes, we'll actually read all those bytes.
[中]从给定的输入流中完全跳过指定的大小。
InputStream#skip(long)有两个问题。一个是,它不允许我们可靠地区分“hit EOF”案例与“inpustream仅返回0,因为当前手头没有可用数据”,以及某些子类型(例如FileInputStream#skip(long)返回-1)。
因此,为了可靠地跳过N个字节,我们将实际读取所有这些字节。

代码示例

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

/**
 * Skips the encoded console note.
 */
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 macSz = - decoded.readInt();
  if (macSz > 0) { // new format
    IOUtils.skip(decoded, macSz);
    int sz = decoded.readInt();
    IOUtils.skip(decoded, sz);
  } else { // old format
    int sz = -macSz;
    IOUtils.skip(decoded, sz);
  }
  byte[] postamble = new byte[POSTAMBLE.length];
  in.readFully(postamble);
}

代码示例来源:origin: jenkinsci/m2release-plugin

private void drainOutput(HttpURLConnection conn) throws IOException {
  // for things like unauthorised (401) we won't have any content and getting the inputStream will
  // cause an IOException as we are in error - but there is no really way to tell this so check the
  // length instead.
  if (conn.getContentLength() > 0) {
    if (conn.getContentLength() < 1024) {
      byte[] data = new byte[conn.getConnectTimeout()];
    }
    if (conn.getErrorStream() != null) {
      IOUtils.skip(conn.getErrorStream(), conn.getContentLength());
    }
    else {
      IOUtils.skip(conn.getInputStream(), conn.getContentLength());
    }
  }
}

代码示例来源:origin: org.jenkins-ci.main/jenkins-core

/**
 * Skips the encoded console note.
 */
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 macSz = - decoded.readInt();
  if (macSz > 0) { // new format
    IOUtils.skip(decoded, macSz);
    int sz = decoded.readInt();
    IOUtils.skip(decoded, sz);
  } else { // old format
    int sz = -macSz;
    IOUtils.skip(decoded, sz);
  }
  byte[] postamble = new byte[POSTAMBLE.length];
  in.readFully(postamble);
}

代码示例来源:origin: org.jvnet.hudson.main/hudson-core

/**
 * Skips the encoded console note.
 */
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);
}

代码示例来源:origin: org.eclipse.hudson.main/hudson-core

/**
 * Skips the encoded console note.
 */
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);
}

代码示例来源:origin: hudson/hudson-2.x

/**
 * Skips the encoded console note.
 */
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);
}

代码示例来源:origin: org.eclipse.hudson/hudson-core

/**
 * Skips the encoded console note.
 */
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);
}
private static final long serialVersionUID = 1L;

相关文章