コード例 #1
0
 /** Creates a TarStreamBuilder using TarArchiveEntries. */
 private void SetUpWithTarEntries()
 {
     // Prepares a test TarStreamBuilder.
     testTarStreamBuilder.AddTarArchiveEntry(TarStreamBuilder.CreateEntryFromFile(fileA.ToFile(), "some/path/to/resourceFileA"));
     testTarStreamBuilder.AddTarArchiveEntry(TarStreamBuilder.CreateEntryFromFile(fileB.ToFile(), "crepecake"));
     testTarStreamBuilder.AddTarArchiveEntry(
         TarStreamBuilder.CreateEntryFromFile(directoryA.ToFile(), "some/path/to/"));
     testTarStreamBuilder.AddTarArchiveEntry(
         TarStreamBuilder.CreateEntryFromFile(
             fileA.ToFile(),
             "some/really/long/path/that/exceeds/100/characters/abcdefghijklmnopqrstuvwxyz0123456789012345678901234567890"));
 }
コード例 #2
0
ファイル: CacheStorageReader.cs プロジェクト: tiaotiao97/jib
        /**
         * Retrieves the layer digest selected by the {@code selector}.
         *
         * @param selector the selector
         * @return the layer digest {@code selector} selects, if found
         * @throws CacheCorruptedException if the selector file contents was not a valid layer digest
         * @throws IOException if an I/O exception occurs
         */
        public Maybe <DescriptorDigest> Select(DescriptorDigest selector)
        {
            selector = selector ?? throw new ArgumentNullException(nameof(selector));
            SystemPath selectorFile = cacheStorageFiles.GetSelectorFile(selector);

            if (!Files.Exists(selectorFile))
            {
                return(Maybe.Empty <DescriptorDigest>());
            }
            string selectorFileContents =
                File.ReadAllText(selectorFile.ToFile().FullName, Encoding.UTF8);

            try
            {
                return(Maybe.Of(DescriptorDigest.FromHash(selectorFileContents)));
            }
            catch (DigestException)
            {
                throw new CacheCorruptedException(
                          cacheStorageFiles.GetCacheDirectory(),
                          "Expected valid layer digest as contents of selector file `"
                          + selectorFile
                          + "` for selector `"
                          + selector.GetHash()
                          + "`, but got: "
                          + selectorFileContents);
            }
        }
コード例 #3
0
ファイル: JsonTemplateMapper.cs プロジェクト: tiaotiao97/jib
 /**
  * Deserializes a JSON file via a JSON object template.
  *
  * @param <T> child type of {@link JsonTemplate}
  * @param jsonFile a file containing a JSON string
  * @param templateClass the template to deserialize the string to
  * @return the template filled with the values parsed from {@code jsonFile}
  * @throws IOException if an error occurred during reading the file or parsing the JSON
  */
 public static T ReadJsonFromFile <T>(SystemPath jsonFile)
 {
     jsonFile = jsonFile ?? throw new ArgumentNullException(nameof(jsonFile));
     using (StreamReader reader = jsonFile.ToFile().OpenText())
     {
         return(JsonConvert.DeserializeObject <T>(reader.ReadToEnd()));
     }
 }