云自无心水自闲

天平山上白云泉,云自无心水自闲。何必奔冲山下去,更添波浪向人间!
posts - 288, comments - 524, trackbacks - 0, articles - 6
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

2015年11月20日

1. java zip 多个文件时,如果先添加了一个excel文件,然后再想添加其他的文件时会出现 steam is closed的错误。这是因为work.write(outputSteam)后,出调用outputSteam.close(),关闭输出流。
解决方法:
将原来的程序:
            ZipEntry entry = new ZipEntry( "file3.txt" );
            zos.putNextEntry( entry );
            workbook.write( zos );
            zos.closeEntry();
改为:
            ZipEntry entry = new ZipEntry( "file3.txt" );
            zos.putNextEntry( entry );
            workbook.write( new NonCloseableOutputStream( zos ) );
            zos.closeEntry();

其中 NonCloseableOutputStream 定义如下:
public class NonCloseableOutputStream extends java.io.FilterOutputStream {
    public NonCloseableOutputStream(OutputStream out) {
        super(out);
    }
    @Override public void close() throws IOException {
        flush();
    }
}



2. 使用binary使得mysql区分大小写
select * from table1 where binary field1 = 'abc';

posted @ 2017-08-09 19:52 云自无心水自闲 阅读(395) | 评论 (0)编辑 收藏

https://notepad-plus-plus.org/community/topic/13661/plugin-manager-x64-available-submit-your-plugins

posted @ 2017-06-26 09:33 云自无心水自闲 阅读(369) | 评论 (0)编辑 收藏

move Git Server to a new IP/URL:

you can just edit 
.git/config and change the URLs there

也可以在git视图中,右键点击项目,选择属性,然后修改url中的地址

posted @ 2017-06-15 08:40 云自无心水自闲 阅读(293) | 评论 (0)编辑 收藏

autohotkey
listary
cmder可以split screen,在一个窗口中同时运行数个cmd

posted @ 2017-05-24 07:13 云自无心水自闲 阅读(13866) | 评论 (0)编辑 收藏

官网地址:autohotkey.com

; fill password
^Numpad2::
Send, root{tab}root{enter}
Return
^Numpad3::
IfWinExist, ahk_exe OUTLOOK.EXE
{
    WinActivate ahk_exe OUTLOOK.EXE ; Automatically uses the window found above.
    ; WinMaximize  ; same
    ;Send, Some text.{Enter}
msgbox Outlook is running.
}
Return

posted @ 2017-03-08 13:06 云自无心水自闲 阅读(338) | 评论 (0)编辑 收藏

<html>
<head>
    <script src="https://unpkg.com/vue/dist/vue.js"></script>
    <script>
        window.onload = function () {
            var app = new Vue({
                el: '#app',
                data: {
                    message: 'Hello Vue!'
                }
            });
        }    
    </script>
</head>

<body>
    <div id="app">
      {{ message }}
    </div>
</body>
</html>

posted @ 2017-02-09 07:41 云自无心水自闲 阅读(373) | 评论 (0)编辑 收藏


String[] splits=someString.split("a,b,c,d", ",");
logger.debug( "array: {}", (Object) splits );

这里要注意的就是要把数组的数据类型强制转换为Object 

posted @ 2016-12-29 11:51 云自无心水自闲 阅读(1554) | 评论 (0)编辑 收藏

在windows环境中,可以用如下方法重置root密码

1、先停止mysql数据库

2、保存密码重置sql文件
     5.7.6(包括)以后的版本:ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
     5.7.5(包括)以前的版本:SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
假设保存到文件: c:\reset.txt

3、以管理员身份打开命令行窗口,运行
C:\> cd "C:\Program Files\MySQL\MySQL Server 5.5\bin"
C:\> mysqld --init-file=C:\reset.txt

4、启动后,还不能马上用新密码连接数据库,需要重启mysql数据库

posted @ 2016-12-21 07:12 云自无心水自闲 阅读(340) | 评论 (0)编辑 收藏

This is a general step that happens when m2e/m2eclipse (Maven integration for Eclipse) is installed, whether projects are actively using it or not.
这是因为m2eclipse(maven插件)要在启动时需要进行的一个步骤。

This step can be disabled through the Eclipse preferences: Window / Preferences / Maven / "Download repository index updates on startup". This option is on the main "Maven" preference page (not a child page). Just uncheck the box to prevent this from happening.
我们可以停止这个动作。方法:Windows -> Preferences -> Maven 取消勾选 Download repository index updates on startup

posted @ 2016-11-29 08:38 云自无心水自闲 阅读(1268) | 评论 (0)编辑 收藏

有好几个java library都可以实现这个功能,但是从pdf提取文本的一个问题是,提取出来的文本没有固定的顺序,不容易比较好的还原其格式。

我的做法是使用pdfclown来进行这项工作。官方网站是:https://pdfclown.org/ 先下载其最新版本。
参考其示例代码:https://pdfclown.org/2010/01/02/upcoming-0-0-8-whats-going-to-be-new/#more-30

使用这段代码,我们不仅可以得到文本的字符串,还能得到文本的页数和相对坐标。
我的思路是先把所有文本的字符串和坐标提取出来。然后排序,排序的顺序是纵坐标,然后横坐标。
这样排序完毕后,就能比较好的解决文本格式问题。

posted @ 2016-11-28 11:03 云自无心水自闲 阅读(354) | 评论 (0)编辑 收藏


1, 先定义一个input, 做为datepicker的容器。
<input type='text' class="form-control" id="dateTo" name="dateTo" required/>

2, 在后面加上glyphicon, 注意关键是label 中的for的id需要是前面定义的容器的id, 这样点击glyphicon的时候就会触发弹出日期选择框。
<label for="dateTo" class="input-group-addon"><span class="glyphicon glyphicon-time"></span></label>

posted @ 2016-10-10 19:57 云自无心水自闲 阅读(198) | 评论 (0)编辑 收藏

在日志文件中看到这个错误信息
Cause: java.sql.SQLException: #HY000

后来才知道这是因为数据库中有个别字段要求不能为空, 但是insert语句中没有提供数据,造成了这个错误。

关键是错误信息不明确直观,不容易知道是这个原因


posted @ 2016-09-28 13:13 云自无心水自闲 阅读(1003) | 评论 (0)编辑 收藏

    public void afterJFinalStart(){
        Configuration config = FreeMarkerRender.getConfiguration();
        config.setTemplateUpdateDelayMilliseconds( 2 );
        config.setAPIBuiltinEnabled( true );
    }

posted @ 2016-09-21 14:02 云自无心水自闲 阅读(221) | 评论 (0)编辑 收藏


中文版地址  https://angular.cn/

posted @ 2016-09-16 13:13 云自无心水自闲 阅读(2099) | 评论 (0)编辑 收藏

1, call ##002# to cancel "call diversion"

2, call 121600, choose option "2" to cancel "Active call catcher"

posted @ 2016-08-25 12:58 云自无心水自闲 阅读(146) | 评论 (0)编辑 收藏

1. 格式化XML的插件
可以安装“XML Tools", 安装完毕后,选择 插件->XML Tools->Pretty Print(XML Only - with line breaks)

2. 格式化JSON的插件
可以安装”JSON Viewer", 安装完毕后,选择 插件->JSON Viewer->Format JSON

3. 格式化SQL的插件
可以安装“Poor man's T-Sql Formatter", 选择 插件->Poor man's T-Sql Formatter->Format T-Sql Code

posted @ 2016-08-12 15:14 云自无心水自闲 阅读(1044) | 评论 (0)编辑 收藏

 
使用的工具

