本文整理了Java中com.google.gwt.dev.util.Util
类的一些代码示例,展示了Util
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util
类的具体详情如下:
包路径:com.google.gwt.dev.util.Util
类名称:Util
暂无
代码示例来源:origin: com.google.gwt/gwt-servlet
@Override
public void prepare(TreeLogger logger, ResourceContext context,
ClientBundleRequirements requirements, JMethod method)
throws UnableToCompleteException {
URL[] urls = ResourceGeneratorUtil.findResources(logger, context, method);
if (urls.length != 1) {
logger.log(TreeLogger.ERROR, "Exactly one resource must be specified",
null);
throw new UnableToCompleteException();
}
URL resource = urls[0];
String toWrite = Util.readURLAsString(resource);
// This de-duplicates strings in the bundle.
if (!hashes.containsKey(toWrite)) {
hashes.put(toWrite, currentIndex++);
if (!first) {
data.append(",\n");
} else {
first = false;
}
data.append('"');
data.append(Generator.escape(toWrite));
data.append('"');
}
// Store the (possibly n:1) mapping of resource function to bundle index.
offsets.put(method.getName(), hashes.get(toWrite));
}
代码示例来源:origin: com.google.gwt/gwt-servlet
private String getMd5HashOfData() {
return Util.computeStrongName(Util.getBytes(data.toString()));
}
代码示例来源:origin: com.google.gwt/gwt-servlet
public Void call() throws Exception {
if (mode.isEmitClasses()) {
String fileName = state.type.getInternalName();
if (fileName == null) {
System.err.println("Got null filename from " + state.type);
return null;
}
fileName += ".class";
emitter.emit(fileName, state.contents);
}
if (mode.isEmitSource()) {
String sourcePath = getPackagePath(state.originalType) + state.source;
String destPath = getPackagePath(state.type) + state.source;
if (sources.add(sourcePath) && loader.exists(sourcePath)) {
String contents = Util.readStreamAsString(loader.getResourceAsStream(sourcePath));
emitter.emit(destPath, new ByteArrayInputStream(Util.getBytes(contents)));
}
}
return null;
}
}
代码示例来源:origin: com.google.gwt/gwt-servlet
private static String key(ImageResourceDeclaration image, URL url) {
return Util.computeStrongName(Util.readURLAsBytes(url)) + ":"
+ image.getScaleHeight() + ":" + image.getScaleWidth();
}
代码示例来源:origin: net.wetheinter/gwt-user
byte[] data = Util.readURLAsBytes(url);
Utility.writeTemplateBinaryFile(file, data);
} else {
String data = Util.readURLAsString(url);
Utility.writeTemplateFile(file, data, replacements);
代码示例来源:origin: net.wetheinter/gwt-user
boolean forceExternal) throws UnableToCompleteException {
String strongName = Util.computeStrongName(data);
String toReturn = strongNameToExpressions.get(strongName);
if (toReturn != null) {
代码示例来源:origin: com.vaadin.external.gwt/gwt-user
public static void main(String[] args) throws Exception {
String filename = args[0];
int line = Integer.valueOf(args[1]);
int col = Integer.valueOf(args[2]);
SourceMapping consumer = SourceMapConsumerFactory.parse(Util.readFileAsString(new File(filename)));
System.out.println(consumer.getMappingForLine(line, col));
}
}
代码示例来源:origin: com.google.gwt/gwt-servlet
private String computeDefaultPrefix(ResourceContext context) {
SortedSet<JClassType> gssResources = computeOperableTypes(context);
Adler32 checksum = new Adler32();
for (JClassType type : gssResources) {
checksum.update(Util.getBytes(type.getQualifiedSourceName()));
}
int seed = Math.abs((int) checksum.getValue());
return encode(seed) + "-";
}
代码示例来源:origin: com.vaadin.external.gwt/gwt-user
@Override
public InputSource resolveEntity(String publicId, String systemId) {
String matchingPrefix = findMatchingPrefix(systemId);
Resource resource = null;
if (matchingPrefix != null) {
resource =
resourceOracle.getResource(RESOURCES + systemId.substring(matchingPrefix.length()));
}
if (resource == null) {
resource = resourceOracle.getResource(pathBase + systemId);
}
if (resource != null) {
String content;
try {
InputStream resourceStream = resource.openContents();
content = Util.readStreamAsString(resourceStream);
} catch (IOException ex) {
logger.log(TreeLogger.ERROR, "Error reading resource: " + resource.getLocation());
throw new RuntimeException(ex);
}
InputSource inputSource = new InputSource(new StringReader(content));
inputSource.setPublicId(publicId);
inputSource.setSystemId(resource.getPath());
return inputSource;
}
/*
* Let Sax find it on the interweb.
*/
return null;
}
代码示例来源:origin: com.google.gwt/gwt-servlet
/**
* Re-encode an image as a PNG to strip random header data.
*/
private URL reencodeToTempFile(TreeLogger logger, ImageRect rect)
throws UnableToCompleteException {
try {
byte[] imageBytes = ImageBundleBuilder.toPng(logger, rect);
if (imageBytes == null) {
return null;
}
File file = File.createTempFile(ImageResourceGenerator.class.getSimpleName(), ".png");
file.deleteOnExit();
Util.writeBytesToFile(logger, file, imageBytes);
return file.toURI().toURL();
} catch (IOException ex) {
logger.log(TreeLogger.ERROR, "Unable to write re-encoded PNG", ex);
throw new UnableToCompleteException();
}
}
代码示例来源:origin: net.wetheinter/gwt-user
public String deploy(URL resource, String mimeType, boolean forceExternal)
throws UnableToCompleteException {
String fileName = ResourceGeneratorUtil.baseName(resource);
byte[] bytes = Util.readURLAsBytes(resource);
try {
String finalMimeType = (mimeType != null)
? mimeType : resource.openConnection().getContentType();
return deploy(fileName, finalMimeType, bytes, forceExternal);
} catch (IOException e) {
getLogger().log(TreeLogger.ERROR,
"Unable to determine mime type of resource", e);
throw new UnableToCompleteException();
}
}
代码示例来源:origin: com.vaadin.external.gwt/gwt-user
byte[] data = Util.readURLAsBytes(url);
Utility.writeTemplateBinaryFile(file, data);
} else {
String data = Util.readURLAsString(url);
Utility.writeTemplateFile(file, data, replacements);
代码示例来源:origin: com.vaadin.external.gwt/gwt-user
boolean forceExternal) throws UnableToCompleteException {
String strongName = Util.computeStrongName(data);
String toReturn = strongNameToExpressions.get(strongName);
if (toReturn != null) {
代码示例来源:origin: net.wetheinter/gwt-user
public static void main(String[] args) throws Exception {
String filename = args[0];
int line = Integer.valueOf(args[1]);
int col = Integer.valueOf(args[2]);
SourceMapping consumer = SourceMapConsumerFactory.parse(Util.readFileAsString(new File(filename)));
System.out.println(consumer.getMappingForLine(line, col));
}
}
代码示例来源:origin: net.wetheinter/gwt-user
private static String key(ImageResourceDeclaration image, URL url) {
return Util.computeStrongName(Util.readURLAsBytes(url)) + ":"
+ image.getScaleHeight() + ":" + image.getScaleWidth();
}
代码示例来源:origin: com.google.gwt/gwt-servlet
checksum.update(Util.getBytes(type.getQualifiedSourceName()));
代码示例来源:origin: net.wetheinter/gwt-user
@Override
public InputSource resolveEntity(String publicId, String systemId) {
String matchingPrefix = findMatchingPrefix(systemId);
Resource resource = null;
if (matchingPrefix != null) {
resource =
resourceOracle.getResource(RESOURCES + systemId.substring(matchingPrefix.length()));
}
if (resource == null) {
resource = resourceOracle.getResource(pathBase + systemId);
}
if (resource != null) {
String content;
try {
InputStream resourceStream = resource.openContents();
content = Util.readStreamAsString(resourceStream);
} catch (IOException ex) {
logger.log(TreeLogger.ERROR, "Error reading resource: " + resource.getLocation());
throw new RuntimeException(ex);
}
InputSource inputSource = new InputSource(new StringReader(content));
inputSource.setPublicId(publicId);
inputSource.setSystemId(resource.getPath());
return inputSource;
}
/*
* Let Sax find it on the interweb.
*/
return null;
}
代码示例来源:origin: com.google.gwt/gwt-servlet
/**
* Re-encode an image as a PNG to strip random header data.
*/
private static URL renderToTempPngFile(TreeLogger logger,
ImageBundleBuilder builder, Arranger arranger)
throws UnableToCompleteException {
try {
byte[] imageBytes = builder.render(logger, arranger);
if (imageBytes == null) {
return null;
}
File file = File.createTempFile(ImageResourceGenerator.class.getSimpleName(), ".png");
file.deleteOnExit();
Util.writeBytesToFile(logger, file, imageBytes);
return file.toURI().toURL();
} catch (IOException ex) {
logger.log(TreeLogger.ERROR, "Unable to write re-encoded PNG", ex);
throw new UnableToCompleteException();
}
}
代码示例来源:origin: com.vaadin.external.gwt/gwt-user
public String deploy(URL resource, String mimeType, boolean forceExternal)
throws UnableToCompleteException {
String fileName = ResourceGeneratorUtil.baseName(resource);
byte[] bytes = Util.readURLAsBytes(resource);
try {
String finalMimeType = (mimeType != null)
? mimeType : resource.openConnection().getContentType();
return deploy(fileName, finalMimeType, bytes, forceExternal);
} catch (IOException e) {
getLogger().log(TreeLogger.ERROR,
"Unable to determine mime type of resource", e);
throw new UnableToCompleteException();
}
}
代码示例来源:origin: com.google.gwt/gwt-servlet
sw.indent();
String toWrite = Util.readURLAsString(resource);
内容来源于网络,如有侵权,请联系作者删除!