public static Path writeResourceToPath()

in common/src/testFixtures/java/org/apache/cassandra/sidecar/common/ResourceUtils.java [44:73]


    public static Path writeResourceToPath(ClassLoader classLoader, Path destinationPath, String resourceName)
    {
        try
        {
            Path resourcePath = destinationPath.resolve(resourceName);

            // ensure parent directory is created
            Files.createDirectories(resourcePath.getParent());

            try (InputStream inputStream = classLoader.getResourceAsStream(resourceName);
                 OutputStream outputStream = Files.newOutputStream(resourcePath))
            {
                assertThat(inputStream).isNotNull();

                int length;
                byte[] buffer = new byte[1024];
                while ((length = inputStream.read(buffer)) != -1)
                {
                    outputStream.write(buffer, 0, length);
                }
            }
            return resourcePath;
        }
        catch (IOException exception)
        {
            String failureMessage = "Unable to create resource " + resourceName;
            fail(failureMessage, exception);
            throw new RuntimeException(failureMessage, exception);
        }
    }