com.google.android.exoplayer2.util.Util.closeQuietly()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(187)

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

Util.closeQuietly介绍

[英]Closes a DataSource, suppressing any IOException that may occur.
[中]关闭数据源,抑制任何可能发生的IOException。

代码示例

代码示例来源:origin: google/ExoPlayer

@SuppressWarnings("ThrowFromFinallyBlock")
private void closeCurrentOutputStream() throws IOException {
 if (outputStream == null) {
  return;
 }
 boolean success = false;
 try {
  outputStream.flush();
  if (syncFileDescriptor) {
   underlyingFileOutputStream.getFD().sync();
  }
  success = true;
 } finally {
  Util.closeQuietly(outputStream);
  outputStream = null;
  File fileToCommit = file;
  file = null;
  if (success) {
   cache.commitFile(fileToCommit);
  } else {
   fileToCommit.delete();
  }
 }
}

代码示例来源:origin: google/ExoPlayer

/**
 * Loads {@link DownloadAction}s from file.
 *
 * @param deserializers {@link Deserializer}s to deserialize DownloadActions.
 * @return Loaded DownloadActions. If the action file doesn't exists returns an empty array.
 * @throws IOException If there is an error during loading.
 */
public DownloadAction[] load(Deserializer... deserializers) throws IOException {
 if (!actionFile.exists()) {
  return new DownloadAction[0];
 }
 InputStream inputStream = null;
 try {
  inputStream = atomicFile.openRead();
  DataInputStream dataInputStream = new DataInputStream(inputStream);
  int version = dataInputStream.readInt();
  if (version > VERSION) {
   throw new IOException("Unsupported action file version: " + version);
  }
  int actionCount = dataInputStream.readInt();
  DownloadAction[] actions = new DownloadAction[actionCount];
  for (int i = 0; i < actionCount; i++) {
   actions[i] = DownloadAction.deserializeFromStream(deserializers, dataInputStream);
  }
  return actions;
 } finally {
  Util.closeQuietly(inputStream);
 }
}

代码示例来源:origin: google/ExoPlayer

/**
 * Stores {@link DownloadAction}s to file.
 *
 * @param downloadActions DownloadActions to store to file.
 * @throws IOException If there is an error during storing.
 */
public void store(DownloadAction... downloadActions) throws IOException {
 DataOutputStream output = null;
 try {
  output = new DataOutputStream(atomicFile.startWrite());
  output.writeInt(VERSION);
  output.writeInt(downloadActions.length);
  for (DownloadAction action : downloadActions) {
   DownloadAction.serializeToStream(action, output);
  }
  atomicFile.endWrite(output);
  // Avoid calling close twice.
  output = null;
 } finally {
  Util.closeQuietly(output);
 }
}

代码示例来源:origin: google/ExoPlayer

Util.closeQuietly(reader);

代码示例来源:origin: google/ExoPlayer

@Override
public void load() throws IOException, InterruptedException {
 // We always load from the beginning, so reset bytesRead to 0.
 dataSource.resetBytesRead();
 try {
  // Create and open the input.
  dataSource.open(dataSpec);
  // Load the sample data.
  int result = 0;
  while (result != C.RESULT_END_OF_INPUT) {
   int sampleSize = (int) dataSource.getBytesRead();
   if (sampleData == null) {
    sampleData = new byte[INITIAL_SAMPLE_SIZE];
   } else if (sampleSize == sampleData.length) {
    sampleData = Arrays.copyOf(sampleData, sampleData.length * 2);
   }
   result = dataSource.read(sampleData, sampleSize, sampleData.length - sampleSize);
  }
 } finally {
  Util.closeQuietly(dataSource);
 }
}

代码示例来源:origin: google/ExoPlayer

private long readInputLength() throws IOException {
 DataSpec dataSpec =
   new DataSpec(Uri.parse("asset:///" + PS_FILE_PATH), 0, C.LENGTH_UNSET, null);
 long totalInputLength = dataSource.open(dataSpec);
 Util.closeQuietly(dataSource);
 return totalInputLength;
}

代码示例来源:origin: google/ExoPlayer

Util.closeQuietly(inputStream);

代码示例来源:origin: google/ExoPlayer

@Override
public final void load() throws IOException, InterruptedException {
 try {
  dataSource.open(dataSpec);
  int limit = 0;
  int bytesRead = 0;
  while (bytesRead != C.RESULT_END_OF_INPUT && !loadCanceled) {
   maybeExpandData(limit);
   bytesRead = dataSource.read(data, limit, READ_GRANULARITY);
   if (bytesRead != -1) {
    limit += bytesRead;
   }
  }
  if (!loadCanceled) {
   consume(data, limit);
  }
 } finally {
  Util.closeQuietly(dataSource);
 }
}

代码示例来源:origin: google/ExoPlayer

private void maybeLoadInitData() throws IOException, InterruptedException {
 if (initLoadCompleted || initDataSpec == null) {
  // Note: The HLS spec forbids initialization segments for packed audio.
  return;
 }
 DataSpec initSegmentDataSpec = initDataSpec.subrange(initSegmentBytesLoaded);
 try {
  DefaultExtractorInput input = prepareExtraction(initDataSource, initSegmentDataSpec);
  try {
   int result = Extractor.RESULT_CONTINUE;
   while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
    result = extractor.read(input, null);
   }
  } finally {
   initSegmentBytesLoaded = (int) (input.getPosition() - initDataSpec.absoluteStreamPosition);
  }
 } finally {
  Util.closeQuietly(initDataSource);
 }
 initLoadCompleted = true;
}

代码示例来源:origin: google/ExoPlayer

@Override
 public final void load() throws IOException {
  // We always load from the beginning, so reset bytesRead to 0.
  dataSource.resetBytesRead();
  DataSourceInputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
  try {
   inputStream.open();
   Uri dataSourceUri = Assertions.checkNotNull(dataSource.getUri());
   result = parser.parse(dataSourceUri, inputStream);
  } finally {
   Util.closeQuietly(inputStream);
  }
 }
}

代码示例来源:origin: google/ExoPlayer

private SeekMap extractSeekMapAndTracks(PsExtractor extractor, FakeExtractorOutput output)
  throws IOException, InterruptedException {
 ExtractorInput input = getExtractorInputFromPosition(0);
 extractor.init(output);
 int readResult = Extractor.RESULT_CONTINUE;
 while (true) {
  try {
   // Keep reading until we can get the seek map
   while (readResult == Extractor.RESULT_CONTINUE
     && (output.seekMap == null || !output.tracksEnded)) {
    readResult = extractor.read(input, positionHolder);
   }
  } finally {
   Util.closeQuietly(dataSource);
  }
  if (readResult == Extractor.RESULT_SEEK) {
   input = getExtractorInputFromPosition(positionHolder.position);
   readResult = Extractor.RESULT_CONTINUE;
  } else if (readResult == Extractor.RESULT_END_OF_INPUT) {
   throw new IOException("EOF encountered without seekmap");
  }
  if (output.seekMap != null) {
   return output.seekMap;
  }
 }
}

代码示例来源:origin: google/ExoPlayer

@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public void load() throws IOException, InterruptedException {
 DataSpec loadDataSpec = dataSpec.subrange(nextLoadPosition);
 try {
  // Create and open the input.
  ExtractorInput input = new DefaultExtractorInput(dataSource,
    loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec));
  if (nextLoadPosition == 0) {
   extractorWrapper.init(
     /* trackOutputProvider= */ null,
     /* startTimeUs= */ C.TIME_UNSET,
     /* endTimeUs= */ C.TIME_UNSET);
  }
  // Load and decode the initialization data.
  try {
   Extractor extractor = extractorWrapper.extractor;
   int result = Extractor.RESULT_CONTINUE;
   while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
    result = extractor.read(input, DUMMY_POSITION_HOLDER);
   }
   Assertions.checkState(result != Extractor.RESULT_SEEK);
  } finally {
   nextLoadPosition = input.getPosition() - dataSpec.absoluteStreamPosition;
  }
 } finally {
  Util.closeQuietly(dataSource);
 }
}

