Search in sources :

Example 16 with InvalidProtocolBufferException

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.InvalidProtocolBufferException in project sonarlint-core by SonarSource.

the class ServerVersionAndStatusChecker method fetchServerInfos.

private ServerInfos fetchServerInfos() {
    try (WsResponse response = wsClient.rawGet("api/system/status")) {
        if (!response.isSuccessful()) {
            if (response.code() == HttpURLConnection.HTTP_NOT_FOUND) {
                return tryFromDeprecatedApi(response);
            } else {
                throw SonarLintWsClient.handleError(response);
            }
        } else {
            String responseStr = response.content();
            try {
                ServerInfos.Builder builder = ServerInfos.newBuilder();
                JsonFormat.parser().merge(responseStr, builder);
                return builder.build();
            } catch (InvalidProtocolBufferException e) {
                throw new IllegalStateException("Unable to parse server infos from: " + StringUtils.abbreviate(responseStr, 100), e);
            }
        }
    }
}
Also used : InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) WsResponse(org.sonarsource.sonarlint.core.util.ws.WsResponse) ServerInfos(org.sonarsource.sonarlint.core.proto.Sonarlint.ServerInfos)

Example 17 with InvalidProtocolBufferException

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.InvalidProtocolBufferException in project CorfuDB by CorfuDB.

the class StreamLogFiles method readAddressSpace.

/**
     * Reads an address space from a log file into a SegmentHandle
     *
     * @param sh
     */
private void readAddressSpace(SegmentHandle sh) throws IOException {
    long logFileSize;
    try (MultiReadWriteLock.AutoCloseableLock ignored = segmentLocks.acquireReadLock(sh.getSegment())) {
        logFileSize = sh.logChannel.size();
    }
    FileChannel fc = getChannel(sh.fileName, true);
    if (fc == null) {
        log.trace("Can't read address space, {} doesn't exist", sh.fileName);
        return;
    }
    // Skip the header
    ByteBuffer headerMetadataBuf = ByteBuffer.allocate(METADATA_SIZE);
    fc.read(headerMetadataBuf);
    headerMetadataBuf.flip();
    Metadata headerMetadata = Metadata.parseFrom(headerMetadataBuf.array());
    fc.position(fc.position() + headerMetadata.getLength());
    long channelOffset = fc.position();
    ByteBuffer o = ByteBuffer.allocate((int) logFileSize - (int) fc.position());
    fc.read(o);
    fc.close();
    o.flip();
    while (o.hasRemaining()) {
        short magic = o.getShort();
        channelOffset += Short.BYTES;
        if (magic != RECORD_DELIMITER) {
            log.error("Expected a delimiter but found something else while trying to read file {}", sh.fileName);
            throw new DataCorruptionException();
        }
        byte[] metadataBuf = new byte[METADATA_SIZE];
        o.get(metadataBuf);
        channelOffset += METADATA_SIZE;
        try {
            Metadata metadata = Metadata.parseFrom(metadataBuf);
            byte[] logEntryBuf = new byte[metadata.getLength()];
            o.get(logEntryBuf);
            LogEntry entry = LogEntry.parseFrom(logEntryBuf);
            if (!noVerify) {
                if (metadata.getChecksum() != getChecksum(entry.toByteArray())) {
                    log.error("Checksum mismatch detected while trying to read file {}", sh.fileName);
                    throw new DataCorruptionException();
                }
            }
            sh.knownAddresses.put(entry.getGlobalAddress(), new AddressMetaData(metadata.getChecksum(), metadata.getLength(), channelOffset));
            channelOffset += metadata.getLength();
        } catch (InvalidProtocolBufferException e) {
            throw new DataCorruptionException();
        }
    }
}
Also used : FileChannel(java.nio.channels.FileChannel) IMetadata(org.corfudb.protocols.wireprotocol.IMetadata) Metadata(org.corfudb.format.Types.Metadata) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) DataCorruptionException(org.corfudb.runtime.exceptions.DataCorruptionException) ByteBuffer(java.nio.ByteBuffer) LogEntry(org.corfudb.format.Types.LogEntry)

