Example #1
0
 private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
   try {
     repositoryName = RepositoryName.create((String) in.readObject());
   } catch (LabelSyntaxException e) {
     throw new IOException("Error serializing repository name: " + e.getMessage());
   }
 }
Example #2
0
 /**
  * Extracts the repository name from a PathFragment that was created with {@code
  * PackageIdentifier.getPathFragment}.
  *
  * @return a {@code Pair} of the extracted repository name and the path fragment with stripped of
  *     "external/"-prefix and repository name, or null if none was found or the repository name
  *     was invalid.
  */
 public static Pair<RepositoryName, PathFragment> fromPathFragment(PathFragment path) {
   if (path.segmentCount() < 2 || !path.getSegment(0).equals(Label.EXTERNAL_PATH_PREFIX)) {
     return null;
   }
   try {
     RepositoryName repoName = RepositoryName.create("@" + path.getSegment(1));
     PathFragment subPath = path.subFragment(2, path.segmentCount());
     return Pair.of(repoName, subPath);
   } catch (LabelSyntaxException e) {
     return null;
   }
 }