/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package org.apache.iceberg.dell.ecs;

import com.emc.object.s3.S3Client;
import org.apache.iceberg.dell.DellProperties;
import org.apache.iceberg.io.InputFile;
import org.apache.iceberg.io.SeekableInputStream;
import org.apache.iceberg.metrics.MetricsContext;

class EcsInputFile extends BaseEcsFile implements InputFile {

  public static EcsInputFile fromLocation(String location, S3Client client) {
    return new EcsInputFile(
        client, new EcsURI(location), new DellProperties(), MetricsContext.nullMetrics());
  }

  public static EcsInputFile fromLocation(
      String location, S3Client client, DellProperties dellProperties) {
    return new EcsInputFile(
        client, new EcsURI(location), dellProperties, MetricsContext.nullMetrics());
  }

  static EcsInputFile fromLocation(
      String location, S3Client client, DellProperties dellProperties, MetricsContext metrics) {
    return new EcsInputFile(client, new EcsURI(location), dellProperties, metrics);
  }

  EcsInputFile(S3Client client, EcsURI uri, DellProperties dellProperties, MetricsContext metrics) {
    super(client, uri, dellProperties, metrics);
  }

  /**
   * Note: this may be stale if file was deleted since metadata is cached for size/existence checks.
   *
   * @return content length
   */
  @Override
  public long getLength() {
    return getObjectMetadata().getContentLength();
  }

  @Override
  public SeekableInputStream newStream() {
    return new EcsSeekableInputStream(client(), uri(), metrics());
  }
}
