本文整理了Java中java.io.FileInputStream.skip()
方法的一些代码示例,展示了FileInputStream.skip()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileInputStream.skip()
方法的具体详情如下:
包路径:java.io.FileInputStream
类名称:FileInputStream
方法名:skip
[英]Skips over and discards n
bytes of data from the input stream.
The skip
method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0
. If n
is negative, an IOException
is thrown, even though the skip
method of the InputStream superclass does nothing in this case. The actual number of bytes skipped is returned.
This method may skip more bytes than are remaining in the backing file. This produces no exception and the number of bytes skipped may include some number of bytes that were beyond the EOF of the backing file. Attempting to read from the stream after skipping past the end will result in -1 indicating the end of the file.
[中]跳过并丢弃输入流中的n
字节数据。
由于各种原因,skip
方法可能会跳过一些较小的字节数,可能是0
。如果n
为负,则会抛出IOException
,即使InputStream超类的skip
方法在这种情况下不执行任何操作。返回跳过的实际字节数。
此方法跳过的字节数可能超过备份文件中剩余的字节数。这不会产生异常,跳过的字节数可能包括超出备份文件EOF的某些字节数。在跳过结束后尝试从流中读取将导致-1表示文件结束。
代码示例
代码示例来源:origin: apache/flink
@Override
public long skip(final long n) throws IOException {
return this.fis.skip(n);
}
}
代码示例来源:origin: org.apache.hadoop/hadoop-common
@Override
public long skip(long n) throws IOException {
long value = fis.skip(n);
if (value > 0) {
this.position += value;
}
return value;
}
代码示例来源:origin: aws/aws-sdk-java
private void skipBytes(FileInputStream fs, long n) throws IOException {
long skippedSoFar = 0;
for (int skips = 0; skips skippedSoFar += fs.skip(n - skippedSoFar);
}
if (skippedSoFar != n) {
throw new SdkClientException(String.format("Unable to skip to offset %d in file %s after %d attempts",
n, request.getFile().getAbsolutePath(), MAX_SKIPS));
}
}
}
代码示例来源:origin: aws/aws-sdk-java
@Override
public long skip(long n) throws IOException {
abortIfNeeded();
long skipped = fis.skip(n);
bytesReadPastMarkPoint += skipped;
return skipped;
}
代码示例来源:origin: aws/aws-sdk-java
@Override
public long skip(long n) throws IOException {
abortIfNeeded();
return fis.skip(n);
}
代码示例来源:origin: FudanNLP/fnlp
public static void processLabeledData(String input,String output) throws Exception{
FileInputStream is = new FileInputStream(input);
is.skip(3); //skip BOM
BufferedReader r = new BufferedReader(
new InputStreamReader(is, "utf8"));
OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(output), "utf8");
while(true) {
String sent = r.readLine();
if(null == sent) break;
String s = Tags.genSegSequence(sent, delimer, 4);
w.write(s);
}
r.close();
w.close();
}
代码示例来源:origin: aws/aws-sdk-java
/**
* Resets the input stream to the last mark point, or the beginning of the
* stream if there is no mark point, by creating a new FileInputStream based
* on the underlying file.
*
* @throws IOException
* when the FileInputStream cannot be re-created.
*/
@Override
public void reset() throws IOException {
this.fis.close();
abortIfNeeded();
this.fis = new FileInputStream(file);
long skipped = 0;
long toSkip = markPoint;
while (toSkip > 0) {
skipped = this.fis.skip(toSkip);
toSkip -= skipped;
}
if (log.isDebugEnabled()) {
log.debug("Reset to mark point " + markPoint
+ " after returning " + bytesReadPastMarkPoint + " bytes");
}
this.bytesReadPastMarkPoint = 0;
}
代码示例来源:origin: naman14/Timber
return null;
in.skip(len - 8);
final byte path[][] = new byte[][]{{'m','o','o','v'},{'u','d','t','a'},{'m','e','t','a'},{'i','l','s','t'},{(byte) '©','l','y','r'},{'d','a','t','a'}};
int atom_size = Integer.MAX_VALUE;
}else{
in.skip(len - 8);
atom_size-=len;
return null;
in.skip(8);
byte buffer[] = new byte[atom_size-8];
in.read(buffer);
代码示例来源:origin: apache/incubator-druid
@Override
public InputStream open(File object, long start) throws IOException
{
final FileInputStream fis = new FileInputStream(object);
Preconditions.checkState(fis.skip(start) == start);
return new TestInputStream(fis);
}
},
代码示例来源:origin: sonyxperiadev/ApkAnalyser
long amt = in.skip(at);
if (amt == -1) {
throw new RuntimeException(file + ": unexpected EOF");
代码示例来源:origin: stackoverflow.com
if (file.exists()) {
FileInputStream input = new FileInputStream(file);
input.skip(cbSkip);
int cbToSendThisBatch = input.available();
while (cbToSendThisBatch > 0) {
代码示例来源:origin: azkaban/azkaban
public static Pair readUtf8File(final File file, final int offset,
final int length, final OutputStream stream) throws IOException {
final byte[] buffer = new byte[length];
final FileInputStream fileStream = new FileInputStream(file);
final long skipped = fileStream.skip(offset);
if (skipped fileStream.close();
return new Pair<>(0, 0);
}
BufferedInputStream inputStream = null;
try {
inputStream = new BufferedInputStream(fileStream);
inputStream.read(buffer);
} finally {
IOUtils.closeQuietly(inputStream);
}
final Pair utf8Range = getUtf8Range(buffer, 0, length);
stream.write(buffer, utf8Range.getFirst(), utf8Range.getSecond());
return new Pair<>(offset + utf8Range.getFirst(),
utf8Range.getSecond());
}
代码示例来源:origin: google/ExoPlayer
long skipped = inputStream.skip(assetStartOffset + dataSpec.position) - assetStartOffset;
if (skipped != dataSpec.position) {
代码示例来源:origin: azkaban/azkaban
public static LogData readUtf8File(final File file, final int fileOffset, final int length)
throws IOException {
final byte[] buffer = new byte[length];
final FileInputStream fileStream = new FileInputStream(file);
final long skipped = fileStream.skip(fileOffset);
if (skipped fileStream.close();
return new LogData(fileOffset, 0, "");
}
BufferedInputStream inputStream = null;
int read = 0;
try {
inputStream = new BufferedInputStream(fileStream);
read = inputStream.read(buffer);
} finally {
IOUtils.closeQuietly(inputStream);
}
if (read <= 0) {
return new LogData(fileOffset, 0, "");
}
final Pair utf8Range = getUtf8Range(buffer, 0, read);
final String outputString =
new String(buffer, utf8Range.getFirst(), utf8Range.getSecond(), StandardCharsets.UTF_8);
return new LogData(fileOffset + utf8Range.getFirst(),
utf8Range.getSecond(), outputString);
}
代码示例来源:origin: azkaban/azkaban
public static JobMetaData readUtf8MetaDataFile(final File file, final int fileOffset,
final int length) throws IOException {
final byte[] buffer = new byte[length];
final FileInputStream fileStream = new FileInputStream(file);
final long skipped = fileStream.skip(fileOffset);
if (skipped fileStream.close();
return new JobMetaData(fileOffset, 0, "");
}
BufferedInputStream inputStream = null;
int read = 0;
try {
inputStream = new BufferedInputStream(fileStream);
read = inputStream.read(buffer);
} finally {
IOUtils.closeQuietly(inputStream);
}
if (read <= 0) {
return new JobMetaData(fileOffset, 0, "");
}
final Pair utf8Range = getUtf8Range(buffer, 0, read);
final String outputString =
new String(buffer, utf8Range.getFirst(), utf8Range.getSecond(), StandardCharsets.UTF_8);
return new JobMetaData(fileOffset + utf8Range.getFirst(),
utf8Range.getSecond(), outputString);
}
代码示例来源:origin: voldemort/voldemort
fileInputStream.skip(keySize + valueSize);
代码示例来源:origin: stackoverflow.com
fis.skip(startFrom);
代码示例来源:origin: NanoHttpd/nanohttpd
fis.skip(startFrom);
代码示例来源:origin: oblac/jodd
public int available() throws IOException { return (int)dataLen; }
};
fis.skip( startFrom );
代码示例来源:origin: pentaho/pentaho-kettle
data.fis.skip( bom.getBomSize() );