-
Notifications
You must be signed in to change notification settings - Fork 712
Conversation
@garydgregory
garydgregory
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some note. I'll comment in the ticket on a separate issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the Builder pattern to avoid constructor creep. For example org.apache.commons.io.input.BOMInputStream.Builder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What should be the default value of trailerLength? 0 is rather useless, so both arguments have to be provided anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I prefer constructors, especially when as here there's exactly one constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There does not need to be a default if none makes sense, an exception can be thrown at build time or in the private ctor for nonsensical values.
If experience has taught us anything here, it's that there will be constructor creep in the future, so please use a builder.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO builders are vastly overused. They're not native to Java's design, and constructors are more natural. There's a place for builders, but they shouldn't be the default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I prefer constructors, especially when as here there's exactly one constructor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't this subtract the bytes in the trailer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The trailer is filled in the constructor. So every single byte read after the constructor finished causes exactly one byte to return to the caller of the read methods. Think about it as shift register.
2261f2b to
59d74a3
Compare
@sebbASF
sebbASF
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update code with design info
@sebbASF
sebbASF
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reword comment please
garydgregory
commented
Oct 23, 2023
If this class is indeed generally useful, can it be reused from our Tailer classes?
@sebbASF
sebbASF
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see the point of allowing a zero-length trailer
Also, it probably make sense to have an upper limit.
@elharo
elharo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting the trailer before the stream is fully read should probably throw an illegal state exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getTrailer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That seems wonky. I'd almost prefer iot to throw IllegalStateException unitl it has the real trailer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
has to be --> is
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
held back
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO builders are vastly overused. They're not native to Java's design, and constructors are more natural. There's a place for builders, but they shouldn't be the default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copyTrailer --> getTrailer
sebbASF
commented
Oct 23, 2023
Whilst the class seems to work well, I'm not convinced that there is a sufficient need for it.
Every extra class adds to the maintenance load, so there needs to be a demonstrated to make it worth the extra effort.
garydgregory
commented
Oct 24, 2023
Whilst the class seems to work well, I'm not convinced that there is a sufficient need for it.
Every extra class adds to the maintenance load, so there needs to be a demonstrated to make it worth the extra effort.
Right, I agree, and as I mentioned earlier: Could this be reused as is within IO itself (Tailer class) and from Tika which provides a similar class?
Uh oh!
There was an error while loading. Please reload this page.
Add a new TrailerInputStream which holds back the last x bytes of the underlying input stream while reading it.
This is useful, e.g., when a payload is followed by a fixed-length checksum.
https://issues.apache.org/jira/browse/IO-427