代码示例来源:origin: google/ExoPlayer

private void readInputFileOnce(PsExtractor extractor, FakeExtractorOutput extractorOutput)
  throws IOException, InterruptedException {
 extractor.init(extractorOutput);
 int readResult = Extractor.RESULT_CONTINUE;
 ExtractorInput input = getExtractorInputFromPosition(0);
 while (readResult != Extractor.RESULT_END_OF_INPUT) {
  try {
   while (readResult == Extractor.RESULT_CONTINUE) {
    readResult = extractor.read(input, positionHolder);
   }
  } finally {
   Util.closeQuietly(dataSource);
  }
  if (readResult == Extractor.RESULT_SEEK) {
   input = getExtractorInputFromPosition(positionHolder.position);
   readResult = Extractor.RESULT_CONTINUE;
  }
 }
}

代码示例来源:origin: google/ExoPlayer

private void readInputFileOnce(
  TsExtractor extractor, FakeExtractorOutput extractorOutput, Uri fileUri)
  throws IOException, InterruptedException {
 extractor.init(extractorOutput);
 int readResult = Extractor.RESULT_CONTINUE;
 ExtractorInput input = TestUtil.getExtractorInputFromPosition(dataSource, 0, fileUri);
 while (readResult != Extractor.RESULT_END_OF_INPUT) {
  try {
   while (readResult == Extractor.RESULT_CONTINUE) {
    readResult = extractor.read(input, positionHolder);
   }
  } finally {
   Util.closeQuietly(dataSource);
  }
  if (readResult == Extractor.RESULT_SEEK) {
   input =
     TestUtil.getExtractorInputFromPosition(dataSource, positionHolder.position, fileUri);
   readResult = Extractor.RESULT_CONTINUE;
  }
 }
}

代码示例来源:origin: google/ExoPlayer

Util.closeQuietly(dataSource);

代码示例来源:origin: google/ExoPlayer

@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public void load() throws IOException, InterruptedException {
 DataSpec loadDataSpec = dataSpec.subrange(nextLoadPosition);
 try {
  // Create and open the input.
  long length = dataSource.open(loadDataSpec);
  if (length != C.LENGTH_UNSET) {
   length += nextLoadPosition;
  }
  ExtractorInput extractorInput =
    new DefaultExtractorInput(dataSource, nextLoadPosition, length);
  BaseMediaChunkOutput output = getOutput();
  output.setSampleOffsetUs(0);
  TrackOutput trackOutput = output.track(0, trackType);
  trackOutput.format(sampleFormat);
  // Load the sample data.
  int result = 0;
  while (result != C.RESULT_END_OF_INPUT) {
   nextLoadPosition += result;
   result = trackOutput.sampleData(extractorInput, Integer.MAX_VALUE, true);
  }
  int sampleSize = (int) nextLoadPosition;
  trackOutput.sampleMetadata(startTimeUs, C.BUFFER_FLAG_KEY_FRAME, sampleSize, 0, null);
 } finally {
  Util.closeQuietly(dataSource);
 }
 loadCompleted = true;
}

代码示例来源:origin: google/ExoPlayer

Util.closeQuietly(dataSource);

代码示例来源:origin: google/ExoPlayer

Util.closeQuietly(dataSource);

代码示例来源:origin: google/ExoPlayer

positionHolder.position = input.getPosition();
Util.closeQuietly(dataSource);

代码示例来源:origin: google/ExoPlayer

Util.closeQuietly(dataSource);

相关文章