Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.github.sanity4j.report;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
import java.util.StringTokenizer;
import com.github.sanity4j.util.QaLogger;
import com.github.sanity4j.util.StringUtil;
import com.github.sanity4j.workflow.QAConfig;
/**
* ExtractStaticContent - extracts static content for the report.
*
* @author Yiannis Paschalidis
* @since Sanity4J 1.0
*/
public final class ExtractStaticContent
{
/** The buffer size to use when copying the data. */
private static final int BUFFER_SIZE = 1024;
/** ExtractStaticContent should not be instantiated. */
private ExtractStaticContent()
{
}
/**
* Copies a resource.
*
* @param classLoader the classloader used to load the resource.
* @param resourcePath the path to the resource
* @param destDir the directory to write the resource to
* @param destPath the destination path, relative to destDir
*
* @throws IOException if there is an error writing the file
*/
private static void copyResource(final ClassLoader classLoader,
final String resourcePath, final File destDir,
final String destPath) throws IOException
{
// Get the resource as a stream
InputStream inStream = classLoader.getResourceAsStream(resourcePath);
if (inStream == null)
{
// If not found, try loading from the default.
inStream = ExtractStaticContent.class.getResourceAsStream(resourcePath);
}
if (inStream == null)
{
// If not found, try loading from the current classloader.
inStream = ExtractStaticContent.class.getClassLoader().getResourceAsStream(resourcePath);
}
if (inStream == null)
{
QaLogger.getInstance().error("Resource [" + resourcePath + "] doesn't exist");
return;
}
// Set up the destination file
File destFile = new File(destDir, destPath);
if (!destFile.getParentFile().exists() && !destFile.getParentFile().mkdirs())
{
QaLogger.getInstance().error("Failed to create parent directory for file [" + destPath + "]");
return;
}
// Copy the data
FileOutputStream fos = new FileOutputStream(destFile);
byte[] buf = new byte[BUFFER_SIZE];
for (int count = inStream.read(buf); count != -1; count = inStream.read(buf))
{
fos.write(buf, 0, count);
}
fos.close();
inStream.close();
}
/**
* Extracts all of the static content specified by a Properties object to the destination directory.
*
* @param classLoader the classloader used to load the resources.
* @param destDir the destination directory
* @param properties a properties file containing name / value pairs
* representing the source resources, and their destinations.
* @throws IOException if there is an error extracting the static content
*/
private static void extractContent(final ClassLoader classLoader, final File destDir, final Properties properties) throws IOException
{
for (Enumeration