You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Gary Gregory <ga...@gmail.com> on 2015/06/17 09:50:01 UTC

ByteSizeUnit a la TimeUnit

Hi All:

Java 5 introduced TimeUnit, a very nice enum.

What do you all think of a ByteSizeUnit enum to handle bit, nibble, byte,
kilobyte, kilobit, megabyte and so on?

Gary

-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: ByteSizeUnit a la TimeUnit

Posted by Bernd Eckenfels <ec...@zusammenkunft.net>.
Am Fri, 17 Jul 2015 16:53:55 -0700
schrieb Gary Gregory <ga...@gmail.com>:

> > - Differenciate between decimal and binary prefixes, e.g. 1
> > Megabyte = 1000 Kilobyte, but 1 Mebibyte = 1024 Kibibyte. Not sure
> > whether this is really that important.
> >
> 
> If we were to do only one I would do the base 2 case. But I can see
> offering a second enum for base 10.

I would vote for both (and maybe even the 1MB  = 1000 * 1 KiB some
systems use?).

I wonder, why you would want different enums (classes)?

For using Kib (kibi-bits) the question is, should this always use 8bit
or are there also times you need 9 or 10 bits?

Gruss
Bernd

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Re: ByteSizeUnit a la TimeUnit

Posted by Gary Gregory <ga...@gmail.com>.
On Wed, Jun 17, 2015 at 6:25 AM, Benedikt Ritter <br...@apache.org> wrote:

> 2015-06-17 14:03 GMT+02:00 David Blevins <da...@gmail.com>:
>
> > I'd be happy to donate these if we want them:
> >
> >
> >
> https://raw.githubusercontent.com/tomitribe/tomitribe-util/master/src/main/java/org/tomitribe/util/SizeUnit.java
> >
> >
> https://raw.githubusercontent.com/tomitribe/tomitribe-util/master/src/test/java/org/tomitribe/util/SizeUnitTest.java
> >
> > Which commons lib would these go in?  (can send a patch)
> >
>
> Very nice! We would add this to Commons IO. You can contribute via github,
> if you like [1]. There are a few things to take into account imho:
>
> - Differenciate between decimal and binary prefixes, e.g. 1 Megabyte = 1000
> Kilobyte, but 1 Mebibyte = 1024 Kibibyte. Not sure whether this is really
> that important.
>

If we were to do only one I would do the base 2 case. But I can see
offering a second enum for base 10.

Gary

- Petta, Exa, Zetta and Yotta prefixes are missing. At least Petta my
> become important soon.
> - What about translations to bits? For example band width are often
> calculated in Mega Bits/sec
> - What about overflows when translating for example Exabytes to Bytes? The
> result won't fit into a long.
>
> I've also put an enum together but without translation logic, because of
> the overflow problem [2]. Maybe the implementations can be merged some how?
>
> Benedikt
>
> [1] https://github.com/apache/commons-io
> [2]
>
> https://issues.apache.org/jira/secure/attachment/12694350/IO-294_FileSizeUnit.patch
>
>
> >
> >
> > -David
> >
> > On Wed, Jun 17, 2015 at 8:50 AM, Gary Gregory <ga...@gmail.com>
> > wrote:
> >
> > > Hi All:
> > >
> > > Java 5 introduced TimeUnit, a very nice enum.
> > >
> > > What do you all think of a ByteSizeUnit enum to handle bit, nibble,
> byte,
> > > kilobyte, kilobit, megabyte and so on?
> > >
> > > Gary
> > >
> > > --
> > > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > > Java Persistence with Hibernate, Second Edition
> > > <http://www.manning.com/bauer3/>
> > > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > > Spring Batch in Action <http://www.manning.com/templier/>
> > > Blog: http://garygregory.wordpress.com
> > > Home: http://garygregory.com/
> > > Tweet! http://twitter.com/GaryGregory
> > >
> >
>
>
>
> --
> http://people.apache.org/~britter/
> http://www.systemoutprintln.de/
> http://twitter.com/BenediktRitter
> http://github.com/britter
>



-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: ByteSizeUnit a la TimeUnit

Posted by Gary Gregory <ga...@gmail.com>.
On Wed, Jun 17, 2015 at 6:25 AM, Benedikt Ritter <br...@apache.org> wrote:

> 2015-06-17 14:03 GMT+02:00 David Blevins <da...@gmail.com>:
>
> > I'd be happy to donate these if we want them:
> >
> >
> >
> https://raw.githubusercontent.com/tomitribe/tomitribe-util/master/src/main/java/org/tomitribe/util/SizeUnit.java
> >
> >
> https://raw.githubusercontent.com/tomitribe/tomitribe-util/master/src/test/java/org/tomitribe/util/SizeUnitTest.java
> >
> > Which commons lib would these go in?  (can send a patch)
> >
>
> Very nice! We would add this to Commons IO. You can contribute via github,
> if you like [1]. There are a few things to take into account imho:
>
> - Differenciate between decimal and binary prefixes, e.g. 1 Megabyte = 1000
> Kilobyte, but 1 Mebibyte = 1024 Kibibyte. Not sure whether this is really
> that important.
> - Petta, Exa, Zetta and Yotta prefixes are missing. At least Petta my
> become important soon.
> - What about translations to bits? For example band width are often
> calculated in Mega Bits/sec
> - What about overflows when translating for example Exabytes to Bytes? The
> result won't fit into a long.
>

