<commit_before>package com.chatwork.sbt.aws.s3.resolver.ivy

import java.io.InputStream

import com.amazonaws.AmazonServiceException
import com.amazonaws.services.s3.AmazonS3Client
import com.chatwork.sbt.aws.s3.resolver.S3Utility
import org.apache.ivy.plugins.repository.Resource

case class S3Resource(s3Client: AmazonS3Client, uri: String) extends Resource {

  val bucket = S3Utility.getBucket(uri)

  val key = S3Utility.getKey(uri)

  private var _exists: Boolean = false
  private var contentLength: Long = 0L
  private var lastModified: Long = 0L

  try {
    val metadata = s3Client.getObjectMetadata(bucket, key)
    _exists = true
    contentLength = metadata.getContentLength
    lastModified = metadata.getLastModified.getTime
  } catch {
    case ex: AmazonServiceException =>
  }

  override def getName: String = uri

  override def isLocal: Boolean = false

  override def openStream(): InputStream = {
    try {
      s3Client.getObject(bucket, key).getObjectContent
    } catch {
      case ex: AmazonServiceException =>
        throw S3RepositoryException(ex)
    }
  }

  override def clone(cloneName: String): Resource = S3Resource(
    s3Client, cloneName
  )

  override def getLastModified: Long = lastModified

  override def getContentLength: Long = contentLength

  override def exists(): Boolean = _exists

}
<commit_msg>Added support for Exception Handling<commit_after>package com.chatwork.sbt.aws.s3.resolver.ivy

import java.io.InputStream

import com.amazonaws.AmazonServiceException
import com.amazonaws.services.s3.AmazonS3Client
import com.chatwork.sbt.aws.s3.resolver.S3Utility
import org.apache.http.NoHttpResponseException
import org.apache.ivy.plugins.repository.Resource

case class S3Resource(s3Client: AmazonS3Client, uri: String) extends Resource {

  private val bucket = S3Utility.getBucket(uri)

  private val key = S3Utility.getKey(uri)

  private var _exists: Boolean = false
  private var contentLength: Long = 0L
  private var lastModified: Long = 0L

  try {
    val metadata = s3Client.getObjectMetadata(bucket, key)
    _exists = true
    contentLength = metadata.getContentLength
    lastModified = metadata.getLastModified.getTime
  } catch {
    case _: AmazonServiceException  =>
    case _: NoHttpResponseException =>
  }

  override def toString: String = {
    s"s3: uri = $uri, contentLength = $contentLength, lastModified = $lastModified"
  }

  override def getName: String = uri

  override def isLocal: Boolean = false

  override def openStream(): InputStream = {
    try {
      s3Client.getObject(bucket, key).getObjectContent
    } catch {
      case ex: AmazonServiceException =>
        throw S3RepositoryException(ex)
    }
  }

  override def clone(cloneName: String): Resource = S3Resource(
    s3Client, cloneName
  )

  override def getLastModified: Long = lastModified

  override def getContentLength: Long = contentLength

  override def exists(): Boolean = _exists

}

{'fraction_non_alphanumeric': 0.07966101694915254, 'fraction_numerical': 0.011864406779661017, 'mean_word_length': 4.01018675721562, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4049176', 'n_tokens_mistral': 884, 'n_tokens_neox': 865, 'n_words': 224}