public void setBinaryStream(int parameterIndex, java.io.InputStream x, int length) throws SQLException { try { byte[] data = new byte[length]; x.read(data, 0, length); setBytes(parameterIndex, data); } catch (java.io.IOException e) { throw new SQLException("I/O failed"); } }
/** * A little test program. * * @param args */ public static void main(String[] args) throws Exception { Configuration conf = new Configuration(); CompressionCodecFactory factory = new CompressionCodecFactory(conf); boolean encode = false; for (int i = 0; i < args.length; ++i) { if ("-in".equals(args[i])) { encode = true; } else if ("-out".equals(args[i])) { encode = false; } else { CompressionCodec codec = factory.getCodec(new Path(args[i])); if (codec == null) { System.out.println("Codec for " + args[i] + " not found."); } else { if (encode) { CompressionOutputStream out = codec.createOutputStream(new java.io.FileOutputStream(args[i])); byte[] buffer = new byte[100]; String inFilename = removeSuffix(args[i], codec.getDefaultExtension()); java.io.InputStream in = new java.io.FileInputStream(inFilename); int len = in.read(buffer); while (len > 0) { out.write(buffer, 0, len); len = in.read(buffer); } in.close(); out.close(); } else { CompressionInputStream in = codec.createInputStream(new java.io.FileInputStream(args[i])); byte[] buffer = new byte[100]; int len = in.read(buffer); while (len > 0) { System.out.write(buffer, 0, len); len = in.read(buffer); } in.close(); } } } } }
public void unpack(String artifact, File destination) { File archiveFile = getAsFile(artifact); if (archiveFile == null || !archiveFile.exists()) return; if (archiveFile.isDirectory()) { try { Files.walkFileTree(archiveFile.toPath(), new CopyDirVisitor(archiveFile, destination)); } catch (Exception e) { OutputBouble.reportError(e); } } else if (archiveFile.getName().endsWith("jar")) { destination.mkdirs(); try { java.util.jar.JarFile jar = new java.util.jar.JarFile(archiveFile); java.util.Enumeration jarEnum = jar.entries(); while (jarEnum.hasMoreElements()) { java.util.jar.JarEntry file = (java.util.jar.JarEntry) jarEnum.nextElement(); java.io.File f = new java.io.File(destination + java.io.File.separator + file.getName()); if (file.isDirectory()) { // if its a directory, create it f.mkdir(); continue; } java.io.InputStream is = jar.getInputStream(file); // get the input stream java.io.FileOutputStream fos = new java.io.FileOutputStream(f); while (is.available() > 0) { // write contents of 'is' to 'fos' fos.write(is.read()); } fos.close(); is.close(); } jar.close(); } catch (Exception e) { } } }