Java Code Examples for org.springframework.core.io.support.EncodedResource#getReader()
The following examples show how to use
org.springframework.core.io.support.EncodedResource#getReader() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EncodedFileSystemResourceDemo.java From geekbang-lessons with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException { String currentJavaFilePath = System.getProperty("user.dir") + "/thinking-in-spring/resource/src/main/java/org/geekbang/thinking/in/spring/resource/EncodedFileSystemResourceDemo.java"; File currentJavaFile = new File(currentJavaFilePath); // FileSystemResource => WritableResource => Resource FileSystemResource fileSystemResource = new FileSystemResource(currentJavaFilePath); EncodedResource encodedResource = new EncodedResource(fileSystemResource, "UTF-8"); // 字符输入流 // 字符输入流 try (Reader reader = encodedResource.getReader()) { System.out.println(IOUtils.toString(reader)); } }
Example 2
Source File: ResourceUtils.java From geekbang-lessons with Apache License 2.0 | 5 votes |
static String getContent(Resource resource, String encoding) throws IOException { EncodedResource encodedResource = new EncodedResource(resource, encoding); // 字符输入流 try (Reader reader = encodedResource.getReader()) { return IOUtils.toString(reader); } }
Example 3
Source File: EncodedFileSystemResourceLoaderDemo.java From geekbang-lessons with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws IOException { String currentJavaFilePath = "/" + System.getProperty("user.dir") + "/thinking-in-spring/resource/src/main/java/org/geekbang/thinking/in/spring/resource/EncodedFileSystemResourceLoaderDemo.java"; // 新建一个 FileSystemResourceLoader 对象 FileSystemResourceLoader resourceLoader = new FileSystemResourceLoader(); // FileSystemResource => WritableResource => Resource Resource resource = resourceLoader.getResource(currentJavaFilePath); EncodedResource encodedResource = new EncodedResource(resource, "UTF-8"); // 字符输入流 try (Reader reader = encodedResource.getReader()) { System.out.println(IOUtils.toString(reader)); } }
Example 4
Source File: DBScriptUtil.java From alfresco-repository with GNU Lesser General Public License v3.0 | 5 votes |
/** * Read a script from the provided EncodedResource, using the supplied line * comment prefix, and build a String containing the lines. * * @param resource * the resource (potentially associated with a specific encoding) to * load the SQL script from * @param lineCommentPrefix * the prefix that identifies comments in the SQL script (typically * "--") * @return a String containing the script lines */ private static String readScript(EncodedResource resource, String lineCommentPrefix) throws IOException { LineNumberReader lineNumberReader = new LineNumberReader(resource.getReader()); try { return readScript(lineNumberReader, lineCommentPrefix); } finally { lineNumberReader.close(); } }
Example 5
Source File: ScriptUtils.java From spring-analysis-note with MIT License | 3 votes |
/** * Read a script from the provided resource, using the supplied comment prefix * and statement separator, and build a {@code String} containing the lines. * <p>Lines <em>beginning</em> with the comment prefix are excluded from the * results; however, line comments anywhere else — for example, within * a statement — will be included in the results. * @param resource the {@code EncodedResource} containing the script * to be processed * @param commentPrefix the prefix that identifies comments in the SQL script * (typically "--") * @param separator the statement separator in the SQL script (typically ";") * @param blockCommentEndDelimiter the <em>end</em> block comment delimiter * @return a {@code String} containing the script lines * @throws IOException in case of I/O errors */ private static String readScript(EncodedResource resource, @Nullable String commentPrefix, @Nullable String separator, @Nullable String blockCommentEndDelimiter) throws IOException { LineNumberReader lnr = new LineNumberReader(resource.getReader()); try { return readScript(lnr, commentPrefix, separator, blockCommentEndDelimiter); } finally { lnr.close(); } }
Example 6
Source File: ScriptUtils.java From java-technology-stack with MIT License | 3 votes |
/** * Read a script from the provided resource, using the supplied comment prefix * and statement separator, and build a {@code String} containing the lines. * <p>Lines <em>beginning</em> with the comment prefix are excluded from the * results; however, line comments anywhere else — for example, within * a statement — will be included in the results. * @param resource the {@code EncodedResource} containing the script * to be processed * @param commentPrefix the prefix that identifies comments in the SQL script * (typically "--") * @param separator the statement separator in the SQL script (typically ";") * @param blockCommentEndDelimiter the <em>end</em> block comment delimiter * @return a {@code String} containing the script lines * @throws IOException in case of I/O errors */ private static String readScript(EncodedResource resource, @Nullable String commentPrefix, @Nullable String separator, @Nullable String blockCommentEndDelimiter) throws IOException { LineNumberReader lnr = new LineNumberReader(resource.getReader()); try { return readScript(lnr, commentPrefix, separator, blockCommentEndDelimiter); } finally { lnr.close(); } }
Example 7
Source File: ScriptUtils.java From lams with GNU General Public License v2.0 | 3 votes |
/** * Read a script from the provided resource, using the supplied comment prefix * and statement separator, and build a {@code String} containing the lines. * <p>Lines <em>beginning</em> with the comment prefix are excluded from the * results; however, line comments anywhere else — for example, within * a statement — will be included in the results. * @param resource the {@code EncodedResource} containing the script * to be processed * @param commentPrefix the prefix that identifies comments in the SQL script — * typically "--" * @param separator the statement separator in the SQL script — typically ";" * @return a {@code String} containing the script lines * @throws IOException in case of I/O errors */ private static String readScript(EncodedResource resource, String commentPrefix, String separator) throws IOException { LineNumberReader lnr = new LineNumberReader(resource.getReader()); try { return readScript(lnr, commentPrefix, separator); } finally { lnr.close(); } }
Example 8
Source File: ScriptUtils.java From multitenant with Apache License 2.0 | 3 votes |
/** * Read a script from the provided resource, using the supplied comment prefix * and statement separator, and build a {@code String} containing the lines. * <p>Lines <em>beginning</em> with the comment prefix are excluded from the * results; however, line comments anywhere else — for example, within * a statement — will be included in the results. * @param resource the {@code EncodedResource} containing the script * to be processed * @param commentPrefix the prefix that identifies comments in the SQL script — * typically "--" * @param separator the statement separator in the SQL script — typically ";" * @return a {@code String} containing the script lines * @throws IOException in case of I/O errors */ private static String readScript(EncodedResource resource, String commentPrefix, String separator) throws IOException { LineNumberReader lnr = new LineNumberReader(resource.getReader()); try { return readScript(lnr, commentPrefix, separator); } finally { lnr.close(); } }
Example 9
Source File: ScriptUtils.java From spring4-understanding with Apache License 2.0 | 3 votes |
/** * Read a script from the provided resource, using the supplied comment prefix * and statement separator, and build a {@code String} containing the lines. * <p>Lines <em>beginning</em> with the comment prefix are excluded from the * results; however, line comments anywhere else — for example, within * a statement — will be included in the results. * @param resource the {@code EncodedResource} containing the script * to be processed * @param commentPrefix the prefix that identifies comments in the SQL script — * typically "--" * @param separator the statement separator in the SQL script — typically ";" * @return a {@code String} containing the script lines * @throws IOException in case of I/O errors */ private static String readScript(EncodedResource resource, String commentPrefix, String separator) throws IOException { LineNumberReader lnr = new LineNumberReader(resource.getReader()); try { return readScript(lnr, commentPrefix, separator); } finally { lnr.close(); } }
Example 10
Source File: ScriptUtils.java From effectivejava with Apache License 2.0 | 3 votes |
/** * Read a script from the provided resource, using the supplied comment prefix * and statement separator, and build a {@code String} containing the lines. * <p>Lines <em>beginning</em> with the comment prefix are excluded from the * results; however, line comments anywhere else — for example, within * a statement — will be included in the results. * @param resource the {@code EncodedResource} containing the script * to be processed * @param commentPrefix the prefix that identifies comments in the SQL script — * typically "--" * @param separator the statement separator in the SQL script — typically ";" * @return a {@code String} containing the script lines * @throws IOException in case of I/O errors */ private static String readScript(EncodedResource resource, String commentPrefix, String separator) throws IOException { LineNumberReader lnr = new LineNumberReader(resource.getReader()); try { return readScript(lnr, commentPrefix, separator); } finally { lnr.close(); } }