We need to use BigInteger for ranges beyond Long.MAX_VALUE.

Gary

>
> I've also put an enum together but without translation logic, because of
> the overflow problem [2]. Maybe the implementations can be merged some how?
>
> Benedikt
>
> [1] https://github.com/apache/commons-io
> [2]
>
> https://issues.apache.org/jira/secure/attachment/12694350/IO-294_FileSizeUnit.patch
>
>
> >
> >
> > -David
> >
> > On Wed, Jun 17, 2015 at 8:50 AM, Gary Gregory <ga...@gmail.com>
> > wrote:
> >
> > > Hi All:
> > >
> > > Java 5 introduced TimeUnit, a very nice enum.
> > >
> > > What do you all think of a ByteSizeUnit enum to handle bit, nibble,
> byte,
> > > kilobyte, kilobit, megabyte and so on?
> > >
> > > Gary
> > >
> > > --
> > > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > > Java Persistence with Hibernate, Second Edition
> > > <http://www.manning.com/bauer3/>
> > > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > > Spring Batch in Action <http://www.manning.com/templier/>
> > > Blog: http://garygregory.wordpress.com
> > > Home: http://garygregory.com/
> > > Tweet! http://twitter.com/GaryGregory
> > >
> >
>
>
>
> --
> http://people.apache.org/~britter/
> http://www.systemoutprintln.de/
> http://twitter.com/BenediktRitter
> http://github.com/britter
>



-- 
E-Mail: garydgregory@gmail.com | ggregory@apache.org
Java Persistence with Hibernate, Second Edition
<http://www.manning.com/bauer3/>
JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
Spring Batch in Action <http://www.manning.com/templier/>
Blog: http://garygregory.wordpress.com
Home: http://garygregory.com/
Tweet! http://twitter.com/GaryGregory

Re: ByteSizeUnit a la TimeUnit

Posted by Benedikt Ritter <br...@apache.org>.
2015-06-17 14:03 GMT+02:00 David Blevins <da...@gmail.com>:

> I'd be happy to donate these if we want them:
>
>
> https://raw.githubusercontent.com/tomitribe/tomitribe-util/master/src/main/java/org/tomitribe/util/SizeUnit.java
>
> https://raw.githubusercontent.com/tomitribe/tomitribe-util/master/src/test/java/org/tomitribe/util/SizeUnitTest.java
>
> Which commons lib would these go in?  (can send a patch)
>

Very nice! We would add this to Commons IO. You can contribute via github,
if you like [1]. There are a few things to take into account imho:

- Differenciate between decimal and binary prefixes, e.g. 1 Megabyte = 1000
Kilobyte, but 1 Mebibyte = 1024 Kibibyte. Not sure whether this is really
that important.
- Petta, Exa, Zetta and Yotta prefixes are missing. At least Petta my
become important soon.
- What about translations to bits? For example band width are often
calculated in Mega Bits/sec
- What about overflows when translating for example Exabytes to Bytes? The
result won't fit into a long.

I've also put an enum together but without translation logic, because of
the overflow problem [2]. Maybe the implementations can be merged some how?

Benedikt

[1] https://github.com/apache/commons-io
[2]
https://issues.apache.org/jira/secure/attachment/12694350/IO-294_FileSizeUnit.patch


>
>
> -David
>
> On Wed, Jun 17, 2015 at 8:50 AM, Gary Gregory <ga...@gmail.com>
> wrote:
>
> > Hi All:
> >
> > Java 5 introduced TimeUnit, a very nice enum.
> >
> > What do you all think of a ByteSizeUnit enum to handle bit, nibble, byte,
> > kilobyte, kilobit, megabyte and so on?
> >
> > Gary
> >
> > --
> > E-Mail: garydgregory@gmail.com | ggregory@apache.org
> > Java Persistence with Hibernate, Second Edition
> > <http://www.manning.com/bauer3/>
> > JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> > Spring Batch in Action <http://www.manning.com/templier/>
> > Blog: http://garygregory.wordpress.com
> > Home: http://garygregory.com/
> > Tweet! http://twitter.com/GaryGregory
> >
>



-- 
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter

Re: ByteSizeUnit a la TimeUnit

Posted by David Blevins <da...@gmail.com>.
I'd be happy to donate these if we want them:

https://raw.githubusercontent.com/tomitribe/tomitribe-util/master/src/main/java/org/tomitribe/util/SizeUnit.java
https://raw.githubusercontent.com/tomitribe/tomitribe-util/master/src/test/java/org/tomitribe/util/SizeUnitTest.java

Which commons lib would these go in?  (can send a patch)


-David

On Wed, Jun 17, 2015 at 8:50 AM, Gary Gregory <ga...@gmail.com>
wrote:

> Hi All:
>
> Java 5 introduced TimeUnit, a very nice enum.
>
> What do you all think of a ByteSizeUnit enum to handle bit, nibble, byte,
> kilobyte, kilobit, megabyte and so on?
>
> Gary
>
> --
> E-Mail: garydgregory@gmail.com | ggregory@apache.org
> Java Persistence with Hibernate, Second Edition
> <http://www.manning.com/bauer3/>
> JUnit in Action, Second Edition <http://www.manning.com/tahchiev/>
> Spring Batch in Action <http://www.manning.com/templier/>
> Blog: http://garygregory.wordpress.com
> Home: http://garygregory.com/
> Tweet! http://twitter.com/GaryGregory
>