Tabnine Logo
PathUtil
Code IndexAdd Tabnine to your IDE (free)

How to use
PathUtil
in
org.jboss.shrinkwrap.impl.base.path

Best Java code snippets using org.jboss.shrinkwrap.impl.base.path.PathUtil (Showing top 20 results out of 315)

origin: org.jboss.shrinkwrap/shrinkwrap-impl-base

/**
 * Composes an absolute context from a given base and actual context relative to the base, returning the result. ie.
 * base of "base" and context of "context" will result in form "/base/context".
 */
public static String composeAbsoluteContext(final String base, final String context) {
  // Precondition checks
  assertSpecified(base);
  assertSpecified(context);
  // Compose
  final String relative = PathUtil.adjustToAbsoluteDirectoryContext(base);
  final String reformedContext = PathUtil.optionallyRemovePrecedingSlash(context);
  final String actual = relative + reformedContext;
  // Return
  return actual;
}
origin: org.jboss.shrinkwrap/shrinkwrap-impl-base

/**
 * Creates a new Path using the specified base and specified relative context.
 *
 * @param basePath
 * @param context
 */
public BasicPath(final String basePath, String context) {
  this(PathUtil.composeAbsoluteContext(basePath, context));
}
origin: org.jboss.shrinkwrap/shrinkwrap-impl-base

/**
 * {@inheritDoc}
 *
 * @see org.jboss.shrinkwrap.api.ArchivePath#getParent()
 */
@Override
public ArchivePath getParent() {
  return PathUtil.getParent(this);
}
origin: org.jboss.shrinkwrap/shrinkwrap-impl-base

/**
 * Adds, if not already present, the absolute slash following the specified path, and returns the adjusted result.
 *
 * @param path
 * @return
 */
public static String optionallyAppendSlash(final String path) {
  // Precondition check
  assertSpecified(path);
  // If the last character is not a slash
  if (!isLastCharSlash(path)) {
    // Append
    return path + ArchivePath.SEPARATOR;
  }
  // Return as-is
  return path;
}
origin: org.jboss.shrinkwrap/shrinkwrap-impl-base

/**
 * Adjusts the specified path to absolute form:
 *
 * 1) Adds, if not present, a preceding slash 2) Adds, if not present, a trailing slash
 *
 * Null arguments are returned as-is
 *
 * @param path
 */
public static String adjustToAbsoluteDirectoryContext(String path) {
  // Return nulls
  if (path == null) {
    return path;
  }
  // Add prefic slash
  final String prefixedPath = optionallyPrependSlash(path);
  // Add end of context slash
  final String addedPostfix = optionallyAppendSlash(prefixedPath);
  // Return
  return addedPostfix;
}
origin: org.jboss.shrinkwrap/shrinkwrap-impl-base

/**
 * Adjusts the specified path to relative form:
 *
 * 1) Removes, if present, a preceding slash 2) Adds, if not present, a trailing slash
 *
 * Null arguments are returned as-is
 *
 * @param path
 */
public static String adjustToRelativeDirectoryContext(final String path) {
  // Return nulls
  if (path == null) {
    return path;
  }
  // Strip absolute form
  final String removedPrefix = optionallyRemovePrecedingSlash(path);
  // Add end of context slash
  final String addedPostfix = optionallyAppendSlash(removedPrefix);
  // Return
  return addedPostfix;
}
origin: shrinkwrap/shrinkwrap

/**
 * Obtains an {@link InputStream} to an entry of specified name from the specified TAR.GZ file, or null if not
 * found. We have to iterate through all entries for a matching name, as the instream does not support random
 * access.
 *
 * @param expectedZip
 * @param path
 * @return
 * @throws IllegalArgumentException
 * @throws IOException
 */
private InputStream getEntryFromTarFile(final File archive, final ArchivePath path)
  throws IllegalArgumentException, IOException {
  String entryPath = PathUtil.optionallyRemovePrecedingSlash(path.get());
  final TarInputStream in = this.getTarInputStreamFromFile(archive);
  TarEntry currentEntry = null;
  while ((currentEntry = in.getNextEntry()) != null) {
    final String entryName = currentEntry.getName();
    if (currentEntry.isDirectory()) {
      entryPath = PathUtil.optionallyAppendSlash(entryPath);
    } else {
      entryPath = PathUtil.optionallyRemoveFollowingSlash(entryPath);
    }
    if (entryName.equals(entryPath)) {
      return in;
    }
  }
  // Not found
  return null;
}
origin: org.jboss.shrinkwrap/shrinkwrap-impl-base

