
io.lightlink.utils.Utils Maven / Gradle / Ivy
package io.lightlink.utils;
/*
* #%L
* lightlink-core
* %%
* Copyright (C) 2015 Vitaliy Shevchuk
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Lesser Public License for more details.
*
* You should have received a copy of the GNU General Lesser Public
* License along with this program. If not, see
* .
* #L%
*/
import io.lightlink.config.ConfigManager;
import jdk.nashorn.api.scripting.ScriptObjectMirror;
import jdk.nashorn.internal.runtime.ScriptObject;
import javax.servlet.ServletContext;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
public class Utils {
public static boolean isBlank(CharSequence cs) {
int strLen;
if (cs == null || (strLen = cs.length()) == 0) {
return true;
}
for (int i = 0; i < strLen; i++) {
if (!Character.isWhitespace(cs.charAt(i))) {
return false;
}
}
return true;
}
public static String streamToString(InputStream is) throws IOException {
StringBuilder sb = new StringBuilder();
byte[] buffer = new byte[4096];
int n = 0;
while (-1 != (n = is.read(buffer))) {
sb.append(new String(buffer, 0, n));
}
return sb.toString();
}
public static String getResourceContent(String resource) throws IOException {
InputStream fnStream;
if ((ConfigManager.isInDebugMode())) {
// without cache
fnStream = Thread.currentThread().getContextClassLoader().getResource(resource).openStream();
} else {
fnStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
}
String assertFns = streamToString(fnStream);
fnStream.close();
return assertFns;
}
public static Object tryConvertToJavaCollections(Object value) {
if (value instanceof Object[]) {
value = Arrays.asList((Object[]) value);
} else if (value instanceof int[]) {
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy