本文整理汇总了Java中com.google.common.io.CharSource.wrap方法的典型用法代码示例。如果您正苦于以下问题:Java CharSource.wrap方法的具体用法?Java CharSource.wrap怎么用?Java CharSource.wrap使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.common.io.CharSource
的用法示例。
在下文中一共展示了CharSource.wrap方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import com.google.common.io.CharSource; //导入方法依赖的package包/类
public LocalDate get() {
LocalDate res = null;
try {
CharSource charSource = CharSource.wrap(text);
String line = charSource.readFirstLine();
line = Strings.nullToEmpty(line);
Matcher matcher = REGEX.matcher(line);
if (matcher.find()) {
String data = matcher.group(0);
res = new LocalDateCsvConverter("dd/MM/yyyy").convert(data);
}
} catch (IOException e) {
}
return res;
}
示例2: computeNext
import com.google.common.io.CharSource; //导入方法依赖的package包/类
@Override
protected CharSource computeNext() {
try {
final String firstLine = reader.readLine();
// no more data - we're done
if (firstLine == null) {
return endOfData();
}
// the reader should always be starting with the split string
// note this means the file being split must begin with the split string
if (!firstLine.startsWith(splitString)) {
throw new ConcatenatedXMLException(
new IOException("Block does not start with split string " + splitString));
}
final StringBuilder data = new StringBuilder();
String line;
// we always mark our position before beginning a new line
// so that if we find the beginning of the next block, we can back up
reader.mark(maxDocBytes);
while ((line = reader.readLine()) != null) {
// beginning of next block. Back up and return what we've accumulated
if (line.startsWith(splitString)) {
reader.reset();
break;
} else {
// not done yet
data.append(line).append("\n");
reader.mark(maxDocBytes);
}
}
return CharSource.wrap(data.toString());
} catch (IOException ioe) {
throw new ConcatenatedXMLException(ioe);
}
}
示例3: ofContent
import com.google.common.io.CharSource; //导入方法依赖的package包/类
/**
* Obtains an instance of {@link CharSource} from a text variable, specified as a {@link String} object.
*
* @param content the text to create a {@link CharSource} for
* @return a new instance of {@link CharSource} with UTF-8 for charset
*/
public static CharSource ofContent(String content) {
return CharSource.wrap(content);
}
示例4: asCharSourceUtf8UsingBom
import com.google.common.io.CharSource; //导入方法依赖的package包/类
/**
* Returns a {@code CharSource} for the same bytes, converted to UTF-8 using a Byte-Order Mark if available.
*
* @return the equivalent {@code CharSource}
*/
public CharSource asCharSourceUtf8UsingBom() {
return CharSource.wrap(readUtf8UsingBom());
}
示例5: prettifyXml
import com.google.common.io.CharSource; //导入方法依赖的package包/类
/**
* Prettifies given XML String.
*
* @param xml input XML
* @return prettified input or input itself is input is not well-formed
*/
public static CharSequence prettifyXml(CharSequence xml) {
return new XmlString(CharSource.wrap(xml));
}