Example usage for org.hibernate.engine.jdbc ReaderInputStream ReaderInputStream

List of usage examples for org.hibernate.engine.jdbc ReaderInputStream ReaderInputStream

Introduction

In this page you can find the example usage for org.hibernate.engine.jdbc ReaderInputStream ReaderInputStream.

Prototype

public ReaderInputStream(Reader reader) 

Source Link

Document

Constructs a ReaderInputStream from a Reader

Usage

From source file:edu.brandeis.cs.planner.utils.WsdlClient.java

License:Apache License

public void init(Reader reader) throws WSDLClientException {
    conf = new ServiceConf();
    try {/*from   ww  w. j a  va2  s  .  c om*/
        StringWriter writer = new StringWriter();
        copy(new ReaderInputStream(reader), writer);
        wsdl = writer.toString();
        init(conf);
    } catch (Exception e) {
        throw new WSDLClientException(e);
    }
}

From source file:nl.mpi.lamus.ams.implementation.AmsFakeRemoteServiceHelperTest.java

License:Open Source License

@Test
public void sendCallToAccessRightsManagementSystem() throws Exception {

    final String expectedString = "some text to read and test the method and bla bla bla";
    final StringReader reader = new StringReader(expectedString);
    final InputStream fakeInputStream = new ReaderInputStream(reader);
    final URL recalcURL = new URL("http://127.0.0.1/ams/pages/recalc.face?nodeid=MPI0%23%2CMPI1%23");

    context.checking(new Expectations() {
        {//from   ww  w  . j a va  2 s  .  c o  m

            oneOf(mockUrl).getURL();
            will(returnValue(recalcURL));
            oneOf(mockUrl).openConnection();
            will(returnValue(mockUrlConnection));
            oneOf(mockUrlConnection).setDoInput(Boolean.TRUE);
            oneOf(mockUrlConnection).setDoOutput(Boolean.FALSE);
            oneOf(mockUrlConnection).setUseCaches(Boolean.FALSE);
            oneOf(mockUrlConnection).setRequestProperty("Content-Type", "text");
            oneOf(mockUrlConnection).getInputStream();
            will(returnValue(fakeInputStream));

            oneOf(mockUrlConnection).disconnect();
        }
    });

    amsFakeRemoteServiceHelper.sendCallToAccessRightsManagementSystem(mockUrl);
}

From source file:org.libreplan.web.orders.files.OrderFilesController.java

License:Open Source License

/**
 * Should be public!/*  w  ww.  j  a  v  a2  s.co  m*/
 * Used in _listOrderElementFiles.zul
 */
public void upload() {
    configurationModel.init();

    String directory;
    if (isRepositoryExists()) {

        String projectCode = orderElementModel.getOrderElement().getCode();
        directory = configurationModel.getRepositoryLocation() + "orders" + "/" + projectCode;

        try {
            // Location of file: libreplan-webapp/src/main/webapp/planner/fileupload.zul
            Fileupload.setTemplate("fileupload.zul");

            Media media = Fileupload.get();

            File dir = new File(directory);
            String filename = media.getName();
            File file = new File(dir, filename);

            // By default Java do not create directories itself
            file.getParentFile().mkdirs();

            OutputStream outputStream = new FileOutputStream(file);

            InputStream inputStream = media.isBinary() ? media.getStreamData()
                    : new ReaderInputStream(media.getReaderData());

            if (inputStream != null) {
                byte[] buffer = new byte[1024];
                for (int count; (count = inputStream.read(buffer)) != -1;) {
                    outputStream.write(buffer, 0, count);
                }
            }

            outputStream.flush();
            outputStream.close();

            if (inputStream != null) {
                inputStream.close();
            }

            orderFileModel.createNewFileObject();
            orderFileModel.setFileName(FilenameUtils.getBaseName(media.getName()));

            orderFileModel.setFileType(FilenameUtils.getExtension(media.getName()).isEmpty()
                    ? OrderFileModel.UNKNOWN_FILE_EXTENSION
                    : FilenameUtils.getExtension(media.getName()));

            orderFileModel.setUploadDate(new Date());
            orderFileModel.setUploader(userDAO.findByLoginName(SecurityUtils.getSessionUserLoginName()));
            orderFileModel.setParent(orderElementModel.getOrderElement());

            orderFileModel.confirmSave();

        } catch (Exception e) {
            e.printStackTrace();
        }

        finally {
            updateListbox();
        }

    } else
        messages.showMessage(Level.ERROR, _("Please, make repository"));

}