forked from yegor256/cactoos
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into padded-text-start
* upstream/master: yegor256#134: UrlAsInput accepts URI and String yegor256#132: InputAsLSInput yegor256#130: fix yegor256#130: reproduced yegor256#128: more ctors yegor256#126: UncheckedText with callback yegor256#126: UncheckedIOException yegor256#126: optimized yegor256#126: UncheckedBytes with fallback
- Loading branch information
Showing
17 changed files
with
1,508 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2017 Yegor Bugayenko | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.cactoos.io; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.Reader; | ||
import java.nio.charset.StandardCharsets; | ||
import org.cactoos.Input; | ||
import org.cactoos.text.BytesAsText; | ||
import org.w3c.dom.ls.LSInput; | ||
|
||
/** | ||
* Input as LSInput. | ||
* | ||
* <p>There is no thread-safety guarantee. | ||
* | ||
* @author Yegor Bugayenko ([email protected]) | ||
* @version $Id$ | ||
* @since 0.6 | ||
* @checkstyle AbbreviationAsWordInNameCheck (10 lines) | ||
*/ | ||
public final class InputAsLSInput implements LSInput { | ||
|
||
/** | ||
* The input. | ||
*/ | ||
private final Input input; | ||
|
||
/** | ||
* Ctor. | ||
* @param inpt Input | ||
*/ | ||
public InputAsLSInput(final Input inpt) { | ||
this.input = inpt; | ||
} | ||
|
||
@Override | ||
public Reader getCharacterStream() { | ||
return new InputStreamReader(this.getByteStream()); | ||
} | ||
|
||
@Override | ||
public void setCharacterStream(final Reader stream) { | ||
// nothing to do | ||
} | ||
|
||
@Override | ||
public InputStream getByteStream() { | ||
try { | ||
return this.input.stream(); | ||
} catch (final IOException ex) { | ||
throw new IllegalStateException(ex); | ||
} | ||
} | ||
|
||
@Override | ||
public void setByteStream(final InputStream stream) { | ||
// nothing to do | ||
} | ||
|
||
@Override | ||
public String getStringData() { | ||
try { | ||
return new BytesAsText(new InputAsBytes(this.input)).asString(); | ||
} catch (final IOException ex) { | ||
throw new IllegalStateException(ex); | ||
} | ||
} | ||
|
||
@Override | ||
public void setStringData(final String data) { | ||
// nothing to do | ||
} | ||
|
||
@Override | ||
public String getSystemId() { | ||
return "#system"; | ||
} | ||
|
||
@Override | ||
public void setSystemId(final String sid) { | ||
// nothing to do | ||
} | ||
|
||
@Override | ||
public String getPublicId() { | ||
return "#public"; | ||
} | ||
|
||
@Override | ||
public void setPublicId(final String pid) { | ||
// nothing to do | ||
} | ||
|
||
@Override | ||
public String getBaseURI() { | ||
return "#base"; | ||
} | ||
|
||
@Override | ||
public void setBaseURI(final String uri) { | ||
// nothing to do | ||
} | ||
|
||
@Override | ||
public String getEncoding() { | ||
return StandardCharsets.UTF_8.displayName(); | ||
} | ||
|
||
@Override | ||
public void setEncoding(final String encoding) { | ||
// nothing to do | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("PMD.BooleanGetMethodName") | ||
public boolean getCertifiedText() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void setCertifiedText(final boolean text) { | ||
// nothing to do | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.