Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup MediaType and implement in Core #2790

Merged
merged 31 commits into from Mar 18, 2022
Merged

Cleanup MediaType and implement in Core #2790

merged 31 commits into from Mar 18, 2022

Conversation

nielsm5
Copy link
Sponsor Member

@nielsm5 nielsm5 commented Feb 21, 2022

No description provided.

@nielsm5 nielsm5 linked an issue Feb 24, 2022 that may be closed by this pull request
@nielsm5 nielsm5 marked this pull request as ready for review March 7, 2022 10:55
Co-authored-by: Gerrit van Brakel <g.vanbrakel@flux-it.nl>
* If no charset was provided and the requested charset is <code>auto</auto>, try to parse the charset.
* If unsuccessful return the default; <code>UTF-8</code>.
*/
private String computeCharset(String defaultCharset) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

computeCharset moet volgens mij de volgende precedence hebben:

  1. de charset uit context METADATA_CHARSET
  2. als 'defaultCharset==auto', dan MessageUtils.computeCharset(this)
  3. defaultCharset
  4. StreamUtil.DEFAULT_INPUT_STREAM_ENCODING

Optie 1 zit er nu niet in

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dat zit als het goed is in de MessageUtils

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ik vind het nog steeds heel verwarrend.

  1. dat deze computeCharset een argument mee krijgt dat hij ook zelf op zou kunnen halen
  2. dat hij niet het argument defaultCharset van asReader(defaultCharset) mee krijgt,
  3. maar dat z'n argument wel defaultCharset heet
  4. dat hij maar een deel van de charset berekent, namelijk dat stuk wat er zou zijn als er zonder defaultCharset van asReader(defaultCharset)
  5. dat er in MessageUtils ook nog een computeCharset is die bijna alles doet, maar niet alles.

Ik zou voor willen stellen:

  1. MessageUtils.computeCharset te hernoemen in MessageUtils.computeDecodingCharset
  2. daar de defaultCharset van asReader(defaultCharset) aan mee te geven
  3. de method computeCharset() in Message op te doeken.

* If no charset was provided and the requested charset is <code>auto</auto>, try to parse the charset.
* If unsuccessful return the default; <code>UTF-8</code>.
*/
private String computeCharset(String defaultCharset) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ik vind het nog steeds heel verwarrend.

  1. dat deze computeCharset een argument mee krijgt dat hij ook zelf op zou kunnen halen
  2. dat hij niet het argument defaultCharset van asReader(defaultCharset) mee krijgt,
  3. maar dat z'n argument wel defaultCharset heet
  4. dat hij maar een deel van de charset berekent, namelijk dat stuk wat er zou zijn als er zonder defaultCharset van asReader(defaultCharset)
  5. dat er in MessageUtils ook nog een computeCharset is die bijna alles doet, maar niet alles.

Ik zou voor willen stellen:

  1. MessageUtils.computeCharset te hernoemen in MessageUtils.computeDecodingCharset
  2. daar de defaultCharset van asReader(defaultCharset) aan mee te geven
  3. de method computeCharset() in Message op te doeken.

Comment on lines 949 to 950
Message messageNullCharset = new Message((String) null) { //NullMessage, charset cannot be determined
@Override
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is eigenlijk raar dat je hier een 'String' messag gebruikt. Die zou geen charset moeten hebben, en een empty message ook niet. Je test nu wel iets, maar computeDecodingCharset zou hier ook null op mogen leveren.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Het is raar dat een String message een charset veld heeft.
Hier wordt in puur de 'flow' van charset bepalen getest, en daar moet de 'compute' null teruggeven.

* Only works for binary messages
* @param readLimit amount of bytes to read.
*/
public byte[] getMagic(int readLimit) throws IOException {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wordt deze getMagic nog ergens anders gebruikt dan in MessageUtils? Moet hij niet daar heen dan?

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nee, alleen in de MessageUtils. Hij kan niet verplaatst worden omdat de InputStream gewrapped moet worden wanneer dit geen markSupported stream is.

LOG.info("unable to detect charset for message [{}] closest match [{}] did not meet confidence level [{}/{}]", message, charset, match.getConfidence(), confidence);
return updateMessageCharset(message, null); //return NULL so calling method can fall back to the default charset.
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ik denk dat je hier ook ergens wil regelen dat als er op een repeatable message meerdere malen getReader(auto) gedaan wordt, er dan maar één keer gedetecteerd wordt, ook als dat niet succesvol is.

@gvanbrakel gvanbrakel merged commit 1e90260 into master Mar 18, 2022
@gvanbrakel gvanbrakel deleted the feature/tika branch March 18, 2022 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LocalFileSystemPipe does not recognize charset automatically
2 participants