当前位置: 首页>>代码示例>>Java>>正文


Java Util类代码示例

本文整理汇总了Java中com.google.gwt.dev.util.Util的典型用法代码示例。如果您正苦于以下问题:Java Util类的具体用法?Java Util怎么用?Java Util使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Util类属于com.google.gwt.dev.util包,在下文中一共展示了Util类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getTemplateContent

import com.google.gwt.dev.util.Util; //导入依赖的package包/类
private String getTemplateContent(ResourceOracle resourceOracle, TreeLogger logger,
    ClassName componentTypeName) throws UnableToCompleteException
{
    String path = slashify(componentTypeName.reflectionName()) + TEMPLATE_EXTENSION;
    Resource resource = resourceOracle.getResource(path);

    // No resource for the template
    if (resource == null)
    {
        logger.log(TreeLogger.ERROR,
            "\nCouldn't find template for component \""
                + componentTypeName.reflectionName()
                + "\". If it doesn't have a template please set hasTemplate to false in the @Component annotation.");
        throw new UnableToCompleteException();
    }

    // Get template content from HTML file
    try
    {
        return Util.readStreamAsString(resource.openContents());
    }
    catch (IOException e)
    {
        logger.log(TreeLogger.ERROR,
            "\nFailed to open template file for component \""
                + componentTypeName.reflectionName());
        throw new UnableToCompleteException();
    }
}
 
开发者ID:Axellience,项目名称:vue-gwt,代码行数:30,代码来源:TemplateGwtGenerator.java

示例2: name

import com.google.gwt.dev.util.Util; //导入依赖的package包/类
private String name(TreeLogger logger, PublicResource r) throws UnableToCompleteException {
  byte[] out;
  try (ByteArrayOutputStream tmp = new ByteArrayOutputStream();
      InputStream in = r.getContents(logger)) {
    final byte[] buf = new byte[2048];
    int n;
    while ((n = in.read(buf)) >= 0) {
      tmp.write(buf, 0, n);
    }
    out = tmp.toByteArray();
  } catch (IOException e) {
    final UnableToCompleteException ute = new UnableToCompleteException();
    ute.initCause(e);
    throw ute;
  }

  String base = r.getPartialPath();
  final int s = base.lastIndexOf('/');
  if (0 < s) {
    base = base.substring(0, s + 1);
  } else {
    base = "";
  }
  return base + Util.computeStrongName(out) + ".cache.css";
}
 
开发者ID:gerrit-review,项目名称:gerrit,代码行数:26,代码来源:CssLinker.java

示例3: getW3cDoc

import com.google.gwt.dev.util.Util; //导入依赖的package包/类
private Document getW3cDoc(MortalLogger logger, DesignTimeUtils designTime,
    ResourceOracle resourceOracle, String templatePath, Resource resource)
    throws UnableToCompleteException {

  Document doc = null;
  try {
    String content = designTime.getTemplateContent(templatePath);
    if (content == null) {
      content = Util.readStreamAsString(resource.openContents());
    }
    doc = new W3cDomHelper(logger.getTreeLogger(), resourceOracle).documentFor(
        content, resource.getPath());
  } catch (IOException iex) {
    logger.die("Error opening resource:" + resource.getLocation(), iex);
  } catch (SAXParseException e) {
    logger.die(
        "Error parsing XML (line " + e.getLineNumber() + "): "
            + e.getMessage(), e);
  }
  return doc;
}
 
开发者ID:ahome-it,项目名称:ahome-core,代码行数:22,代码来源:UiBinderGenerator.java

示例4: create

import com.google.gwt.dev.util.Util; //导入依赖的package包/类
/**
 * Creates an app directory, doing any cleanup needed.
 * @param dir the directory to use. It need not exist, but
 * the parent dir should exist.
 */
static AppSpace create(File dir, String module) throws IOException {
  if (!dir.exists() && !dir.mkdir()) {
    throw new IOException("can't create app directory: " + dir);
  }

  // clean up existing subdirectories
  for (File candidate : dir.listFiles()) {
    if (candidate.getName().startsWith(module)) {
      System.err.println("deleting: " + candidate);
      Util.recursiveDelete(candidate, false);
    }
  }

  return new AppSpace(dir, module);
}
 
开发者ID:WeTheInternet,项目名称:xapi,代码行数:21,代码来源:AppSpace.java

示例5: renderToTempPngFile

