Example #1
0
 public void init() throws Exception {
   SocialAuthConfig config = new SocialAuthConfig();
   File devConfig = Files.findFile("oauth_consumer.properties_dev"); // 开发期所使用的配置文件
   if (devConfig == null) devConfig = Files.findFile("oauth_consumer.properties"); // 真实环境所使用的配置文件
   if (devConfig == null) config.load(new NullInputStream());
   else config.load(new FileInputStream(devConfig));
   this.config = config;
 }
Example #2
0
 public static void main(String[] args) {
   for (File f : new File("C:\\Users\\wendal\\workspace\\git\\github\\nutzmore").listFiles()) {
     if (!f.getName().startsWith("nutz-")) continue;
     // System.out.println(f);
     File readme = new File(f, "README.md");
     if (!readme.exists()) {
       System.out.println("miss README.md " + f);
       StringBuilder sb = new StringBuilder();
       sb.append("" + f.getName()).append("\r\n");
       sb.append("==================================\r\n\r\n");
       sb.append("简介(可用性:开发中)\r\n");
       sb.append("==================================\r\n\r\n");
       sb.append("待编写");
       Files.write(readme, sb);
     }
     boolean flag = true;
     List<String> lines = Files.readLines(readme);
     for (int i = 0; i < lines.size(); i++) {
       String line = lines.get(i);
       if (line.startsWith("简介(可用性:")) {
         String avi = line.substring("简介(可用性:".length(), line.length() - 1);
         if (avi.equals("生产")) avi = "**" + avi + "**";
         // System.out.println(lines.get(i+3));
         String shortt = lines.get(i + 3);
         String maven =
             "![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.nutz/"
                 + f.getName()
                 + "/badge.svg)";
         String link =
             "["
                 + f.getName()
                 + "](https://github.com/nutzam/nutzmore/tree/master/"
                 + f.getName()
                 + ")";
         System.out.printf("| %s | %s | %s | %s |\r\n", link, maven, shortt, avi);
         flag = false;
         break;
       }
     }
     if (flag) {
       StringBuilder sb = new StringBuilder();
       sb.append("简介(可用性:开发中)\r\n");
       sb.append("==================================\r\n\r\n");
       sb.append("待编写");
       lines.add(3, sb.toString());
       Files.write(readme, Strings.join("\r\n", lines.toArray()));
     }
   }
 }
 /** 输出Sitemap */
 @At
 @Ok("raw:xml")
 public File sitemap() throws MalformedURLException, ParseException {
   String tmpdir = conf.get("website.tmp_dir", "/tmp");
   Files.createDirIfNoExists(tmpdir);
   final WebSitemapGenerator gen = new WebSitemapGenerator(urlbase, new File(tmpdir));
   gen.addUrl(urlbase + "/yvr/list");
   dao.each(
       Topic.class,
       Cnd.orderBy().desc("createTime"),
       dao.createPager(1, 1000),
       new Each<Topic>() {
         public void invoke(int index, Topic topic, int length) {
           try {
             Options options = new Options(urlbase + "/yvr/t/" + topic.getId());
             // TODO 从redis读取最后更新时间
             // options.lastMod(topic.getCreateAt());
             WebSitemapUrl url = new WebSitemapUrl(options);
             gen.addUrl(url);
           } catch (Exception e) {
             e.printStackTrace();
           }
         }
       });
   List<File> list = gen.write();
   if (list.size() > 0) return list.get(0);
   return null;
 }
Example #4
0
  @SuppressWarnings({"unchecked"})
  public void init() throws FileNotFoundException {

    File config = Files.findFile("auth.json");
    if (null == config) {
      log.error("Can not find path:[classpath:auth.json]");
      throw new FileNotFoundException("[classpath:auth.json]");
    }

    FileReader reader = new FileReader(config);
    authMap = new LinkedHashMap<String, Integer>();
    authMap = Json.fromJson(authMap.getClass(), reader);
    log.info("Get url mapping:[" + authMap + "]");
    patternMap = new LinkedHashMap<String, Pattern>();
    if (!authMap.isEmpty()) {
      for (String url : authMap.keySet()) {
        patternMap.put(url, Pattern.compile(url));
      }
    }

    excludePaths = new HashSet<String>();
    Collections.addAll(
        excludePaths, PropertiesReader.getProperties("doe.url.pass").trim().split(","));
    //          System.out.println(Json.toJson(excludePaths));
  }