private Set<String> adjust(String... paths) {
  Set<String> adjusted = new HashSet<String>();
  for(String path : paths) {
    adjusted.add(PathUtil.optionallyPrependSlash(path));
  }
  return adjusted;
}
origin: org.jboss.shrinkwrap/shrinkwrap-impl-base

final String adjustedContext = PathUtil.optionallyRemoveFollowingSlash(context);
final String adjustedOther = PathUtil.optionallyRemoveFollowingSlash(other.context);
if (!adjustedContext.equals(adjustedOther)) {
  return false;
origin: shrinkwrap/shrinkwrap

/**
 * Ensures that the preceding slash is removed as requested
 */
@Test
public void testRemovePrecedingSlash() {
  log.info("testRemovePrecedingSlash");
  final String precedingSlash = "/test/something";
  final String expected = precedingSlash.substring(1);
  final String result = PathUtil.optionallyRemovePrecedingSlash(precedingSlash);
  Assert.assertEquals("Call to remove preceding slash should return everything in input except the first slash",
    expected, result);
}
origin: shrinkwrap/shrinkwrap

/**
 * Ensures that a slash may be appended to a given String
 */
@Test
public void testAppendSlash() {
  log.info("testRemovePrecedingSlash");
  final String noFollowingSlash = "test/something";
  final String expected = noFollowingSlash + ArchivePath.SEPARATOR;
  final String result = PathUtil.optionallyAppendSlash(noFollowingSlash);
  Assert.assertEquals("Call to append a slash failed", expected, result);
}
origin: org.jboss.shrinkwrap/shrinkwrap-impl-base

/**
 * Removes, if present, the absolute slash preceding the specified path, and returns the adjusted result.
 *
 * @param path
 * @return
 */
public static String optionallyRemovePrecedingSlash(final String path) {
  // Precondition check
  assertSpecified(path);
  // Is there's a first character of slash
  if (isFirstCharSlash(path)) {
    // Return everything but first char
    return path.substring(1);
  }
  // Return as-is
  return path;
}
origin: shrinkwrap/shrinkwrap

/**
 * Ensures that a relative path may be converted to full absolute directory form
 */
@Test
public void testAdjustToAbsoluteDirectoryContext() {
  log.info("testRemovePrecedingSlash");
  final String relativeWithoutTrailingSlash = "test/something";
  final String expected = ArchivePath.SEPARATOR + relativeWithoutTrailingSlash + ArchivePath.SEPARATOR;
  final String result = PathUtil.adjustToAbsoluteDirectoryContext(relativeWithoutTrailingSlash);
  Assert.assertEquals("Adjusting to absolute form should prepend preceding slash and append a trailing one",
    expected, result);
}
origin: org.jboss.shrinkwrap/shrinkwrap-impl-base

/**
 * Returns whether or not the first character in the specified String is a slash
 */
private static boolean isFirstCharSlash(final String path) {
  assertSpecified(path);
  if (path.length() == 0) {
    return false;
  }
  return path.charAt(0) == ArchivePath.SEPARATOR;
}
origin: org.jboss.shrinkwrap/shrinkwrap-impl-base

/**
 * Adds, if not already present, the absolute slash preceding the specified path, and returns the adjusted result.
 * If the argument is null, adjusts to an empty String before processing.
 *
 * @param path
 * @return
 */
public static String optionallyPrependSlash(final String path) {
  // Adjust null
  String resolved = path;
  if (resolved == null) {
    resolved = EMPTY;
  }
  // If the first character is not a slash
  if (!isFirstCharSlash(resolved)) {
    // Prepend the slash
    return ArchivePath.SEPARATOR + resolved;
  }
  // Return as-is
  return resolved;
}
origin: shrinkwrap/shrinkwrap

/**
 * Ensures that an absolute path may be converted to full relative directory form
 */
@Test
public void testAdjustToRelativeDirectoryContext() {
  log.info("testRemovePrecedingSlash");
  final String absoulteWithoutTrailingSlash = "/test/something";
  final String expected = absoulteWithoutTrailingSlash.substring(1) + ArchivePath.SEPARATOR;
  final String result = PathUtil.adjustToRelativeDirectoryContext(absoulteWithoutTrailingSlash);
  Assert.assertEquals("Adjusting to relative form should strip preceding slash and append a trailing one",
    expected, result);
}
origin: shrinkwrap/shrinkwrap

/**
 * Adjusts the specified path to relative form:
 *
 * 1) Removes, if present, a preceding slash 2) Adds, if not present, a trailing slash
 *
 * Null arguments are returned as-is
 *
 * @param path
 */
public static String adjustToRelativeDirectoryContext(final String path) {
  // Return nulls
  if (path == null) {
    return path;
  }
  // Strip absolute form
  final String removedPrefix = optionallyRemovePrecedingSlash(path);
  // Add end of context slash
  final String addedPostfix = optionallyAppendSlash(removedPrefix);
  // Return
  return addedPostfix;
}
origin: org.jboss.shrinkwrap/shrinkwrap-impl-base

private Set<String> adjust(String... paths) {
  Set<String> adjusted = new HashSet<String>();
  for(String path : paths) {
    adjusted.add(PathUtil.optionallyPrependSlash(path));
  }
  return adjusted;
}
origin: shrinkwrap/shrinkwrap

/**
 * Adjusts the specified path to absolute form:
 *
 * 1) Adds, if not present, a preceding slash 2) Adds, if not present, a trailing slash
 *
 * Null arguments are returned as-is
 *
 * @param path
 */
public static String adjustToAbsoluteDirectoryContext(String path) {
  // Return nulls
  if (path == null) {
    return path;
  }
  // Add prefic slash
  final String prefixedPath = optionallyPrependSlash(path);
  // Add end of context slash
  final String addedPostfix = optionallyAppendSlash(prefixedPath);
  // Return
  return addedPostfix;
}
origin: shrinkwrap/shrinkwrap

final String adjustedContext = PathUtil.optionallyRemoveFollowingSlash(context);
final String adjustedOther = PathUtil.optionallyRemoveFollowingSlash(other.context);
if (!adjustedContext.equals(adjustedOther)) {
  return false;
org.jboss.shrinkwrap.impl.base.pathPathUtil

Javadoc

PathUtil A series of internal-only path utilities for adjusting relative forms, removing double-slashes, etc. Used in correcting inputs in the creation of new Paths

Most used methods

  • adjustToAbsoluteDirectoryContext
    Adjusts the specified path to absolute form: 1) Adds, if not present, a preceding slash 2) Adds, if
  • composeAbsoluteContext
    Composes an absolute context from a given base and actual context relative to the base, returning th
  • getParent
    Obtains the parent of this Path, if exists, else null. For instance if the Path is "/my/path", the p
  • optionallyAppendSlash
    Adds, if not already present, the absolute slash following the specified path, and returns the adjus
  • optionallyPrependSlash
    Adds, if not already present, the absolute slash preceding the specified path, and returns the adjus
  • optionallyRemoveFollowingSlash
    Removes, if present, the absolute slash following the specified path, and returns the adjusted resul
  • optionallyRemovePrecedingSlash
    Removes, if present, the absolute slash preceding the specified path, and returns the adjusted resul
  • adjustToRelativeDirectoryContext
    Adjusts the specified path to relative form: 1) Removes, if present, a preceding slash 2) Adds, if n
  • assertSpecified
    Ensures the path is specified
  • isFirstCharSlash
    Returns whether or not the first character in the specified String is a slash
  • isLastCharSlash
    Returns whether or not the last character in the specified String is a slash
  • isLastCharSlash

Popular in Java

  • Running tasks concurrently on multiple threads
  • getExternalFilesDir (Context)
  • runOnUiThread (Activity)
  • findViewById (Activity)
  • MalformedURLException (java.net)
    This exception is thrown when a program attempts to create an URL from an incorrect specification.
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • ZipFile (java.util.zip)
    This class provides random read access to a zip file. You pay more to read the zip file's central di
  • FileUtils (org.apache.commons.io)
    General file manipulation utilities. Facilities are provided in the following areas: * writing to a
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
  • Top plugins for Android Studio
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now