当前位置: 首页>>代码示例>>Java>>正文


Java InputStream.skip方法代码示例

本文整理汇总了Java中java.io.InputStream.skip方法的典型用法代码示例。如果您正苦于以下问题:Java InputStream.skip方法的具体用法?Java InputStream.skip怎么用?Java InputStream.skip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.InputStream的用法示例。


在下文中一共展示了InputStream.skip方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: skip

import java.io.InputStream; //导入方法依赖的package包/类
/**
 * Skips exactly bytesCount bytes in inputStream unless end of stream is reached first.
 *
 * @param inputStream input stream to skip bytes from
 * @param bytesCount number of bytes to skip
 * @return number of skipped bytes
 * @throws IOException
 */
public static long skip(final InputStream inputStream, final long bytesCount) throws IOException {
  Preconditions.checkNotNull(inputStream);
  Preconditions.checkArgument(bytesCount >= 0);

  long toSkip = bytesCount;
  while (toSkip > 0) {
    final long skipped = inputStream.skip(toSkip);
    if (skipped > 0) {
      toSkip -= skipped;
      continue;
    }

    if (inputStream.read() != -1) {
      toSkip--;
      continue;
    }
    return bytesCount - toSkip;
  }

  return bytesCount;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:StreamUtil.java

示例2: moveToTiffEntryWithTag

import java.io.InputStream; //导入方法依赖的package包/类
/**
 * Positions the given input stream to the entry that has a specified tag. Tag will be consumed.
 * @param is the input stream of TIFF data positioned to the beginning of an IFD.
 * @param length length of the available data in the given input stream.
 * @param isLittleEndian whether the TIFF data is stored in little or big endian format
 * @param tagToFind tag to find
 * @return remaining length of the data on success, 0 on failure
 */
private static int moveToTiffEntryWithTag(
    InputStream is,
    int length,
    boolean isLittleEndian,
    int tagToFind)
    throws IOException {
  if (length < 14) {
    return 0;
  }
  // read the number of entries and go through all of them
  // each IFD entry has length of 12 bytes and is composed of
  // {TAG [2], TYPE [2], COUNT [4], VALUE/OFFSET [4]}
  int numEntries = StreamProcessor.readPackedInt(is, 2, isLittleEndian);
  length -= 2;
  while (numEntries-- > 0 && length >= 12) {
    int tag = StreamProcessor.readPackedInt(is, 2, isLittleEndian);
    length -= 2;
    if (tag == tagToFind) {
      return length;
    }
    is.skip(10);
    length -= 10;
  }
  return 0;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:34,代码来源:TiffUtil.java

示例3: skipFully

import java.io.InputStream; //导入方法依赖的package包/类
public static void skipFully(InputStream is, long num_bytes) throws EOFException, IOException {
	long num_skipped = 0;
	while (num_skipped < num_bytes) {
		long just_skipped = is.skip(num_bytes - num_skipped);
		if (just_skipped > 0)
			num_skipped += just_skipped;
		else {
			if (is.read() < 0)
				throw new EOFException("Skipped only " + num_skipped + " bytes to end of file.");
			else
				++num_skipped;
		}
	}
}
 
开发者ID:juebanlin,项目名称:util4j,代码行数:15,代码来源:InputStreamUtils.java

示例4: copy

import java.io.InputStream; //导入方法依赖的package包/类
private static void copy(InputStream input, OutputStream output, long inputSize, long start, long length)
        throws IOException {
    byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
    int read;

    if (inputSize == length) {
        // Write full range.
        while ((read = input.read(buffer)) > 0) {
            output.write(buffer, 0, read);
            output.flush();
        }
    } else {
        long skipped = input.skip(start);
        Assert.isTrue(skipped == start);

        long toRead = length;

        while ((read = input.read(buffer)) > 0) {
            toRead -= read;
            if (toRead > 0) {
                output.write(buffer, 0, read);
                output.flush();
            } else {
                output.write(buffer, 0, (int) toRead + read);
                output.flush();
                break;
            }
        }
    }
}
 
开发者ID:react-dev26,项目名称:NGB-master,代码行数:31,代码来源:MultipartFileSender.java

示例5: modbusWriteSingle

import java.io.InputStream; //导入方法依赖的package包/类
public int modbusWriteSingle(int uid, int address, int val) throws IOException {
  OutputStream os = socket.getOutputStream();

  byte[] req = new byte[] { 0, 1, 0, 0, 0, 6, (byte) uid, (byte) FNC_WRITE_SINGLE, // header
      (byte) (address / 256), (byte) (address % 256), 
      (byte) (val / 256), (byte) (val % 256)};

  os.write(req);
  os.flush();

  InputStream is = socket.getInputStream();
  is.skip(7); // ids
  int code = is.read();
  if (code == (FNC_ERR_FLAG | FNC_WRITE_SINGLE)) {
    int ec = is.read();
    if (ec == ERR_SLAVE_DEVICE_FAILURE)
      throw new RuntimeException("Modbus error. Check if 'Inverter control via Modbus' is enabled.");
    throw new RuntimeException("modbus error " + ec);
  }
  if (code != 6)
    throw new RuntimeException("modbus response error fnc = " + code);
  int response;
  byte[] buff = new byte[2];
  if (is.read(buff) == -1)  // address
    throw new RuntimeException("response error");
  if (is.read(buff) == -1)  // value
    throw new RuntimeException("response error");
  int hi = buff[0] & 0xFF;
  int lo = buff[1] & 0xFF;
  response = hi * 256 + lo;
  return response;
}
 
开发者ID:jandrassy,项目名称:battsett,代码行数:33,代码来源:BattSett.java

示例6: getInputStream

import java.io.InputStream; //导入方法依赖的package包/类
public InputStream getInputStream(TinkerZipEntry entry) throws IOException {
    entry = getEntry(entry.getName());
    if (entry == null) {
        return null;
    }
    InputStream rafStream;
    RandomAccessFile localRaf = this.raf;
    synchronized (localRaf) {
        rafStream = new RAFStream(localRaf, entry.localHeaderRelOffset);
        DataInputStream is = new DataInputStream(rafStream);
        int localMagic = Integer.reverseBytes(is.readInt());
        if (((long) localMagic) != ZipConstants.LOCSIG) {
            throwZipException(this.filename, localRaf.length(), entry.getName(), entry
                    .localHeaderRelOffset, "Local File Header", localMagic);
        }
        is.skipBytes(2);
        int gpbf = Short.reverseBytes(is.readShort()) & 65535;
        if ((gpbf & 1) != 0) {
            throw new ZipException("Invalid General Purpose Bit Flag: " + gpbf);
        }
        is.skipBytes(18);
        int fileNameLength = Short.reverseBytes(is.readShort()) & 65535;
        int extraFieldLength = Short.reverseBytes(is.readShort()) & 65535;
        is.close();
        rafStream.skip((long) (fileNameLength + extraFieldLength));
        if (entry.compressionMethod == 0) {
            rafStream.endOffset = rafStream.offset + entry.size;
        } else {
            rafStream.endOffset = rafStream.offset + entry.compressedSize;
        }
    }
    return rafStream;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:34,代码来源:TinkerZipFile.java

示例7: moveToMarker

import java.io.InputStream; //导入方法依赖的package包/类
/**
 *  Reads the content of the input stream until specified marker is found. Marker will be
 *  consumed and the input stream will be positioned after the specified marker.
 *  @param is the input stream to read bytes from
 *  @param markerToFind the marker we are looking for
 *  @return boolean: whether or not we found the expected marker from input stream.
 */
public static boolean moveToMarker(InputStream is, int markerToFind) throws IOException {
  Preconditions.checkNotNull(is);
  // ISO/IEC 10918-1:1993(E)
  while (StreamProcessor.readPackedInt(is, 1, false) == MARKER_FIRST_BYTE) {
    int marker = MARKER_FIRST_BYTE;
    while (marker == MARKER_FIRST_BYTE) {
      marker = StreamProcessor.readPackedInt(is, 1, false);
    }

    if (markerToFind == MARKER_SOFn && isSOFn(marker)) {
      return true;
    }
    if (marker == markerToFind) {
      return true;
    }

    // Check if the marker is SOI or TEM. These two don't have length field, so we skip it.
    if (marker == MARKER_SOI || marker == MARKER_TEM) {
      continue;
    }

    // Check if the marker is EOI or SOS. We will stop reading since metadata markers don't
    // come after these two markers.
    if (marker == MARKER_EOI || marker == MARKER_SOS) {
      return false;
    }

    // read block length
    // subtract 2 as length contain SIZE field we just read
    int length = StreamProcessor.readPackedInt(is, 2, false) - 2;
    // Skip other markers.
    is.skip(length);
  }
  return false;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:43,代码来源:JfifUtil.java

示例8: getVP8Dimension

import java.io.InputStream; //导入方法依赖的package包/类
/**
 * We manage the Simple WebP case
 *
 * @param is The InputStream we're reading
 * @return The dimensions if any
 * @throws IOException In case or error reading from the InputStream
 */
private static Pair<Integer, Integer> getVP8Dimension(final InputStream is) throws IOException {
  // We need to skip 7 bytes
  is.skip(7);
  // And then check the signature
  final short sign1 = getShort(is);
  final short sign2 = getShort(is);
  final short sign3 = getShort(is);
  if (sign1 != 0x9D || sign2 != 0x01 || sign3 != 0x2A) {
    // Signature error
    return null;
  }
  // We read the dimensions
  return new Pair<>(get2BytesAsInt(is), get2BytesAsInt(is));
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:WebpUtil.java

示例9: read

import java.io.InputStream; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public Chunk read(final GUID guid, final InputStream stream, final long chunkStart) throws IOException
{
    final BigInteger chunkLen = Utils.readBig64(stream);
    final EncodingChunk result = new EncodingChunk(chunkLen);
    int readBytes = 24;
    // Can't be interpreted
    /*
     * What do I think of this data, well it seems to be another GUID. Then
     * followed by a UINT16 indicating a length of data following (by half).
     * My test files just had the length of one and a two bytes zero.
     */
    stream.skip(20);
    readBytes += 20;

    /*
     * Read the number of strings which will follow
     */
    final int stringCount = Utils.readUINT16(stream);
    readBytes += 2;

    /*
     * Now reading the specified amount of strings.
     */
    for (int i = 0; i < stringCount; i++)
    {
        final String curr = Utils.readCharacterSizedString(stream);
        result.addString(curr);
        readBytes += 4 + 2 * curr.length();
    }
    stream.skip(chunkLen.longValue() - readBytes);
    result.setPosition(chunkStart);
    return result;
}
 
开发者ID:GlennioTech,项目名称:MetadataEditor,代码行数:37,代码来源:EncodingChunkReader.java

示例10: skip

import java.io.InputStream; //导入方法依赖的package包/类
private long skip(final InputStream in, final long offset) throws IOException {
      long skipped = in.skip(offset);
int attempts = 10;
      // try to skip 10 times as skip(..) method does not guarantee to skip exactly given number of bytes
      while (skipped < offset && attempts > 0) {
	skipped += in.skip(offset - skipped);
	attempts--;
}
      return skipped;
  }
 
开发者ID:Samsung,项目名称:microbit,代码行数:11,代码来源:HexInputStream.java

示例11: decompress

import java.io.InputStream; //导入方法依赖的package包/类
public static int[] decompress(ROM rom, int offset) {
    InputStream stream = new ByteArrayInputStream(rom.getData());
    HexInputStream hexStream = new HexInputStream(stream);

    try {
        stream.skip(offset);

        return CompressUtils.decompress(hexStream);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:hugmanrique,项目名称:PokeData,代码行数:14,代码来源:Lz77.java

示例12: main

import java.io.InputStream; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    try
    {
        setUp();

        for (int i = 0; i < 8; i++) {
            ModelByteBuffer buff;
            if(i % 2 == 0)
                buff = new ModelByteBuffer(test_file);
            else
                buff = new ModelByteBuffer(test_byte_array);
            if((i / 2) == 1)
                buff.subbuffer(5);
            if((i / 2) == 2)
                buff.subbuffer(5,500);
            if((i / 2) == 3)
                buff.subbuffer(5,600,true);

            long capacity = buff.capacity();
            InputStream is = buff.getInputStream();
            try
            {
                int ret = is.available();
                long n = is.skip(75);
                if(n == -1)
                    throw new RuntimeException("is.read shouldn't return -1!");
                if(is.available() != ret - n)
                    throw new RuntimeException(
                            "is.available() returns incorrect value ("
                            + is.available() + "!="+(ret - n)+") !");

                ret = is.available();
                n = is.skip(-100);
                if(n != 0)
                    throw new RuntimeException("is.skip(-100) shouldn't skip values!");
                if(is.available() != ret - n)
                    throw new RuntimeException(
                            "is.available() returns incorrect value ("
                            + is.available() + "!="+(ret - n)+") !");

                ret = is.available();
                n = is.skip(5000);
                if(is.available() != ret - n)
                    throw new RuntimeException(
                            "is.available() returns incorrect value ("
                            + is.available() + "!="+(ret - n)+") !");
                if(is.available() != 0)
                    throw new RuntimeException(
                            "is.available() returns incorrect value ("
                            + is.available() + "!="+(0)+") !");                }
            finally
            {
                is.close();
            }
            if(buff.capacity() != capacity)
                throw new RuntimeException("Capacity variable should not change!");
        }
    }
    finally
    {
        tearDown();
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:64,代码来源:Skip.java

示例13: skipAll

import java.io.InputStream; //导入方法依赖的package包/类
public static void skipAll(InputStream in) throws IOException {
    do {
        in.skip(Long.MAX_VALUE);
    } while (in.read() != -1);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:6,代码来源:Streams.java

示例14: skipAll

import java.io.InputStream; //导入方法依赖的package包/类
public static void skipAll(InputStream in) throws IOException {
  do {
    in.skip(Long.MAX_VALUE);
  } while (in.read() != -1);
}
 
开发者ID:aabognah,项目名称:LoRaWAN-Smart-Parking,代码行数:6,代码来源:Util.java

示例15: main

import java.io.InputStream; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    try
    {
        setUp();

        for (int i = 0; i < 8; i++) {
            ModelByteBuffer buff;
            if(i % 2 == 0)
                buff = new ModelByteBuffer(test_file);
            else
                buff = new ModelByteBuffer(test_byte_array);
            if((i / 2) == 1)
                buff.subbuffer(5);
            if((i / 2) == 2)
                buff.subbuffer(5,500);
            if((i / 2) == 3)
                buff.subbuffer(5,600,true);

            long capacity = buff.capacity();
            InputStream is = buff.getInputStream();
            try
            {
                is.mark(1000);
                int ret = is.available();
                int a = is.read();
                is.skip(75);
                is.reset();
                if(is.available() != ret)
                    throw new RuntimeException(
                            "is.available() returns incorrect value ("
                            + is.available() + "!="+(ret)+") !");
                int b = is.read();
                if(a != b)
                    throw new RuntimeException(
                            "is doesn't return same value after reset ("
                            + a + "!="+b+") !");

                is.skip(15);
                ret = is.available();
                is.mark(1000);
                is.reset();
                if(is.available() != ret)
                    throw new RuntimeException(
                            "is.available() returns incorrect value ("
                            + is.available() + "!="+(ret)+") !");


            }
            finally
            {
                is.close();
            }
            if(buff.capacity() != capacity)
                throw new RuntimeException("Capacity variable should not change!");
        }
    }
    finally
    {
        tearDown();
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:62,代码来源:MarkReset.java


注:本文中的java.io.InputStream.skip方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。