Java Code Examples for org.apache.commons.io.IOUtils#skip()

The following examples show how to use org.apache.commons.io.IOUtils#skip() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public synchronized void reset() throws IOException {
    InputStream unwrappedInput = EnhancedBufferedInputStream.tryUnwrap(currentInput);
    if (unwrappedInput instanceof FileInputStream) {
        FileInputStream fis = FileInputStream.class.cast(unwrappedInput);
        fis.getChannel().position(0);
        currentInput = new EnhancedBufferedInputStream(unwrappedInput);
    } else {
        if (tmpOutputStream == null) {
            throw new IllegalStateException("No output stream which buffers to a temp file has been created");
        }
        // spool all bytes to the temp file
        IOUtils.skip(currentInput, Long.MAX_VALUE);
        tmpOutputStream.close();
        currentInput = new EnhancedBufferedInputStream(Files.newInputStream(tmpFile));
    }
}
 
Example 2
Source Project: riiablo   File: DS1.java    License: Apache License 2.0 5 votes vote down vote up
private void readGroups(InputStream in) throws IOException {
  if (version >= 12 && (tagType == 1 || tagType == 2)) {
    if (version >= 18) IOUtils.skip(in, Ints.BYTES);
    numGroups = EndianUtils.readSwappedInteger(in);
    groups = numGroups == 0 ? Group.EMPTY_GROUP_ARRAY : new Group[numGroups];
    for (int i = 0; i < numGroups; i++) {
      groups[i] = new Group().read(version, in);
      if (DEBUG_GROUPS) Gdx.app.debug(TAG, groups[i].toString());
    }
  } else {
    numGroups = 0;
    groups = Group.EMPTY_GROUP_ARRAY;
  }
}
 
Example 3
@Override
public long skip(final long len) throws IOException {
    return IOUtils.skip(this, len);
}
 
Example 4
@Override
public long skip(final long len) throws IOException {
    return IOUtils.skip(this, len);
}
 
Example 5
/**
 * Copies the given files to the specified {@code root/dirName} and creates {@code .md5} hash files for each.
 *
 * @param targetFolder the target folder
 * @param filesToCopy  the files to write
 * @param zos          the ZipOutputStream to write to
 * @throws IOException if writing the zip entry goes wrong
 */
static void writeAsZipEntriesWithMD5(Path targetFolder, List<Path> filesToCopy, ZipOutputStream zos) throws IOException {
	if (filesToCopy == null || filesToCopy.isEmpty()) {
		return;
	}

	if (targetFolder == null) {
		targetFolder = Paths.get("");
	}

	if (zos == null) {
		throw new IOException("Zip output stream cannot be null");
	}

	MessageDigest md5 = DigestUtils.getMd5Digest();
	for (Path file : filesToCopy) {
		String fileName = targetFolder.resolve(file.getFileName()).toString().replace(File.separatorChar, ZIP_FILE_SEPARATOR_CHAR);
		ZipEntry entry = new ZipEntry(fileName);
		ZipEntry md5Entry = new ZipEntry(fileName + MD5_SUFFIX);

		// We read every file twice to speed up reading later
		// - We don't have to copy every file into memory (see else case in handleOtherFile)
		// - Connections should be way often read than written

		// Write Checksum first
		try (InputStream is = Files.newInputStream(file);
			 DigestInputStream dis = new DigestInputStream(is, md5)) {
			zos.putNextEntry(md5Entry);
			IOUtils.skip(dis, Long.MAX_VALUE);
			zos.write(Hex.encodeHexString(md5.digest()).getBytes());
			zos.closeEntry();
		}

		// Copy entry
		try (InputStream is = Files.newInputStream(file)) {
			zos.putNextEntry(entry);
			IOUtils.copy(is, zos);
			zos.closeEntry();
		}
	}
}