Search in sources :

Example 1 with Bytes

use of org.apache.wicket.util.lang.Bytes in project wicket by apache.

the class MultipartServletWebRequestImpl method newFileUpload.

/**
 * Factory method for creating new instances of FileUploadBase
 *
 * @param encoding
 *            The encoding to use while reading the data
 * @return A new instance of FileUploadBase
 */
protected FileUploadBase newFileUpload(String encoding) {
    // Configure the factory here, if desired.
    ServletFileUpload fileUpload = new ServletFileUpload(fileItemFactory);
    // set encoding specifically when we found it
    if (encoding != null) {
        fileUpload.setHeaderEncoding(encoding);
    }
    fileUpload.setSizeMax(getMaxSize().bytes());
    Bytes fileMaxSize = getFileMaxSize();
    if (fileMaxSize != null) {
        fileUpload.setFileSizeMax(fileMaxSize.bytes());
    }
    return fileUpload;
}
Also used : Bytes(org.apache.wicket.util.lang.Bytes) ServletFileUpload(org.apache.commons.fileupload.servlet.ServletFileUpload)

Example 2 with Bytes

use of org.apache.wicket.util.lang.Bytes in project wicket by apache.

the class BytesTest method stringOperationsCommaLocale.

/**
 * @throws StringValueConversionException
 */
@Test
public void stringOperationsCommaLocale() throws StringValueConversionException {
    Locale.setDefault(Locale.GERMANY);
    assertTrue("1G".equals(Bytes.gigabytes(1).toString()));
    assertTrue(Bytes.valueOf("15,5K").bytes() == ((15 * 1024) + 512));
    final Bytes b = Bytes.kilobytes(7.3);
    assertTrue(Bytes.valueOf(b.toString()).equals(b));
}
Also used : Bytes(org.apache.wicket.util.lang.Bytes) Test(org.junit.Test)

Example 3 with Bytes

use of org.apache.wicket.util.lang.Bytes in project wicket by apache.

the class BytesTest method allOperationsCurrentLocale.

/**
 * @throws StringValueConversionException
 */
@Test
public void allOperationsCurrentLocale() throws StringValueConversionException {
    assertTrue(Bytes.bytes(1024).equals(Bytes.kilobytes(1)));
    assertTrue(Bytes.bytes(1024 * 1024).equals(Bytes.megabytes(1)));
    assertTrue("1G".equals(Bytes.gigabytes(1).toString()));
    final Bytes b = Bytes.kilobytes(7.3);
    assertTrue(b.equals(Bytes.kilobytes(7.3)));
    assertTrue(b.greaterThan(Bytes.kilobytes(7.25)));
    assertTrue(b.lessThan(Bytes.kilobytes(7.9)));
    assertTrue(Bytes.valueOf(b.toString()).equals(b));
}
Also used : Bytes(org.apache.wicket.util.lang.Bytes) Test(org.junit.Test)

Example 4 with Bytes

use of org.apache.wicket.util.lang.Bytes in project wicket by apache.

the class PageSizeDebugPanel method getDataModel.

@Override
protected IModel<String> getDataModel() {
    return new IModel<String>() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getObject() {
            Page enclosingPage = getPage();
            long pageSize = WicketObjects.sizeof(enclosingPage);
            Bytes pageSizeInBytes = (pageSize > -1 ? Bytes.bytes(pageSize) : null);
            String pageSizeAsString = pageSizeInBytes != null ? pageSizeInBytes.toString() : "unknown";
            return "Page: " + pageSizeAsString;
        }
    };
}
Also used : Bytes(org.apache.wicket.util.lang.Bytes) IModel(org.apache.wicket.model.IModel) Page(org.apache.wicket.Page) WebPage(org.apache.wicket.markup.html.WebPage)

Example 5 with Bytes

use of org.apache.wicket.util.lang.Bytes in project wicket by apache.

the class DebugPageManagerProvider method newDataStore.

@Override
protected IDataStore newDataStore() {
    StoreSettings storeSettings = application.getStoreSettings();
    File fileStoreFolder = storeSettings.getFileStoreFolder();
    Bytes maxSizePerSession = storeSettings.getMaxSizePerSession();
    dataStore = new DebugDiskDataStore(application.getName(), fileStoreFolder, maxSizePerSession);
    return dataStore;
}
Also used : StoreSettings(org.apache.wicket.settings.StoreSettings) Bytes(org.apache.wicket.util.lang.Bytes) File(java.io.File)

Aggregations

Bytes (org.apache.wicket.util.lang.Bytes)12 Test (org.junit.Test)5 File (java.io.File)2 IModel (org.apache.wicket.model.IModel)2 StoreSettings (org.apache.wicket.settings.StoreSettings)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 FileItem (org.apache.commons.fileupload.FileItem)1 FileUploadException (org.apache.commons.fileupload.FileUploadException)1 ServletFileUpload (org.apache.commons.fileupload.servlet.ServletFileUpload)1 Page (org.apache.wicket.Page)1 UrlResourceStream (org.apache.wicket.core.util.resource.UrlResourceStream)1 SessionSizeModel (org.apache.wicket.devutils.inspector.SessionSizeModel)1 WebPage (org.apache.wicket.markup.html.WebPage)1 DiskDataStore (org.apache.wicket.pageStore.DiskDataStore)1