1. Apache HttpClient
2. Firefox + FireBug
3. Burp Suite ( https://portswigger.net/burp ) + Firefox FoxyProxy

Firefox + FireBug 主要用于查看渲染出的页面中的信息(比如:表单项的名称,节点ID等等)
Burp Suite 主要用于动态拦截页面的交互,查看Ajax的调用。
HttpClient 用于最后程序的编制。搞清楚了网页交互的过程,就可以自主决定程序需要包含的内容。
在实际网页中,可能需要点开数级菜单,才能最后看到需要的内容。
但是在程序中,可以直接跳到最后一步。

posted @ 2016-06-05 19:00 云自无心水自闲 阅读(188) | 评论 (0)编辑 收藏

1. 表格文字右对齐 
 <table>
<tr>
    <td><p style="text-align:right;margin:0;padding:0">文字右对齐</p></td>
    <td>文字左对齐</td>
</tr>
</table>

2. 表格边缘的margin 需要在表格外再套一个div
<div style="margin:10px">
    <table>
    ......
    </table>
</div>

3. btn-toolbar class can put a margin between 2 "pull-right" buttons
        <div class="row">
            <div class="col-md-2"></div>
            <div class="col-md-8 btn-toolbar">
                <input type="submit" class="btn btn-warning pull-right" value="Submit">
                <input type="button" id="profilePassBackBtn" class="btn btn-info pull-right" value="Back">
            </div>
            <div class="col-md-2">
            </div>
        </div>

posted @ 2016-05-31 11:39 云自无心水自闲 阅读(364) | 评论 (0)编辑 收藏

 AngularJS 2.0 已经发布了Beta版本,相信正式版不久以后就会发布了。

下面是官网上的新功能介绍:

1. 更快更高效。AngularJS 2 将会比 AnuglarJS 1 快很多。因为它会支持:从远程胳快速加载、离线编译以便于更快启动、以及超快的变动检测和为使滚动更平滑的视图缓存等等。

2. 更加简单清晰。语法将会显得更加自然,易于编写

3. 跨越平台。无论是台式机、手机浏览器、安卓、IOS平台,AngularJS都能提供相应的支持。

4. 无缝从 AngularJS 1 升级到 2

5. 简便的开发。支持各种开发语言,ES5, TypeScript, Dart

6. 全面完备的路由。 方便地映射URL到应用组件,并提供多种高级功能,比如:嵌套和邻接路由,支持卡片栈导航、动画过渡、手机用户延迟加载等等

7. 依赖注入。

8. 旧浏览器的良好支持

9. 动画效果 (仍在开发中)

10. 国际化支持(仍在开发中)

posted @ 2016-04-18 20:09 云自无心水自闲 阅读(254) | 评论 (0)编辑 收藏

  1. Go to web project properties.
  2. Deployment Assembly (Left).
  3. Add > Select project > Select your lib project > Check "Assemble projects into the WEB-INF/lib folder of the web application" if not checked > Finish.

posted @ 2016-04-13 10:35 云自无心水自闲 阅读(162) | 评论 (0)编辑 收藏

 使用酷狗就可以转换。
右键点击歌曲 ,工具,格式转换。
唯一要注意的是要先登录。

posted @ 2016-03-17 20:20 云自无心水自闲 阅读(1583) | 评论 (0)编辑 收藏

今天把commons dbcp 和 pool都升级到2.x, 结果发现不能正常的工作,卡在new BasicDataSource()上了.
后来才发现原因是因为没有加入commons-logging的jar文件

几个注意点:
1. commons dbcp2.x 和 commons pool需要同时升到2.x
2. dbcp 2.x要运行在java 7以上 
3. mysql connector要5.1.11以上
4. 需要有commons-logging的包,我使用的是slf4j, 就需要加一个jcl-over-slf4j

posted @ 2016-02-09 11:44 云自无心水自闲 阅读(603) | 评论 (0)编辑 收藏

Error
com.jcraft.jsch.JSchException: The cipher 'aes256-cbc' is required, but it is not available.
or
Caused by: java.security.InvalidKeyException: Illegal key size


posted @ 2016-02-05 13:51 云自无心水自闲 阅读(258) | 评论 (0)编辑 收藏


我在网上搜索了一下如何使用Selenium下载文件,其中确实有几篇文件介绍了实现的方法。
但是其主要思想都是使用httpClient或者URL获得InputStream, 然后保存到文件中。
但是,其中的问题是用户登录的Session不能维持。

我发现了一个简单的方法。
直接使用WebDriver.get, 示例如下:

webDriver.get("https://website.com/login");
WebElement element = driver.findElement( By.id( "userID" ) );
element.sendKeys( "user01" );

element = driver.findElement( By.id( "passwd" ) );
element.sendKeys( "password" );

element = driver.findElement( By.name( "Login" ) );
element.submit();

webDriver.get("https://website.cm/download.do?start=xx&end=yy");
String source = webDriver.getPageSource();

这个source就是我们想保存的要下载的内容。
只要把这个String写到一个文件中,就实现了文件下载的目的

posted @ 2016-01-28 18:06 云自无心水自闲 阅读(447) | 评论 (0)编辑 收藏

     摘要: 在我的上一篇文章中介绍了如何进行GPG加密解密。
加密解密的基本操作流程是,用户使用公钥对明文进行加密,解密方使用私钥对密文进行解密。

在实际应用中,除了加密保证文本内容不泄露外,同时还要考虑能够验证密文发送方的身份,比较普遍使用的方法就是签名。
本文主要对具体的方法进行介绍并附上源代码。  阅读全文

posted @ 2015-12-11 21:40 云自无心水自闲 阅读(1225) | 评论 (0)编辑 收藏

Java程序中访问拥有全部读写权限的目录相对比较简单,和普通的目录没有什么差别。
但是要访问一个需要用户和密码验证的目录就需要一点点小技巧了。
这里介绍一个开源的库能够比较容易的实现这一需求。
1。 下载库文件:
 https://jcifs.samba.org/
下载的zip文件中, 不仅包含了jar文件,还有文档和示例。

2。拷贝jcif-1.3.18.jar到类路径中。

3。代码示例:
 1     String user = "your_user_name";
 2     String pass ="your_pass_word";
 3 
 4     String sharedFolder="shared";
 5     String path="smb://ip_address/"+sharedFolder+"/test.txt";
 6     NtlmPasswordAuthentication auth = new NtlmPasswordAuthentication("",user, pass);
 7     SmbFile smbFile = new SmbFile(path,auth);
 8     SmbFileOutputStream smbfos = new SmbFileOutputStream(smbFile);
 9     smbfos.write("testing.and writing to a file".getBytes());
10     System.out.println("completed nice !");
说明: 如果有一个共享目录,比如: \\192.168.1.2\testdir\
那么smb的路径就是:smb://192.168.1.2/testdir/
NtlmPasswordAuthentication需要三个参数, 第一个是名,没有的话,填null, 第二个是用户名,第三个是密码

得到SmbFile之后,操作就和java.io.File基本一样了。
另外还有一些功能比如:
SmbFile.copyTo
SmbFile.renameTo
等等

posted @ 2015-11-20 14:03 云自无心水自闲 阅读(12788) | 评论 (0)编辑 收藏