Search in sources :

Example 51 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class BTreePersistentIndexedCache method remove.

public void remove(K key) {
    try {
        Lookup lookup = header.getRoot().find(key);
        if (lookup.entry == null) {
            return;
        }
        lookup.indexBlock.remove(lookup.entry);
        DataBlock block = store.read(lookup.entry.dataBlock, DataBlock.class);
        store.remove(block);
        store.flush();
    } catch (Exception e) {
        throw new UncheckedIOException(String.format("Could not remove entry '%s' from %s.", key, this), e);
    }
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException)

Example 52 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class BTreePersistentIndexedCache method put.

public void put(K key, V value) {
    try {
        long hashCode = keyHasher.getHashCode(key);
        Lookup lookup = header.getRoot().find(hashCode);
        DataBlock newBlock = null;
        if (lookup.entry != null) {
            DataBlock block = store.read(lookup.entry.dataBlock, DataBlock.class);
            DataBlockUpdateResult updateResult = block.useNewValue(value);
            if (updateResult.isFailed()) {
                store.remove(block);
                newBlock = new DataBlock(value, updateResult.getSerializedValue());
            }
        } else {
            newBlock = new DataBlock(value);
        }
        if (newBlock != null) {
            store.write(newBlock);
            lookup.indexBlock.put(hashCode, newBlock.getPos());
        }
        store.flush();
    } catch (Exception e) {
        throw new UncheckedIOException(String.format("Could not add entry '%s' to %s.", key, this), e);
    }
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException)

Example 53 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class FileBackedBlockStore method read.

public <T extends BlockPayload> T read(BlockPointer pos, Class<T> payloadType) {
    assert !pos.isNull();
    try {
        T payload = payloadType.cast(factory.create(payloadType));
        BlockImpl block = new BlockImpl(payload, pos);
        block.read();
        return payload;
    } catch (CorruptedCacheException e) {
        throw e;
    } catch (Exception e) {
        throw new UncheckedIOException(e);
    }
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException)

Example 54 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class FileBackedBlockStore method clear.

public void clear() {
    try {
        file.setLength(0);
        currentFileSize = 0;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    nextBlock = 0;
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException)

Example 55 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class DefaultClasspathEntryHasher method hashFile.

private HashCode hashFile(FileDetails fileDetails, Hasher hasher, ClasspathContentHasher classpathContentHasher) {
    InputStream inputStream = null;
    try {
        inputStream = new FileInputStream(fileDetails.getPath());
        classpathContentHasher.appendContent(fileDetails.getName(), inputStream, hasher);
        return hasher.hash();
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } finally {
        IOUtils.closeQuietly(inputStream);
    }
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) FileInputStream(java.io.FileInputStream)

Aggregations

UncheckedIOException (org.gradle.api.UncheckedIOException)101 IOException (java.io.IOException)79 File (java.io.File)32 InputStream (java.io.InputStream)9 FileOutputStream (java.io.FileOutputStream)7 OutputStream (java.io.OutputStream)7 BufferedReader (java.io.BufferedReader)6 StringReader (java.io.StringReader)6 FileInputStream (java.io.FileInputStream)5 Matcher (java.util.regex.Matcher)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 URI (java.net.URI)4 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 Manifest (java.util.jar.Manifest)4 ZipInputStream (java.util.zip.ZipInputStream)4 FileVisitDetails (org.gradle.api.file.FileVisitDetails)4 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 FileReader (java.io.FileReader)3