Example #5
0
 public NutMap upload(TempFile tmp, int userId) throws IOException {
   NutMap re = new NutMap();
   if (userId < 1) return re.setv("msg", "请先登陆!");
   if (tmp == null || tmp.getSize() == 0) {
     return re.setv("msg", "空文件");
   }
   if (tmp.getSize() > 10 * 1024 * 1024) {
     tmp.delete();
     return re.setv("msg", "文件太大了");
   }
   String id = R.UU32();
   String path = "/" + id.substring(0, 2) + "/" + id.substring(2);
   File f = new File(imageDir + path);
   Files.createNewFile(f);
   Files.write(f, tmp.getInputStream());
   tmp.delete();
   re.put("url", Mvcs.getServletContext().getContextPath() + "/yvr/upload" + path);
   re.setv("success", true);
   return re;
 }
Example #6
0
  // for issue 278
  @Test
  public void test_clob() throws IOException, SQLException {
    dao.create(BinObject.class, true);
    BinObject bin = new BinObject();
    File f = File.createTempFile("clob", "data");
    Files.write(f, "中文");
    bin.setMyClob(new SimpleClob(f));
    dao.insert(bin);

    bin = dao.fetch(BinObject.class);
    String str = Lang.readAll(bin.getMyClob().getCharacterStream());
    assertEquals("中文", str);
  }
Example #7
0
 public static void main(String[] args) {
   String path = Take.class.getResource("/").getPath();
   String proFile = path + "file.json";
   final List<String> urls = new ArrayList<String>();
   Files.readLine(
       Files.findFile(proFile),
       new Callback<String>() {
         @Override
         public void invoke(String str) {
           urls.add(str);
         }
       });
   for (String url : urls) {
     if (StringUtils.isBlank(url)) {
       continue;
     }
     Response req = Http.get(url);
     String savePath = path + "/temp/" + StringUtils.substringAfterLast(url, "/");
     savePath = StringUtils.substringBefore(savePath, "?");
     Files.write(savePath, req.getStream());
     System.out.println("save Path:" + savePath);
   }
 }
Example #8
0
 public static void loadProperties(String fileName) {
   InputStream is = null;
   try {
     pp = new Properties();
     File f = Files.findFile(fileName);
     if (f == null) throw new RuntimeException("nutz-test.properties Not FOUND!!!");
     is = Streams.fileIn(f);
     pp.load(is);
     pp.list(System.out);
   } catch (Exception e) {
     throw Lang.wrapThrow(e);
   } finally {
     Streams.safeClose(is);
   }
 }
Example #9
0
  @Test
  // 如果报错且mysql的话,设置数据库的max_allowed_packet属性哦
  public void test_big_blob() throws IOException {
    String path = "~/tmp/big.blob";
    Files.createFileIfNoExists(path);
    OutputStream fos = Streams.fileOut(path);
    for (int i = 0; i < 5 * 1024; i++) { // 更多的数据需要不同的类型
      fos.write(new byte[1024]);
    }
    fos.close();

    dao.create(TheGoods.class, true);
    TheGoods tg = TheGoods.create("AAA", path);
    dao.insert(tg);

    new File(path).delete();
  }
Example #10
0
  /** @see Issue #119 为何从数据库里面取出二进制数据时会被转成String类型? */
  @Test
  public void test_simple_byte_array() throws IOException {
    String path = "org/nutz/dao/test/meta/goods.png";

    dao.create(TheGoods.class, true);
    TheGoods tg = TheGoods.create("AAA", path);
    dao.insert(tg);

    // 读取
    TheGoods tg2 = dao.fetch(TheGoods.class, tg.getId());

    // 比较字节流
    byte[] olds = Files.readBytes(path);
    byte[] dbs = tg2.getThumbnail();

    assertEquals(olds.length, dbs.length);
    for (int i = 0; i < olds.length; i++) {
      assertEquals(olds[i], dbs[i]);
    }
  }
Example #11
0
 public void free() throws SQLException {
   Files.deleteFile(file);
 }
Example #12
0
 public void truncate(long len) throws SQLException {
   Files.write(file, new Byte[] {});
 }
Example #13
0
 public void append(String name, File f) {
   String contentType = getContentType(Files.getSuffixName(f));
   FileMultipartItem fmi = new FileMultipartItem(helper, boundary, name, f, contentType);
   append(fmi);
 }
 public void init() throws IOException {
   Files.createDirIfNoExists(indexDir);
   luceneIndex = new LuceneIndex(indexDir, OpenMode.CREATE_OR_APPEND);
 }
Example #15
0
 /**
  * 从classpath或当前目录下查找配置文件来进行初始化
  *
  * @param name
  */
 public void init(String name) throws IOException {
   init(new FileInputStream(Files.findFile(name)));
 }