Java Code Examples for org.apache.wicket.util.io.IOUtils

The following examples show how to use org.apache.wicket.util.io.IOUtils. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: onedev   Source File: CssConcatResourceBundleReference.java    License: MIT License 5 votes vote down vote up
@Override
public IResource getResource() {
	ConcatBundleResource bundleResource = new ConcatBundleResource(getProvidedResources()) {

		@Override
		protected byte[] readAllResources(List<IResourceStream> resources)
				throws IOException, ResourceStreamNotFoundException {
			ByteArrayOutputStream output = new ByteArrayOutputStream();
			for (IResourceStream curStream : resources) {
				IOUtils.copy(curStream.getInputStream(), output);
				output.write("\n".getBytes());
			}

			byte[] bytes = output.toByteArray();

			if (getCompressor() != null) {
				String nonCompressed = new String(bytes, "UTF-8");
				bytes = getCompressor().compress(nonCompressed).getBytes("UTF-8");
			}

			return bytes;
		}
		
	};
	ITextResourceCompressor compressor = getCompressor();
	if (compressor != null) {
		bundleResource.setCompressor(compressor);
	}
	return bundleResource;
}
 
Example 2
Source Project: onedev   Source File: JavaScriptConcatResourceBundleReference.java    License: MIT License 5 votes vote down vote up
@Override
public IResource getResource() {
	ConcatBundleResource bundleResource = new ConcatBundleResource(getProvidedResources()) {

		@Override
		protected byte[] readAllResources(List<IResourceStream> resources)
				throws IOException, ResourceStreamNotFoundException {
			ByteArrayOutputStream output = new ByteArrayOutputStream();
			for (IResourceStream curStream : resources) {
				IOUtils.copy(curStream.getInputStream(), output);
				output.write(";\n".getBytes());
			}

			byte[] bytes = output.toByteArray();

			if (getCompressor() != null) {
				String nonCompressed = new String(bytes, "UTF-8");
				bytes = getCompressor().compress(nonCompressed).getBytes("UTF-8");
			}

			return bytes;
		}
		
	};
	ITextResourceCompressor compressor = getCompressor();
	if (compressor != null) {
		bundleResource.setCompressor(compressor);
	}
	return bundleResource;
}
 
Example 3
Source Project: openmeetings   Source File: RoomsPanel.java    License: Apache License 2.0 5 votes vote down vote up
public RoomsPanel(String id, List<Room> rooms) {
	super(id);
	this.rooms = rooms;
	clients = new ListView<>("clients", clientsInRoom){
		private static final long serialVersionUID = 1L;

		@Override
		protected void populateItem(final ListItem<Client> item) {
			Client client = item.getModelObject();
			final Long userId = client.getUserId();
			item.add(new Image("clientImage", new ByteArrayResource("image/png") {
				private static final long serialVersionUID = 1L;

				@Override
				protected ResourceResponse newResourceResponse(Attributes attributes) {
					ResourceResponse rr = super.newResourceResponse(attributes);
					rr.disableCaching();
					return rr;
				}

				@Override
				protected byte[] getData(Attributes attributes) {
					String uri = null;
					if (userId != null) {
						uri = userDao.get(userId > 0 ? userId : -userId).getPictureUri();
					}
					File img = OmFileHelper.getUserProfilePicture(userId, uri);
					try (InputStream is = new FileInputStream(img)) {
						return IOUtils.toByteArray(is);
					} catch (Exception e) {
						//no-op
					}
					return null;
				}
			}));
			item.add(new Label("clientLogin", client.getUser().getLogin()));
			item.add(new Label("from", client.getConnectedSince()));
		}
	};
}
 
Example 4
Source Project: webanno   Source File: UrlImporter.java    License: Apache License 2.0 5 votes vote down vote up
private String read(URL url)
{
    try {
        return IOUtils.toString(url.openStream(), StandardCharsets.UTF_8.name());
    }
    catch (IOException ex) {
        throw new WicketRuntimeException(ex);
    }
}
 
Example 5
Source Project: Orienteer   Source File: OrienteerClassLoaderUtil.java    License: Apache License 2.0 5 votes vote down vote up
/**
   * Download Orienteer artifacts from server.
   * @return list of {@link OArtifact} from server
   * @throws IOException 
   */
  public static List<OArtifact> getOrienteerArtifactsFromServer() throws IOException  {
  	
  	URL website = new URL(initUtils.getOrienteerModulesUrl());
  	File localFile = new File(initUtils.getPathToModulesFolder().toFile(), "modules.xml");
  	FileOutputStream fos = new FileOutputStream(localFile);
  	try {
  		IOUtils.copy(website.openStream(), fos);
  	} finally {
	fos.close();
}
  	
      OrienteerArtifactsReader reader = new OrienteerArtifactsReader(localFile.toPath());
      List<OArtifact> ooArtifacts = reader.readArtifacts();
      List<OArtifact> metadataModules = getOArtifactsMetadataAsList();
      for (OArtifact metadataModule : metadataModules) {
          for (OArtifact module : ooArtifacts) {
              OArtifactReference metadataArtifact = metadataModule.getArtifactReference();
              OArtifactReference moduleArtifact = module.getArtifactReference();
              if (metadataArtifact.getGroupId().equals(moduleArtifact.getGroupId()) &&
                      metadataArtifact.getArtifactId().equals(moduleArtifact.getArtifactId())) {
                  module.setDownloaded(true);
              }
          }
      }
      addAvailableVersions(ooArtifacts);
      return ooArtifacts;
  }
 
Example 6
Source Project: syncope   Source File: MIMETypesLoader.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected String getMimeTypesFile() throws IOException {
    return IOUtils.toString(getClass().getResourceAsStream("/MIMETypes.json"));
}
 
Example 7
Source Project: syncope   Source File: MIMETypesLoader.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected String getMimeTypesFile() throws IOException {
    return IOUtils.toString(getClass().getResourceAsStream("/MIMETypes.json"));
}
 
Example 8
Source Project: Orienteer   Source File: TestModule.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testModuleLoaded() throws EngineException, IOException
{
    OrienteerWebApplication app = tester.getApplication();
    assertNotNull(app);
    IOrienteerModule module = app.getModuleByName(Module.MODULE_NAME);
    assertNotNull(module);
    assertTrue(module instanceof Module);
    ClassLoader loader = getClass().getClassLoader();
    URL innerResource = loader.getResource("test.rptdesign");
    
    HtmlBirtResource resource = new HtmlBirtResource(
    		new BirtHtmlReportPanel("rp",
    				new BirtReportFileConfig(innerResource.getFile())
    		)
    );
    MockWebRequest request = new MockWebRequest(new Url());
    ByteArrayResponse response = new ByteArrayResponse();
    Attributes attributes = new IResource.Attributes(request, response); 
    
    resource.respond(attributes);
    
    String newResult = new String(response.getBytes());
    FileInputStream savedStream = new FileInputStream(loader.getResource("test.rptdesign.result.html").getFile());
    String oldResult;
    
    try {
        oldResult = IOUtils.toString(savedStream);
    } finally {
    	savedStream.close();
    }
    
    assertEquals(oldResult.replace("\r\n",  "\n"),newResult.replace("\r\n",  "\n"));
    //ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
    //OutputStream stream = response.getOutputStream();
    
    //FileOutputStream out = new FileOutputStream("test.rptdesign.result.html");
    //out.write(response.getBytes());
    //out.close();

    //System.out.println(new String(response.getBytes()));
    
    //BirtHtmlReportPanel testedPanel = new BirtHtmlReportPanel("panel", null);
    
    
}