All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.sentry.core.SentryEnvelopeItemHeader Maven / Gradle / Ivy

There is a newer version: 3.0.0-alpha.1
Show newest version
package io.sentry.core;

import io.sentry.core.util.Objects;
import java.util.concurrent.Callable;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@ApiStatus.Internal
public final class SentryEnvelopeItemHeader {

  private final @Nullable String contentType;
  private final @Nullable String fileName;
  private final @NotNull SentryItemType type;
  private final int length;
  @Nullable private final Callable getLength;

  public @NotNull SentryItemType getType() {
    return type;
  }

  public int getLength() {
    if (getLength != null) {
      try {
        return getLength.call();
      } catch (Exception ignored) {
        return -1;
      }
    }
    return length;
  }

  public @Nullable String getContentType() {
    return contentType;
  }

  public @Nullable String getFileName() {
    return fileName;
  }

  SentryEnvelopeItemHeader(
      final @NotNull SentryItemType type,
      int length,
      final @Nullable String contentType,
      final @Nullable String fileName) {
    this.type = Objects.requireNonNull(type, "type is required");
    this.contentType = contentType;
    this.length = length;
    this.fileName = fileName;
    this.getLength = null;
  }

  SentryEnvelopeItemHeader(
      final @NotNull SentryItemType type,
      final @Nullable Callable getLength,
      final @Nullable String contentType,
      final @Nullable String fileName) {
    this.type = Objects.requireNonNull(type, "type is required");
    this.contentType = contentType;
    this.length = -1;
    this.fileName = fileName;
    this.getLength = getLength;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy