Class Utilities

java.lang.Object
com.easypost.easyvcr.internal.Utilities

public abstract class Utilities extends Object
Internal tools for EasyVCR.
  • Constructor Details

    • Utilities

      public Utilities()
  • Method Details

    • getFile

      public static File getFile(String filePath)
      Get a File object from a path.
      Parameters:
      filePath - The path to the file.
      Returns:
      The File object.
    • getFilePath

      public static String getFilePath(String folderPath, String fileName)
      Get a file path from a folder-file pair.
      Parameters:
      folderPath - The folder path.
      fileName - The file name.
      Returns:
      The file path.
    • toBase64String

      public static String toBase64String(String input)
      Get the base64 representation of a string.
      Parameters:
      input - The string to encode.
      Returns:
      The base64 representation of the string.
    • createInputStream

      public static InputStream createInputStream(String string)
      Create an input stream from a string.
      Parameters:
      string - The string to create the input stream from.
      Returns:
      The input stream.
    • createOutputStream

      public static OutputStream createOutputStream(String string) throws IOException
      Create an output stream from a string.
      Parameters:
      string - The string to create the output stream from.
      Returns:
      The output stream.
      Throws:
      IOException
    • copyInputStream

      public static InputStream copyInputStream(InputStream stream)
      Make a copy of an input stream (resetting the position to 0).
      Parameters:
      stream - The input stream to copy.
      Returns:
      A copy of the input stream.
    • readFromInputStream

      public static String readFromInputStream(InputStream stream)
      Read the contents of an input stream into a string.
      Parameters:
      stream - The input stream to read.
      Returns:
      The contents of the input stream as a string.
    • mapToQueryParameters

      public static List<ApachePatch.NameValuePair> mapToQueryParameters(Map<String,​String> map)
      Convert a map to a query parameters string.
      Parameters:
      map - The map to convert.
      Returns:
      The query parameters string.
    • queryParametersToMap

      public static Map<String,​String> queryParametersToMap(URI uri)
      Convert a URI's query parameters to a Map.
      Parameters:
      uri - The URI.
      Returns:
      The Map of query parameters.
    • simulateDelay

      public static void simulateDelay(HttpInteraction interaction, AdvancedSettings advancedSettings) throws InterruptedException
      Sleep the current thread for a specified number of milliseconds.
      Parameters:
      interaction - The interaction used to determine the number of milliseconds to sleep.
      advancedSettings - The advanced settings used to determine the number of milliseconds to sleep.
      Throws:
      InterruptedException - If the thread is interrupted.
    • isDictionary

      public static boolean isDictionary(Object obj)
      Check if the object is a dictionary.
      Parameters:
      obj - The object to check.
      Returns:
      True if the object is a dictionary.
    • isList

      public static boolean isList(Object obj)
      Check if the object is a list.
      Parameters:
      obj - The object to check.
      Returns:
      True if the object is a list.
    • removeJsonElements

      public static String removeJsonElements(String json, List<CensorElement> elements)
      Remove elements from a JSON string.
      Parameters:
      json - The JSON string to remove elements from.
      elements - The elements to remove.
      Returns:
      The JSON string without the elements.
    • extractPathFromUri

      public static String extractPathFromUri(URI uri)
      Extract the path from a URI.
      Parameters:
      uri - The URI to extract the path from.
      Returns:
      The path.