import com.google.gwt.dev.util.Util; //导入依赖的package包/类
/**
 * 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();
  }
}
 
开发者ID:kDCYorke,项目名称:RetinaImages,代码行数:22,代码来源:RetinaImageResourceGenerator.java

示例6: reencodeToTempFile

import com.google.gwt.dev.util.Util; //导入依赖的package包/类
/**
 * 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();
  }
}
 
开发者ID:kDCYorke,项目名称:RetinaImages,代码行数:22,代码来源:RetinaImageResourceGenerator.java

示例7: getFile

import com.google.gwt.dev.util.Util; //导入依赖的package包/类
@Override
public String getFile(String name)
{
    Resource resource = resourceOracle.getResource(getPath() + "/" + name);
    if (resource == null)
        return null;

    return Util.readURLAsString(resource.getURL());
}
 
开发者ID:Axellience,项目名称:vue-gwt,代码行数:10,代码来源:GwtResourceFolder.java

示例8: createAssignment

import com.google.gwt.dev.util.Util; //导入依赖的package包/类
@Override
public String createAssignment(TreeLogger logger, ResourceContext context, JMethod method) throws UnableToCompleteException {
	URL[] resources = ResourceGeneratorUtil.findResources(logger, context, method);

	if (resources.length != 1) {
		logger.log(TreeLogger.ERROR, "Exactly one resource must be specified", null);
		throw new UnableToCompleteException();
	}

	URL resource = resources[0];
	String processedMarkdown = null;
	try {
		processedMarkdown = new MarkdownProcessor().process(Util.readURLAsString(resource));
	} catch (Exception e) {
		logger.log(TreeLogger.ERROR, "Error processing markdown", e);
		throw new UnableToCompleteException();
	}

	SourceWriter sw = new StringSourceWriter();
	// Convenience when examining the generated code.
	if (!AbstractResourceGenerator.STRIP_COMMENTS) {
		sw.println("// " + resource.toExternalForm());
	}
	sw.println("new " + Markdown.class.getCanonicalName() + "() {");
	sw.indent();
	sw.println("public String asString() { return \"" + processedMarkdown.replace("\"", "\\\"").replace("\n", "\\n\"\n + \"") + "\"; }");
	sw.println("public String getName() { return \"" + method.getName() + "\"; }");
	sw.outdent();
	sw.println("}");

	return sw.toString();
}
 
开发者ID:billy1380,项目名称:markdown4j-gwt,代码行数:33,代码来源:MarkdownResourceGenerator.java

示例9: create

import com.google.gwt.dev.util.Util; //导入依赖的package包/类
private RebindResult create(TreeLogger logger,
                            GeneratorContext context,
                            JClassType toGenerate)
    throws UnableToCompleteException {

  Date start = new Date();

  String packageName = toGenerate.getPackage()
                                 .getName();
  String simpleSourceName = toGenerate.getName()
                                      .replace('.',
                                               '_') + "Impl";

  SourceWriter sw = getSourceWriter(logger,
                                    context,
                                    toGenerate,
                                    packageName,
                                    simpleSourceName);
  if (sw == null) {
    return new RebindResult(RebindMode.USE_EXISTING,
                            packageName + "." + simpleSourceName);
  }

  String template;
  for (JMethod method : toGenerate.getMethods()) {
    TreeLogger branchLogger = logger.branch(TreeLogger.Type.DEBUG,
                                 "Creating Template method " + method.getName());

    Gwt4eTemplates.Template templateSource = method.getAnnotation(Gwt4eTemplates.Template.class);
    if (templateSource == null) {
      branchLogger.log(TreeLogger.Type.ERROR,
                 "Unable to create templateSource for method " + method.getReadableDeclaration()
                 + ", this may cause other problems.");
      continue;
    } else {
      if (templateSource.source()
                        .length() != 0) {
        if (templateSource.value()
                          .length() != 0) {
          branchLogger.log(TreeLogger.Type.WARN,
                     "Found both source file and inline templateSource, using source file");
        }

        InputStream stream = getTemplateAsStream(context,
                                                 toGenerate,
                                                 logger,
                                                 templateSource.source());
        if (stream == null) {
          branchLogger.log(TreeLogger.Type.ERROR,
                     "No data could be loaded - no data at path " + templateSource.source());
          throw new UnableToCompleteException();
        }
        template = Util.readStreamAsString(stream);
      } else if (templateSource.value()
                               .length() != 0) {
        template = templateSource.value();
      } else {
        branchLogger.log(TreeLogger.Type.ERROR,
                   "Template annotation found with no contents, cannot generate method " + method.getName()
                   + ", this may cause other problems.");
        continue;
      }
    }

    generateFile(sw,
                 method,
                 template);
  }

  sw.commit(logger);

  Date end = new Date();

  logger.log(TreeLogger.INFO,
             "Generation completed: " + (end.getTime() - start.getTime()) + "ms.");

  return new RebindResult(RebindMode.USE_ALL_NEW_WITH_NO_CACHING,
                          packageName + "." + simpleSourceName);
}
 
开发者ID:gwt4e,项目名称:gwt4e,代码行数:80,代码来源:TemplateGenerator.java

示例10: key

import com.google.gwt.dev.util.Util; //导入依赖的package包/类
private static String key(ImageResourceDeclaration image, URL url) {
  return Util.computeStrongName(Util.readURLAsBytes(url)) + ":"
      + image.getScaleHeight() + ":" + image.getScaleWidth();
}
 
开发者ID:kDCYorke,项目名称:RetinaImages,代码行数:5,代码来源:RetinaImageResourceGenerator.java

示例11: computeDefaultPrefix

import com.google.gwt.dev.util.Util; //导入依赖的package包/类
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) + "-";
}
 
开发者ID:jDramaix,项目名称:gss.gwt,代码行数:14,代码来源:GssResourceGenerator.java


注:本文中的com.google.gwt.dev.util.Util类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。