Search in sources :

Example 1 with ZipError

use of java.util.zip.ZipError in project j2objc by google.

the class ZipErrorTest method test_constructor.

/**
 * {@link java.util.zip.ZipError#ZipError(String)}
 */
public void test_constructor() {
    ZipError error = new ZipError("ZipError");
    assertEquals("ZipError", error.getMessage());
}
Also used : ZipError(java.util.zip.ZipError)

Example 2 with ZipError

use of java.util.zip.ZipError in project spf4j by zolyfarkas.

the class MavenSchemaResolver method resolveSchema.

@Override
@SuppressFBWarnings("PCAIL_POSSIBLE_CONSTANT_ALLOCATION_IN_LOOP")
public Schema resolveSchema(final String id) {
    SchemaRef ref = new SchemaRef(id);
    try {
        File artifact = MavenRepositoryUtils.resolveArtifact(ref.getGroupId(), ref.getArtifactId(), classifier, extension, ref.getVersion(), remotes, repoSystem, repoSystemSession);
        URI zipUri = URI.create("jar:" + artifact.toURI().toURL());
        FileSystem zipFs;
        synchronized (zipUri.toString().intern()) {
            // newFileSystem fails if already one there...
            try {
                zipFs = FileSystems.newFileSystem(zipUri, Collections.emptyMap());
            } catch (FileSystemAlreadyExistsException ex) {
                zipFs = FileSystems.getFileSystem(zipUri);
            } catch (ZipError ze) {
                throw new AvroRuntimeException("Cannot resolve " + id, ze);
            }
        }
        for (Path root : zipFs.getRootDirectories()) {
            Path index = root.resolve("schema_index.properties");
            if (Files.exists(index)) {
                Properties prop = new Properties();
                try (BufferedReader indexReader = Files.newBufferedReader(index)) {
                    prop.load(indexReader);
                }
                String schemaName = prop.getProperty(ref.getRef());
                if (schemaName == null) {
                    throw new AvroRuntimeException("unable to resolve schema: " + id + " missing from index " + index);
                }
                Path schemaPath = root.resolve(schemaName.replace('.', '/') + ".avsc");
                try (BufferedInputStream bis = new BufferedInputStream(Files.newInputStream(schemaPath))) {
                    return new Schema.Parser().parse(bis);
                }
            }
        }
        throw new IOException("unable to resolve schema: " + id);
    } catch (ArtifactResolutionException | IOException ex) {
        throw new AvroRuntimeException("Cannot resolve " + id, ex);
    }
}
Also used : Path(java.nio.file.Path) SchemaRef(org.spf4j.avro.SchemaRef) Schema(org.apache.avro.Schema) AvroRuntimeException(org.apache.avro.AvroRuntimeException) IOException(java.io.IOException) Properties(java.util.Properties) URI(java.net.URI) ArtifactResolutionException(org.eclipse.aether.resolution.ArtifactResolutionException) BufferedInputStream(java.io.BufferedInputStream) FileSystem(java.nio.file.FileSystem) BufferedReader(java.io.BufferedReader) FileSystemAlreadyExistsException(java.nio.file.FileSystemAlreadyExistsException) File(java.io.File) ZipError(java.util.zip.ZipError) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 3 with ZipError

use of java.util.zip.ZipError in project j2objc by google.

the class ZipErrorTest method test_serialization.

/**
 * java.util.zip.ZipError#Serialization()
 */
public void test_serialization() throws Exception {
    ZipError error = new ZipError("serialization test");
    SerializationTest.verifySelf(error);
}
Also used : ZipError(java.util.zip.ZipError)

Example 4 with ZipError

use of java.util.zip.ZipError in project j2objc by google.

the class ZipErrorTest method testSerializationCompatibility.

/**
 * serialization/deserialization compatibility with RI.
 */
public void testSerializationCompatibility() throws Exception {
    ZipError error = new ZipError("serialization test");
    SerializationTest.verifyGolden(this, error);
}
Also used : ZipError(java.util.zip.ZipError)

Aggregations

ZipError (java.util.zip.ZipError)4 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 BufferedInputStream (java.io.BufferedInputStream)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 URI (java.net.URI)1 FileSystem (java.nio.file.FileSystem)1 FileSystemAlreadyExistsException (java.nio.file.FileSystemAlreadyExistsException)1 Path (java.nio.file.Path)1 Properties (java.util.Properties)1 AvroRuntimeException (org.apache.avro.AvroRuntimeException)1 Schema (org.apache.avro.Schema)1 ArtifactResolutionException (org.eclipse.aether.resolution.ArtifactResolutionException)1 SchemaRef (org.spf4j.avro.SchemaRef)1