本文整理汇总了Java中org.apache.wicket.util.lang.Bytes类的典型用法代码示例。如果您正苦于以下问题:Java Bytes类的具体用法?Java Bytes怎么用?Java Bytes使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Bytes类属于org.apache.wicket.util.lang包,在下文中一共展示了Bytes类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: render
import org.apache.wicket.util.lang.Bytes; //导入依赖的package包/类
@Override
public String render(Bytes value, Locale locale) {
double humanReadableSize = Long.valueOf(value.bytes()).doubleValue();
int unitKeyIndex = 0;
while (humanReadableSize > DISPLAY_LIMIT && unitKeyIndex < unitKeys.size() - 1) {
humanReadableSize = humanReadableSize / BYTES_IN_KB;
unitKeyIndex++;
}
DecimalFormat twoDecimalsFormat = new DecimalFormat(OUTPUT_DECIMAL_FORMAT, DecimalFormatSymbols.getInstance(locale));
return new StringBuilder(twoDecimalsFormat.format(humanReadableSize)).append(" ")
.append(getString(unitKeys.get(unitKeyIndex), locale))
.toString();
}
示例2: validate
import org.apache.wicket.util.lang.Bytes; //导入依赖的package包/类
@Override
public void validate(IValidatable<List<FileUpload>> validatable) {
for (FileUpload fileUpload : validatable.getValue()) {
Bytes fileSize = Bytes.bytes(fileUpload.getSize());
if (fileSize.greaterThan(maximum)) {
ValidationError error = new ValidationError();
if (errorResourceKey != null) {
error.addKey(errorResourceKey);
}
error.addKey(this);
error.setVariable("maximum", maximum);
error.setVariable("clientFileName", fileUpload.getClientFileName());
error.setVariable("size", fileSize);
validatable.error(error);
}
}
}
示例3: UploadForm
import org.apache.wicket.util.lang.Bytes; //导入依赖的package包/类
public UploadForm(String id) {
super(id);
setMultiPart(true);
setMaxSize(Bytes.megabytes(2));
fileUploadField = new FileUploadField("upload");
add(fileUploadField);
add(new Button("continuebutton"));
Button cancel = new Button("cancelbutton"){
public void onSubmit() {
// info("Cancel was pressed!");
setResponsePage(new GradebookPage());
}
};
cancel.setDefaultFormProcessing(false);
add(cancel);
}
示例4: setupCache
import org.apache.wicket.util.lang.Bytes; //导入依赖的package包/类
private void setupCache() {
// configure cache by applying the vlo configuration settings to it
final int pagesInApplicationCache = vloConfig.getPagesInApplicationCache();
logger.info("Setting Wicket in-memory cache size to {}", pagesInApplicationCache);
this.getStoreSettings().setInmemoryCacheSize(pagesInApplicationCache);
final Bytes sessionCacheSize = Bytes.kilobytes((long) vloConfig.getSessionCacheSize());
logger.info("Setting Wicket max size per session to {}", sessionCacheSize);
this.getStoreSettings().setMaxSizePerSession(sessionCacheSize);
}
示例5: init
import org.apache.wicket.util.lang.Bytes; //导入依赖的package包/类
@Override
public void init() {
super.init();
getRequestCycleSettings().setTimeout(Duration.minutes(5));
getRequestCycleListeners().add(new SingularServerContextListener());
Locale.setDefault(new Locale("pt", "BR"));//NOSONAR
getApplicationSettings().setAccessDeniedPage(Error403Page.class);
getApplicationSettings().setPageExpiredErrorPage(Page410.class);
// Don't forget to check your Application server for this
getApplicationSettings().setDefaultMaximumUploadSize(Bytes.megabytes(10));
getMarkupSettings().setStripWicketTags(true);
getMarkupSettings().setStripComments(true);
getMarkupSettings().setDefaultMarkupEncoding(StandardCharsets.UTF_8.name());
getComponentOnConfigureListeners().add(component -> {
boolean outputId = !component.getRenderBodyOnly();
component.setOutputMarkupId(outputId).setOutputMarkupPlaceholderTag(outputId);
});
getComponentInstantiationListeners().add(new SpringComponentInjector(this, getApplicationContext(), true));
new SingularAnnotatedMountScanner().mountPages(this);
if (RuntimeConfigurationType.DEVELOPMENT == getConfigurationType()) {
getDebugSettings().setComponentPathAttributeName("wicketdebug");
WicketSerializationDebugUtil.configurePageSerializationDebug(this, this.getClass());
}
}
示例6: setObject
import org.apache.wicket.util.lang.Bytes; //导入依赖的package包/类
@Override
public void setObject(Long object) {
if (object == null) {
bytesModel.setObject(null);
} else {
bytesModel.setObject(Bytes.bytes(object));
}
super.setObject(object);
}
示例7: onInitialize
import org.apache.wicket.util.lang.Bytes; //导入依赖的package包/类
@Override
protected void onInitialize() {
super.onInitialize();
final Form<Void> form = new Form<>("form");
form.setMultiPart(true);
form.setMaxSize(Bytes.bytes(getMaxUploadSize()));
// Model is necessary here to avoid writing image to the User object
form.add(fileUploadField);
form.add(new UploadProgressBar("progress", form, fileUploadField));
fileUploadField.add(new AjaxFormSubmitBehavior(form, "change") {
private static final long serialVersionUID = 1L;
@Override
protected void onSubmit(AjaxRequestTarget target) {
FileUpload fu = fileUploadField.getFileUpload();
if (fu != null) {
File temp = null;
try {
temp = fu.writeToTempFile();
StoredFile sf = new StoredFile(fu.getClientFileName(), temp);
if (sf.isImage()) {
processImage(sf, temp);
}
} catch (Exception e) {
log.error("Error", e);
} finally {
if (temp != null && temp.exists()) {
log.debug("Temp file was deleted ? {}", temp.delete());
}
fu.closeStreams();
fu.delete();
}
}
update();
target.add(profile, form);
}
});
add(form.setOutputMarkupId(true));
add(BootstrapFileUploadBehavior.INSTANCE);
}
示例8: parse
import org.apache.wicket.util.lang.Bytes; //导入依赖的package包/类
public static Bytes parse(Long size, SessionUnit sessionUnit){
switch(sessionUnit){
case BYTES:
return Bytes.bytes(size);
case KILOBYTES:
return Bytes.kilobytes(size);
case MEGABYTES:
return Bytes.megabytes(size);
case TERABYTES:
return Bytes.terabytes(size);
}
throw new WicketSpringBootException("Could not parse size with session unit " + size + " " + sessionUnit);
}
示例9: DefaultFileUploadForm
import org.apache.wicket.util.lang.Bytes; //导入依赖的package包/类
public DefaultFileUploadForm(String name, UploadListener listener) {
super(name, ContextHelper.get().getArtifactoryHome().getTempUploadDir().getAbsolutePath(), listener);
add(new SubmitOnceBehavior());
//Set maximum upload size
int uploadMaxSizeMb = centralConfig.getDescriptor().getFileUploadMaxSizeMb();
if (uploadMaxSizeMb > 0) {
setMaxSize(Bytes.megabytes(uploadMaxSizeMb));
}
}
示例10: LogoFileUploadForm
import org.apache.wicket.util.lang.Bytes; //导入依赖的package包/类
public LogoFileUploadForm(String name, UploadListener listener) {
super(name, ContextHelper.get().getArtifactoryHome().getTempUploadDir().getAbsolutePath(), listener);
add(new SubmitOnceBehavior());
//Set maximum upload size
int uploadMaxSizeMb = centralConfig.getDescriptor().getFileUploadMaxSizeMb();
if (uploadMaxSizeMb > 0) {
setMaxSize(Bytes.megabytes(uploadMaxSizeMb));
}
}
示例11: FileUploadForm
import org.apache.wicket.util.lang.Bytes; //导入依赖的package包/类
public FileUploadForm(String id, String userUuid, FeedbackPanel fileFeedback) {
super(id);
this.userUuid = userUuid;
this.fileFeedback = fileFeedback;
// set form to multipart mode
setMultiPart(true);
setMaxSize(Bytes.megabytes(sakaiProxy.getMaxProfilePictureSize()
* ProfileConstants.MAX_GALLERY_FILE_UPLOADS));
}
示例12: FileUploadForm
import org.apache.wicket.util.lang.Bytes; //导入依赖的package包/类
public FileUploadForm(String name, ValidatorPage page) {
super(name);
this.page = page;
setMultiPart(true);
add(fileUploadField = new FileUploadField("fileInput"));
setMaxSize(Bytes.kilobytes(100));
}
示例13: FileUploadForm
import org.apache.wicket.util.lang.Bytes; //导入依赖的package包/类
public FileUploadForm(EntityModel<Entry> entry) {
super("uploadForm");
this.entry = entry;
setMultiPart(true);
add(fileUploadField = new FileUploadField("fileInput"));
setMaxSize(Bytes.megabytes(50));
}
示例14: UploadLicenseForm
import org.apache.wicket.util.lang.Bytes; //导入依赖的package包/类
public UploadLicenseForm(String id) {
super(id);
// set this form to multipart mode (allways needed for uploads!)
setMultiPart(true);
// add one file input field
add(fileUploadField = new FileUploadField("fileInput"));
// set maximum size to 100K
setMaxSize(Bytes.kilobytes(100));
}
示例15: newSessionStore
import org.apache.wicket.util.lang.Bytes; //导入依赖的package包/类
@Override
protected ISessionStore newSessionStore() {
DiskPageStore page = new DiskPageStore((int) Bytes.megabytes(100).bytes(), (int) Bytes.gigabytes(1.0).bytes(), 50);
SecondLevelCacheSessionStore store = new SecondLevelCacheSessionStore(this, page);
return store;
}