private static void addAttachment(Multipart multipart, String filename) { DataSource source = new FileDataSource(filename); BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName(filename); multipart.addBodyPart(messageBodyPart); }
private Multipart _multipart; _multipart = new MimeMultipart(); public void addAttachment(String filename,String subject) throws Exception { BodyPart messageBodyPart = new MimeBodyPart(); DataSource source = new FileDataSource(filename); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName(filename); _multipart.addBodyPart(messageBodyPart); BodyPart messageBodyPart2 = new MimeBodyPart(); messageBodyPart2.setText(subject); _multipart.addBodyPart(messageBodyPart2); } message.setContent(_multipart);
Multipart multipart = new MimeMultipart("mixed"); for (String str : attachment_PathList) { MimeBodyPart messageBodyPart = new MimeBodyPart(); DataSource source = new FileDataSource(str); messageBodyPart.setDataHandler(new DataHandler(source)); messageBodyPart.setFileName(source.getName()); multipart.addBodyPart(messageBodyPart); } msg.setContent(multipart); Transport.send(msg);
javax.sql.DataSource source = new org.apache.commons.dbcp.BasicDataSource(); source.setDriverClassName("com.mysql.jdbc.Driver"); source.setUsername("username"); source.setPassword("password"); source.setUrl("jdbc:mysql://localhost:3306/myDatabase");
MimeBodyPart mbp = new MimeBodyPart(); String data = "any ASCII data"; DataSource ds = new ByteArrayDataSource(data, "application/x-any"); mbp.setDataHandler(new DataHandler(ds));
import org.apache.commons.mail.*; // create the mail MultiPartEmail email = new MultiPartEmail(); email.setHostName("mail.myserver.com"); email.addTo("jdoe@somewhere.org", "John Doe"); email.setFrom("me@apache.org", "Me"); email.setSubject("The picture"); email.setMsg("Here is the picture you wanted"); // get your inputstream from your db InputStream is = new BufferedInputStream(MyUtils.getBlob()); DataSource source = new ByteArrayDataSource(is, "application/pdf"); // add the attachment email.attach(source, "somefile.pdf", "Description of some file"); // send the email email.send();
String h264Path = "path to my h264 file, generated by Android MediaCodec"; DataSource videoFile = new FileDataSourceImpl(h264Path); H264TrackImpl h264Track = new H264TrackImpl(videoFile, "eng", 5, 1); // 5fps. you can play with timescale and timetick to get non integer fps, 23.967 is 24000/1001 Movie movie = new Movie(); movie.addTrack(h264Track); Container out = new DefaultMp4Builder().build(movie); FileOutputStream fos = new FileOutputStream(new File("path to my generated file.mp4")); out.writeContainer(fos.getChannel()); fos.close();
DataSource source = new DataSource(new File("mycsvinputfile")); System.out.println(source.getStructure()); Instances data = source.getDataSet(); // setting class attribute if the data format does not provide this information // For example, the XRFF format saves the class attribute information as well if (data.classIndex() == -1) data.setClassIndex(data.numAttributes() - 1); //initialize svm classifier LibSVM svm = new LibSVM(); svm.buildClassifier(data);
DataSource source = new FileDataSource(file); attachment.setDataHandler(new DataHandler(source)); attachment.setFileName(file.getName());
DataSource source = new FileDataSource(filename);
private DataSource createDsManuallyUsingSomeExternalConfigurationSource() { DataSource ds = new org.apache.commons.dbcp.BasicDataSource(); ds.setDriverClassName("org.h2.Driver"); ds.setUrl(/*New database URL*/); ds.setUsername(/*New username*/); ds.setPassword(/*New password*/); return ds; }
// second part (the image) messageBodyPart = new MimeBodyPart(); DataSource fds = new FileDataSource ("C:\\images\\cec_header_457.png"); DataSource fds1 = new FileDataSource ("C:\\images\\cec_header_420.png"); messageBodyPart.setDataHandler(new DataHandler(fds)); messageBodyPart.setDataHandler(new DataHandler(fds1)); messageBodyPart.addHeader("Content-ID","<image>"); messageBodyPart.addHeader("Content-ID","<senny>"); // add it multipart.addBodyPart(messageBodyPart);
ByteArrayOutputStream bos = new ByteArrayOutputStream(); xlsFile.write(bos); // write excel data to a byte array fos.close(); // Now use your ByteArrayDataSource as DataSource fds = new ByteArrayDataSource(bos.toByteArray(), "application/vnd.ms-excel");
String fileName = "/WEB-INF/resources/images/logomailtemplate.png"; InputStream stream = getServletContext().getResourceAsStream(fileName); //or null if you can't obtain a ServletContext if (stream == null) { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); if (classLoader == null) { classLoader = this.getClass().getClassLoader(); } stream = classLoader.getResourceAsStream(fileName); } DataSource ds = new ByteArrayDataSource(stream, "image/*");
DataSource rawDS = /* your actual data source */ // (optional) make access lazy final DataSource lazyDS = new LazyConnectionDataSourceProxy(rawDataSource); // make spring transactions available in plain jdbc context final DataSource txDS = new TransactionAwareDataSourceProxy(lazyDS); // create jOOQ factory Factory jooq = new Factory(txDS, /* dialect */, /* settings */) // voila!
public class Program { public static void main(String[] args) { DataSource ds = new B(); //Here we've picked the concrete implementation MyThingThatNeedsData thing = new MyThingThatNeedsData(ds); //And we pass it in String result = thing.doSomethingThatRequiresData(); } }
FileItem f = files.get(0); // there is a problem here where the file being created is empty, since we only have a // partial path: DataSource source = new FileDataSource(new File(f.getName())); // because of the above problem, we are going to copy over the data ourselves: byte[] sourceBytes = f.get(); OutputStream sourceOS = source.getOutputStream(); sourceOS.write(sourceBytes);
SimpleJdbcTemplate db; DataSource dataSource = new SingleConnectionDataSource(System.getProperty( "lingcog.db.connectstring"), System.getProperty("lingcog.db.username"), System.getProperty("lingcog.db.password"), false); db = new SimpleJdbcTemplate(dataSource);
// First create the mock JNDI tree and bind the DS SimpleNamingContextBuilder builder = new SimpleNamingContextBuilder(); DataSource ds = new ComboPooledDataSource(); ds.setDriverClass( ... ); // etc. for uid, password, url builder.bind( "java:comp/env/jdbc/MyDS" , ds ); builder.activate(); // Then create the Spring context, which should now be able // to resolve the JNDI datasource ApplicationContext context = new ClassPathXmlApplicationContext( "..." );
PoolProperties p = new PoolProperties(); p.setUrl("jdbc:your-jdbc-url"); p.setDriverClassName("your.jdbc.driver.class"); p.setUsername("user"); p.setPassword("password"); p.setJdbcInterceptors( "org.apache.tomcat.jdbc.pool.interceptor.StatementCache"); DataSource datasource = new DataSource(); datasource.setPoolProperties(p);