Example 18 with InvalidProtocolBufferException

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.InvalidProtocolBufferException in project sulky by huxi.

the class MetaDataDecoder method decode.

public MetaData decode(byte[] bytes) {
    if (bytes == null) {
        return null;
    }
    MetaDataProto.MetaData parsedData = null;
    if (!compressing) {
        try {
            parsedData = MetaDataProto.MetaData.parseFrom(bytes);
        } catch (InvalidProtocolBufferException e) {
        // ignore
        }
    } else {
        ByteArrayInputStream in = new ByteArrayInputStream(bytes);
        try {
            GZIPInputStream gis = new GZIPInputStream(in);
            parsedData = MetaDataProto.MetaData.parseFrom(gis);
            gis.close();
        } catch (IOException e) {
        // ignore
        }
    }
    return convert(parsedData);
}
Also used : MetaDataProto(de.huxhorn.sulky.codec.filebuffer.generated.MetaDataProto) GZIPInputStream(java.util.zip.GZIPInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) IOException(java.io.IOException)

Example 19 with InvalidProtocolBufferException

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.InvalidProtocolBufferException in project core-java by SpineEventEngine.

the class MetadataConverter method toError.

/**
 * Returns the {@link Error} extracted from the {@link Metadata}.
 *
 * @param metadata the metadata to convert
 * @return the error extracted from the metadata or {@code Optional.absent()}
 *         if there is no error.
 */
public static Optional<Error> toError(Metadata metadata) {
    checkNotNull(metadata);
    final byte[] bytes = metadata.get(KEY);
    if (bytes == null) {
        return Optional.absent();
    }
    try {
        final Error error = Error.parseFrom(bytes);
        return Optional.of(error);
    } catch (InvalidProtocolBufferException e) {
        throw Exceptions.illegalStateWithCauseOf(e);
    }
}
Also used : InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) Error(io.spine.base.Error)

Example 20 with InvalidProtocolBufferException

use of org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.InvalidProtocolBufferException in project yamcs-studio by yamcs.

the class CommandingCatalogue method initialiseState.

private void initialiseState() {
    log.fine("Fetching available commands");
    YamcsClient restClient = YamcsPlugin.getYamcsClient();
    String instance = ManagementCatalogue.getCurrentYamcsInstance();
    restClient.get("/mdb/" + instance + "/commands", null).whenComplete((data, exc) -> {
        try {
            ListCommandInfoResponse response = ListCommandInfoResponse.parseFrom(data);
            processMetaCommands(response.getCommandList());
        } catch (InvalidProtocolBufferException e) {
            log.log(Level.SEVERE, "Failed to decode server response", e);
        }
    });
}
Also used : YamcsClient(org.yamcs.studio.core.client.YamcsClient) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ListCommandInfoResponse(org.yamcs.protobuf.Rest.ListCommandInfoResponse)

Aggregations

InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)334 IOException (java.io.IOException)69 ByteString (com.google.protobuf.ByteString)46 ServerRequest (com.pokegoapi.main.ServerRequest)46 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)39 GeneralSecurityException (java.security.GeneralSecurityException)32 CleartextKeysetHandle (com.google.crypto.tink.CleartextKeysetHandle)25 KeysetHandle (com.google.crypto.tink.KeysetHandle)25 HashMap (java.util.HashMap)25 ArrayList (java.util.ArrayList)22 InvalidProtocolBufferException (org.apache.beam.vendor.grpc.v1p43p2.com.google.protobuf.InvalidProtocolBufferException)22 List (java.util.List)19 Any (com.google.protobuf.Any)18 Map (java.util.Map)18 Key (org.apache.accumulo.core.data.Key)17 Value (org.apache.accumulo.core.data.Value)17 Status (org.apache.accumulo.server.replication.proto.Replication.Status)17 Text (org.apache.hadoop.io.Text)17 HashSet (java.util.HashSet)12 RunnerApi (org.apache.beam.model.pipeline.v1.RunnerApi)11