/** * Read the content of the Path and returns it as a byte[]. * * @param self the file whose content we want to read * @return a String containing the content of the file * @throws java.io.IOException if an IOException occurs. * @since 2.3.0 */ public static byte[] getBytes(Path self) throws IOException { return IOGroovyMethods.getBytes(Files.newInputStream(self)); }
/** * Read the content of the File and returns it as a byte[]. * * @param file the file whose content we want to read * @return a String containing the content of the file * @throws IOException if an IOException occurs. * @since 1.7.1 */ public static byte[] getBytes(File file) throws IOException { return IOGroovyMethods.getBytes(new FileInputStream(file)); }
@Deprecated public static byte[] getBytes(InputStream is) throws IOException { return IOGroovyMethods.getBytes(is); }
/** * Read the content of this URL and returns it as a byte[]. * * @param url URL to read content from * @return the byte[] from that URL * @throws IOException if an IOException occurs. * @since 1.7.1 */ public static byte[] getBytes(URL url) throws IOException { return IOGroovyMethods.getBytes(url.openConnection().getInputStream()); }
/** * Read the content of this URL and returns it as a byte[]. * The default connection parameters can be modified by adding keys to the * <i>parameters map</i>: * <ul> * <li>connectTimeout : the connection timeout</li> * <li>readTimeout : the read timeout</li> * <li>useCaches : set the use cache property for the URL connection</li> * <li>allowUserInteraction : set the user interaction flag for the URL connection</li> * <li>requestProperties : a map of properties to be passed to the URL connection</li> * </ul> * * @param url URL to read content from * @param parameters connection parameters * @return the byte[] from that URL * @throws IOException if an IOException occurs. * @since 2.4.4 */ public static byte[] getBytes(URL url, Map parameters) throws IOException { return IOGroovyMethods.getBytes(configuredInputStream(parameters, url)); }
/** * Read the content of the Path and returns it as a byte[]. * * @param self the file whose content we want to read * @return a String containing the content of the file * @throws java.io.IOException if an IOException occurs. * @since 2.3.0 */ public static byte[] getBytes(Path self) throws IOException { return IOGroovyMethods.getBytes(Files.newInputStream(self)); }
@Override public void save(Client client, InputStream stream) throws IOException { String path = client.getFixtureLocation(fileName); String testResourcesFromSystem = System.getProperty(AbstractContentMinion.TEST_RESOURCES_FOLDER_PROPERTY_NAME); File file = new File(testResourcesFromSystem != null ? testResourcesFromSystem : "src/test/resources", path); file.getParentFile().mkdirs(); try (FileOutputStream out = new FileOutputStream(file)) { IOGroovyMethods.setBytes(out, IOGroovyMethods.getBytes(stream)); } }
/** * Saves the fixture to the appropriate location. * * The root for the fixtures is either specified with `TEST_RESOURCES_FOLDER` system property or defaults to * <code>src/test/resources</code>. * * @param fileName relative name of the file * @param stream the stream with the content for the new file */ public void writeStream(String fileName, InputStream stream) throws IOException { String path = getFixtureLocation(fileName); File file = new File(getTestResourcesLocation(), path); file.getParentFile().mkdirs(); try (FileOutputStream out = new FileOutputStream(file)) { IOGroovyMethods.setBytes(out, IOGroovyMethods.getBytes(stream)); } }