Java BufferedReader Read loadTemplate(String templateUrl)

Here you can find the source of loadTemplate(String templateUrl)

Description

load Template

License

Open Source License

Declaration

private static String loadTemplate(String templateUrl) throws IOException 

Method Source Code


//package com.java2s;
/*/* ww w.ja v a2 s. com*/
 * Copyright 2014 Amazon.com, Inc. or its affiliates. All Rights Reserved.
 *
 * Licensed under the Amazon Software License (the "License").
 * You may not use this file except in compliance with the License.
 * A copy of the License is located at
 *
 * http://aws.amazon.com/asl/
 *
 * or in the "license" file accompanying this file. This file is distributed
 * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing
 * permissions and limitations under the License.
 */

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    private static String loadTemplate(String templateUrl) throws IOException {
        try (InputStream input = Thread.currentThread().getContextClassLoader().getResourceAsStream(templateUrl)) {
            if (input == null) {
                throw new IOException("Could not find template at location: " + templateUrl);
            }
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(input))) {
                StringBuilder stringBuilder = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                    stringBuilder.append(line).append("\n");
                }
                return stringBuilder.toString();
            }
        }
    }
}

Related

  1. loadStream(InputStream is)
  2. loadStreamContent(InputStream stream)
  3. loadSystemClassPath()
  4. loadTableList(List list, String fileName)
  5. loadTemplate(final String resource)
  6. loadTemplateParametersFile(File f)
  7. loadTestFixture(String path)
  8. loadTestUserEventRelation(String eventFilePath, HashMap> TestUser2EventIndexSetMap)
  9. loadToStringListFromFile(String fullFileName)