├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── cache-example ├── .project ├── cache-example.iml ├── ehcache-example │ ├── .project │ ├── ehcache-example.iml │ ├── pom.xml │ ├── src │ │ └── main │ │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── biezhi │ │ │ │ └── ehcache │ │ │ │ ├── BasicProgrammatic.java │ │ │ │ ├── BasicXML.java │ │ │ │ ├── ClusteredProgrammatic.java │ │ │ │ └── ClusteredXML.java │ │ │ └── resources │ │ │ ├── clustered-ehcache.xml │ │ │ ├── ehcache.xml │ │ │ └── log4j.xml │ └── tc-config.xml ├── guava-cache-example │ ├── .project │ ├── guava-cache-example.iml │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── github │ │ └── biezhi │ │ └── guavacache │ │ ├── EvictionBySizeExample.java │ │ ├── EvictionByTimeExample.java │ │ ├── HandleNullValuesExample.java │ │ ├── HelloGuavaCache.java │ │ ├── RefreshCacheExample.java │ │ └── RemovalNotification.java ├── jedis-example │ ├── .project │ ├── jedis-example.iml │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── github │ │ └── biezhi │ │ └── jedis │ │ ├── BasicExample.java │ │ ├── DBExample.java │ │ ├── HashExample.java │ │ ├── HelloJedis.java │ │ ├── JedisPoolExample.java │ │ ├── JedisUtil.java │ │ ├── KeyExample.java │ │ ├── ListExample.java │ │ ├── ListStrExample.java │ │ ├── MGetExample.java │ │ ├── OtherExample.java │ │ ├── PageExample.java │ │ ├── PipelineExample.java │ │ ├── SetExample.java │ │ ├── SetExample2.java │ │ ├── SortExample.java │ │ ├── SortSetExample.java │ │ ├── SortSetExample2.java │ │ └── StringExample.java └── pom.xml ├── common-beans ├── .project ├── common-beans.iml ├── pom.xml └── src │ └── main │ └── java │ └── io │ └── github │ └── biezhi │ ├── model │ ├── Address.java │ ├── Gender.java │ ├── Human.java │ └── Person.java │ └── utils │ ├── BeanData.java │ └── PrintUtils.java ├── compress-example ├── .project ├── compress-example.iml ├── pom.xml └── src │ └── main │ ├── java │ └── io │ │ └── github │ │ └── biezhi │ │ └── compress │ │ ├── gzip │ │ ├── GzipApache.java │ │ ├── GzipJava.java │ │ └── GzipProgram.java │ │ ├── jar │ │ ├── JAR.java │ │ └── JARProgram.java │ │ ├── sevenz │ │ ├── SevenZ.java │ │ └── SevenZProgram.java │ │ ├── tar │ │ ├── TAR.java │ │ └── TARProgram.java │ │ └── zip │ │ ├── ZIP.java │ │ └── ZIPProgram.java │ └── resources │ ├── dir │ ├── dir-resource1.txt │ ├── dir-resource2.txt │ └── sub-dir │ │ ├── sub-dir-resource1.txt │ │ └── sub-dir-resource2.txt │ ├── example.xml │ ├── in │ ├── dir │ │ ├── dir-resource1.txt │ │ ├── dir-resource2.txt │ │ └── sub-dir │ │ │ ├── sub-dir-resource1.txt │ │ │ └── sub-dir-resource2.txt │ ├── resource1.txt │ ├── resource2.txt │ └── resource3.txt │ ├── resource1.txt │ ├── resource2.txt │ └── resource3.txt ├── crawler-example ├── .project ├── crawler-example.iml ├── crawler4j-example │ ├── .project │ ├── crawler4j-example.iml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── biezhi │ │ │ └── crawler4j │ │ │ ├── basic │ │ │ ├── BasicCrawlController.java │ │ │ └── BasicCrawler.java │ │ │ ├── fetcher │ │ │ ├── PageFetcherHtmlOnly.java │ │ │ └── PageFetcherHtmlTest.java │ │ │ ├── imagecrawler │ │ │ ├── ImageCrawlController.java │ │ │ └── ImageCrawler.java │ │ │ ├── localdata │ │ │ ├── CrawlStat.java │ │ │ ├── Downloader.java │ │ │ ├── LocalDataCollectorController.java │ │ │ └── LocalDataCollectorCrawler.java │ │ │ ├── multiple │ │ │ ├── BasicCrawler.java │ │ │ └── MultipleCrawlerController.java │ │ │ ├── shutdown │ │ │ ├── BasicCrawler.java │ │ │ └── ControllerWithShutdown.java │ │ │ └── statushandler │ │ │ ├── StatusHandlerCrawlController.java │ │ │ └── StatusHandlerCrawler.java │ │ └── resources │ │ └── logback.xml ├── elves-example │ ├── .project │ ├── elves-example.iml │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── github │ │ └── biezhi │ │ └── elves │ │ ├── DoubanExample.java │ │ ├── MeiziExample.java │ │ ├── News163Example.java │ │ └── QiubaiExample.java ├── pom.xml └── webmagic-example │ ├── .project │ ├── pom.xml │ ├── src │ └── main │ │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── biezhi │ │ │ └── webmagic │ │ │ ├── main │ │ │ └── QuickStarter.java │ │ │ ├── model │ │ │ ├── BaiduNews.java │ │ │ ├── Blog.java │ │ │ ├── DianpingFtlDataScanner.java │ │ │ ├── GithubRepo.java │ │ │ ├── IteyeBlog.java │ │ │ ├── JokejiModel.java │ │ │ ├── Kr36NewsModel.java │ │ │ ├── News163.java │ │ │ ├── OschinaAnswer.java │ │ │ ├── OschinaBlog.java │ │ │ └── QQMeishi.java │ │ │ └── samples │ │ │ ├── AlexanderMcqueenGoodsProcessor.java │ │ │ ├── AmanzonPageProcessor.java │ │ │ ├── AngularJSProcessor.java │ │ │ ├── DiandianBlogProcessor.java │ │ │ ├── DiaoyuwengProcessor.java │ │ │ ├── F58PageProcesser.java │ │ │ ├── GithubRepo.java │ │ │ ├── GithubRepoPageProcessor.java │ │ │ ├── HuxiuProcessor.java │ │ │ ├── InfoQMiniBookProcessor.java │ │ │ ├── IteyeBlogProcessor.java │ │ │ ├── KaichibaProcessor.java │ │ │ ├── MamacnPageProcessor.java │ │ │ ├── MeicanProcessor.java │ │ │ ├── NjuBBSProcessor.java │ │ │ ├── PhantomJSPageProcessor.java │ │ │ ├── QzoneBlogProcessor.java │ │ │ ├── SinaBlogProcessor.java │ │ │ ├── TianyaPageProcesser.java │ │ │ ├── ZhihuPageProcessor.java │ │ │ ├── formatter │ │ │ └── StringTemplateFormatter.java │ │ │ ├── pipeline │ │ │ └── OneFilePipeline.java │ │ │ └── scheduler │ │ │ ├── DelayQueueScheduler.java │ │ │ ├── LevelLimitScheduler.java │ │ │ └── ZipCodePageProcessor.java │ │ └── resources │ │ ├── crawl.js │ │ └── log4j.xml │ └── webmagic-example.iml ├── email-example ├── .project ├── commons-email-example │ ├── .project │ ├── commons-email-example.iml │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── github │ │ └── biezhi │ │ └── email │ │ ├── HtmlEmbeddedImageExample.java │ │ ├── HtmlMailExample.java │ │ ├── SendTextExample.java │ │ └── SendWithAttachExample.java ├── email-example.iml ├── ohmyemail-example │ ├── .project │ ├── ohmyemail-example.iml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── biezhi │ │ │ └── ohmyemail │ │ │ └── OhMyEmailTest.java │ │ └── resources │ │ └── register.html └── pom.xml ├── embedded-example ├── .project ├── embedded-example.iml ├── embedded-jetty-example │ ├── .project │ ├── README.md │ ├── embedded-jetty-example.iml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── biezhi │ │ │ └── jetty │ │ │ ├── AddFilterMultipleMapping.java │ │ │ ├── ConnectorSpecificContexts.java │ │ │ ├── ConnectorSpecificWebapps.java │ │ │ ├── DefaultServletFileServer.java │ │ │ ├── DefaultServletMultipleBases.java │ │ │ ├── FileServer.java │ │ │ ├── GzipResponsesExample.java │ │ │ ├── HelloHandler.java │ │ │ ├── ManyContexts.java │ │ │ ├── MinimalServlets.java │ │ │ ├── MovedPermanentlyExample.java │ │ │ ├── OneConnector.java │ │ │ ├── OneContext.java │ │ │ ├── OneServletContext.java │ │ │ ├── ResourceHandlerFromClasspath.java │ │ │ ├── ResourceHandlerFromFileSystem.java │ │ │ ├── SecuredRedirectHandlerExample.java │ │ │ ├── ServerConnectorHttps.java │ │ │ ├── ServletTransportGuaranteeExample.java │ │ │ ├── SimplestServer.java │ │ │ ├── VirtualHostsExample.java │ │ │ ├── WebAppContextFromClasspath.java │ │ │ ├── WebAppContextFromFileSystem.java │ │ │ ├── handlers │ │ │ └── HelloHandler.java │ │ │ ├── servlets │ │ │ ├── DumpServlet.java │ │ │ ├── HelloServlet.java │ │ │ └── TimeServlet.java │ │ │ └── websocket │ │ │ ├── JettyTimeSocket.java │ │ │ ├── SecureWebSocketServer.java │ │ │ ├── WebSocketServerViaFilter.java │ │ │ └── jsr │ │ │ ├── JsrBrowserConfigurator.java │ │ │ ├── JsrBrowserMain.java │ │ │ ├── JsrBrowserSocket.java │ │ │ └── TimeSocket.java │ │ ├── resources │ │ ├── hello-webapp │ │ │ ├── WEB-INF │ │ │ │ └── web.xml │ │ │ └── hello.html │ │ ├── jetty-logging.properties │ │ ├── ssl │ │ │ └── keystore │ │ ├── static-root │ │ │ └── hello.html │ │ └── websocket-statics │ │ │ ├── index.html │ │ │ ├── main.css │ │ │ └── websocket.js │ │ └── webapps │ │ ├── alt-root │ │ ├── alt-hello.html │ │ └── index.htm │ │ └── static-root │ │ ├── css │ │ └── main.css │ │ ├── hello.html │ │ ├── images │ │ ├── jetty-avatar.png │ │ ├── jetty-avatar.svg │ │ └── jetty-logo.png │ │ ├── index.html │ │ └── js │ │ ├── jquery-2.1.4.js │ │ ├── jquery-2.1.4.js.gz │ │ ├── jquery.timer.js │ │ ├── jquery.timer.js.gz │ │ └── time.js ├── mapdb-example │ ├── .project │ ├── mapdb-example.iml │ └── pom.xml └── pom.xml ├── encrypt-example ├── .project ├── encrypt-example.iml └── pom.xml ├── excel-example ├── .project ├── excel-example.iml ├── jxl-excel-example │ ├── .project │ ├── jxl-excel-example.iml │ └── pom.xml ├── poi-excel-example │ ├── .project │ ├── poi-excel-example.iml │ └── pom.xml └── pom.xml ├── gui-example ├── .project ├── gui-example.iml └── pom.xml ├── http-example ├── .project ├── http-example.iml ├── httpclient4-example │ ├── .project │ ├── httpclient4-example.iml │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── github │ │ └── biezhi │ │ └── httpclient4 │ │ ├── CookieExample.java │ │ ├── GetExample.java │ │ ├── GetMimeTypeExample.java │ │ ├── NoRedirectExample.java │ │ ├── PostExample.java │ │ └── TimeoutExample.java ├── ohmyrequest-example │ ├── .project │ ├── ohmyrequest-example.iml │ └── pom.xml ├── okhttp3-example │ ├── .project │ ├── okhttp3-example.iml │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── github │ │ └── biezhi │ │ └── okhttp3 │ │ ├── AuthorizationExample.java │ │ ├── CacheResponseExample.java │ │ ├── CookieExample.java │ │ ├── DefaultHeaderExample.java │ │ ├── GetExample.java │ │ ├── MultipartExample.java │ │ ├── NoRedirectExample.java │ │ ├── PostExample.java │ │ ├── PostWithJsonExample.java │ │ └── TimeoutExample.java ├── pom.xml └── unirest-example │ ├── .project │ ├── pom.xml │ ├── src │ └── main │ │ └── java │ │ └── io │ │ └── github │ │ └── biezhi │ │ └── unirest │ │ ├── AsynRequestExample.java │ │ ├── AuthenticationExample.java │ │ ├── CustomBodyExample.java │ │ ├── FileUploadExample.java │ │ ├── RouteParamExample.java │ │ ├── SerializationExample.java │ │ ├── UnirestExample.java │ │ └── model │ │ ├── Author.java │ │ └── Book.java │ └── unirest-example.iml ├── json-example ├── .project ├── fastjson-example │ ├── .project │ ├── fastjson-example.iml │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── github │ │ └── biezhi │ │ └── json │ │ └── fastjson │ │ └── FastjsonExample1.java ├── gson-exmaple │ ├── .project │ ├── gson-exmaple.iml │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── github │ │ └── biezhi │ │ └── json │ │ └── gson │ │ ├── ArraysAndListsExample.java │ │ ├── BasicExample.java │ │ ├── ExposeExample.java │ │ ├── FileReaderWriterExample.java │ │ ├── FloatExample.java │ │ ├── GenericsExample.java │ │ ├── SerializeCollections.java │ │ ├── SerializeEnums.java │ │ ├── SerializeGenericTypes.java │ │ ├── SerializePrimitivesTypes.java │ │ └── model │ │ ├── Animal.java │ │ ├── Box.java │ │ ├── Dog.java │ │ ├── Health.java │ │ ├── RestaurantMenuItem.java │ │ ├── RestaurantWithMenu.java │ │ ├── UserFloat.java │ │ └── UserSimple.java ├── jackson-example │ ├── .project │ ├── jackson-example.iml │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── github │ │ └── biezhi │ │ └── json │ │ └── jackson │ │ ├── AnnotationFieldExample.java │ │ ├── BasicExample.java │ │ ├── FileReadWriteExample.java │ │ ├── IgnoreClassExample.java │ │ ├── IgnoreFieldExample.java │ │ ├── IgnoreUnknownExample.java │ │ ├── JsonCreatorConstructorExample.java │ │ ├── JsonCreatorFactoryMethodExample.java │ │ └── model │ │ ├── Employee.java │ │ ├── Employee2.java │ │ ├── Employee3.java │ │ └── Employee4.java ├── json-example.iml └── pom.xml ├── log-example ├── .project ├── commons-logging-example │ ├── .project │ ├── commons-logging-example.iml │ ├── pom.xml │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── github │ │ └── biezhi │ │ └── commons │ │ └── logging │ │ ├── Example1.java │ │ └── Example2.java ├── log-example.iml ├── log4j-example │ ├── .project │ ├── log4j-example.iml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── biezhi │ │ │ └── log4j │ │ │ └── Example.java │ │ └── resources │ │ └── log4j.properties ├── logback-example │ ├── .project │ ├── logback-example.iml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── biezhi │ │ │ └── logback │ │ │ └── LogbackExample.java │ │ └── resources │ │ ├── logback-file.xml │ │ └── logback.xml ├── pom.xml └── slf4j-example │ ├── .project │ ├── pom.xml │ ├── slf4j-example.iml │ └── src │ └── main │ ├── java │ └── io │ │ └── github │ │ └── biezhi │ │ └── slf4j │ │ ├── Hello.java │ │ └── Slf4jExample.java │ └── resources │ └── logback.xml ├── metrics-example ├── README.md ├── pom.xml └── src │ └── main │ └── java │ └── io │ └── github │ └── biezhi │ └── metrics │ ├── CounterExample.java │ ├── GaugeExample.java │ ├── HistogramExample.java │ ├── MeterExample.java │ └── TimerExample.java ├── mq-example ├── .project ├── kafka-example │ ├── .project │ ├── kafka-example.iml │ └── pom.xml ├── mq-example.iml ├── pom.xml ├── rabbitmq-example │ ├── .project │ ├── pom.xml │ └── rabbitmq-example.iml └── rocketmq-example │ ├── .project │ ├── pom.xml │ └── rocketmq-example.iml ├── network-example ├── .project ├── mina-example │ ├── .project │ ├── mina-example.iml │ └── pom.xml ├── netty-example │ ├── .project │ ├── netty-example.iml │ └── pom.xml ├── network-example.iml └── pom.xml ├── orm-example ├── .project ├── blade-jdbc-example │ ├── .project │ ├── blade-jdbc-example.iml │ └── pom.xml ├── dbutils-example │ ├── .project │ ├── dbutils-example.iml │ └── pom.xml ├── hibernate-example │ ├── .project │ ├── hibernate-example.iml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── biezhi │ │ │ └── hibernate │ │ │ ├── ExampleMain.java │ │ │ └── Person.java │ │ └── resources │ │ └── hibernate.cfg.xml ├── jooq-example │ ├── .project │ ├── jooq-example.iml │ └── pom.xml ├── mybatis-example │ ├── .project │ ├── mybatis-example.iml │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── io │ │ │ │ └── github │ │ │ │ └── biezhi │ │ │ │ └── mybatis │ │ │ │ ├── RunMybatis.java │ │ │ │ ├── dao │ │ │ │ └── VillageDAO.java │ │ │ │ ├── mapper │ │ │ │ ├── TransactionTokenMapper.java │ │ │ │ └── VillageMapper.java │ │ │ │ ├── model │ │ │ │ ├── TransactionToken.java │ │ │ │ └── Village.java │ │ │ │ └── utils │ │ │ │ └── MyBatisUtil.java │ │ └── resources │ │ │ ├── log4j.xml │ │ │ ├── mapper │ │ │ └── VillageMapper.xml │ │ │ └── mybatis-config.xml │ │ └── test │ │ └── java │ │ └── io │ │ └── github │ │ └── biezhi │ │ └── mybatis │ │ └── AppTest.java ├── orm-example.iml ├── pom.xml └── sql2o-example │ ├── .project │ ├── pom.xml │ └── sql2o-example.iml ├── pom.xml ├── qrcode-example ├── .project ├── pom.xml ├── qrcode-example.iml ├── qrgen-example │ ├── .project │ ├── pom.xml │ ├── qrgen-example.iml │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── github │ │ └── biezhi │ │ └── qrgen │ │ ├── CreateQrCodeVCard.java │ │ ├── QRGenExample.java │ │ └── URLQRCodeExample.java └── zxing-example │ ├── .project │ ├── pom.xml │ ├── src │ └── main │ │ └── java │ │ └── io │ │ └── github │ │ └── biezhi │ │ └── zxing │ │ ├── QRCodeExample.java │ │ └── URLQRCodeExample.java │ └── zxing-example.iml ├── rss-example ├── .project ├── pom.xml └── rss-example.iml ├── task-example ├── .project ├── pom.xml ├── quartz-example │ ├── .project │ ├── pom.xml │ ├── quartz-example.iml │ └── src │ │ └── main │ │ └── java │ │ └── io │ │ └── github │ │ └── biezhi │ │ └── quartz │ │ ├── CronTriggerExample.java │ │ ├── JobListenerExample.java │ │ ├── SimpleTriggerExample.java │ │ ├── job │ │ ├── ExceptionJob.java │ │ └── HelloJob.java │ │ └── listener │ │ └── HelloJobListener.java └── task-example.iml ├── template-example ├── .project ├── freemarker-example │ ├── .project │ ├── freemarker-example.iml │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── io │ │ │ └── github │ │ │ └── biezhi │ │ │ └── freemarker │ │ │ └── HelloExample.java │ │ └── resources │ │ └── hello.ftl ├── jetbrick-example │ ├── .project │ ├── jetbrick-example.iml │ └── pom.xml ├── pom.xml ├── template-example.iml └── velocity-example │ ├── .project │ ├── pom.xml │ └── velocity-example.iml ├── tensorflow-example ├── pom.xml └── src │ └── main │ └── java │ └── io │ └── github │ └── biezhi │ └── tensorflow │ ├── GraphExample.java │ └── HelloTF.java └── yaml-example ├── pom.xml └── src └── main ├── java └── io │ └── github │ └── biezhi │ └── yaml │ ├── JavaToYamlExample.java │ ├── JavaToYamlWithOptions.java │ ├── LoadList.java │ ├── LoadMapList.java │ ├── YamlExample.java │ └── model │ ├── Person.java │ └── Persons.java └── resources ├── fruits.yml ├── fruitsGroup.yml ├── person.yml └── persons.yml /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | 3 | jdk: 4 | - oraclejdk8 5 | 6 | notifications: 7 | email: false 8 | 9 | sudo: false 10 | 11 | before_install: 12 | - export TZ='Asia/Shanghai' -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 王爵nice (biezhi) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /cache-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | cache-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /cache-example/cache-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /cache-example/ehcache-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | ehcache-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /cache-example/ehcache-example/src/main/resources/ehcache.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | java.lang.Long 9 | java.lang.String 10 | 11 | 100 12 | 1 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /cache-example/ehcache-example/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /cache-example/ehcache-example/tc-config.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 10 7 | 8 | 9 | 10 | 11 | 12 | 9510 13 | terracotta/server-data 14 | terracotta/server-logs 15 | 16 | 17 | -------------------------------------------------------------------------------- /cache-example/guava-cache-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | guava-cache-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /cache-example/guava-cache-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | cache-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | guava-cache-example 13 | 14 | 15 | 16 | com.google.guava 17 | guava 18 | 23.0 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /cache-example/jedis-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | jedis-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /cache-example/jedis-example/src/main/java/io/github/biezhi/jedis/DBExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.jedis; 2 | 3 | import redis.clients.jedis.Jedis; 4 | 5 | /** 6 | * Redis DB 操作 7 | * 8 | * @author biezhi 9 | * @date 2018/1/19 10 | */ 11 | public class DBExample { 12 | 13 | public static void main(String[] args) { 14 | 15 | try (Jedis jedis = JedisUtil.getInstance().getJedis()) { 16 | // select db-index 17 | System.out.println(jedis.select(0)); 18 | // 通过索引选择数据库,默认连接的数据库所有是0,默认数据库数是16个。返回1表示成功,0失败 19 | // dbsize 返回当前数据库的key数量 20 | System.out.println(jedis.dbSize()); 21 | // 返回匹配指定模式的所有key 22 | System.out.println(jedis.keys("*")); 23 | System.out.println(jedis.randomKey()); 24 | // 删除当前数据库中所有key,此方法不会失败。慎用 25 | jedis.flushDB(); 26 | // 删除所有数据库中的所有key,此方法不会失败。更加慎用 27 | jedis.flushAll(); 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /cache-example/jedis-example/src/main/java/io/github/biezhi/jedis/HelloJedis.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.jedis; 2 | 3 | import redis.clients.jedis.Jedis; 4 | 5 | /** 6 | * 第一个 Redis 操作示例 7 | * 8 | * @author biezhi 9 | * @date 2018/1/19 10 | */ 11 | public class HelloJedis { 12 | 13 | public static void main(String[] args) { 14 | // 连接到本地 localhost:6379 的redis服务 15 | Jedis jedis = new Jedis("localhost", 6379); 16 | 17 | // 设置一个 Key 18 | jedis.set("name", "biezhi"); 19 | 20 | // 获取key的数据 21 | System.out.println(jedis.get("name")); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /cache-example/jedis-example/src/main/java/io/github/biezhi/jedis/JedisPoolExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.jedis; 2 | 3 | import redis.clients.jedis.Jedis; 4 | 5 | import java.util.Set; 6 | 7 | /** 8 | * Jedis Pool 示例 9 | * 10 | * @author biezhi 11 | * @date 2018/1/19 12 | */ 13 | public class JedisPoolExample { 14 | 15 | public static void main(String[] args) { 16 | /// Jedis implements Closeable. Hence, the jedis instance will be auto-closed after the last statement. 17 | try (Jedis jedis = JedisUtil.getInstance().getJedis("127.0.0.1", 6379)) { 18 | /// ... do stuff here ... for example 19 | jedis.set("foo", "bar"); 20 | String foobar = jedis.get("foo"); 21 | jedis.zadd("sose", 0, "car"); 22 | jedis.zadd("sose", 0, "bike"); 23 | Set sose = jedis.zrange("sose", 0, -1); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /cache-example/jedis-example/src/main/java/io/github/biezhi/jedis/KeyExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.jedis; 2 | 3 | import redis.clients.jedis.Jedis; 4 | 5 | /** 6 | * Redis Key 操作 7 | * 8 | * @author biezhi 9 | * @date 2018/1/19 10 | */ 11 | public class KeyExample { 12 | 13 | public static void main(String[] args) { 14 | 15 | try (Jedis jedis = JedisUtil.getInstance().getJedis()) { 16 | System.out.println("=============key=========================="); 17 | // 清空数据 18 | System.out.println(jedis.flushDB()); 19 | System.out.println(jedis.echo("foo")); 20 | // 判断key否存在 21 | System.out.println(jedis.exists("foo")); 22 | jedis.set("key", "values"); 23 | System.out.println(jedis.exists("key")); 24 | } 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /cache-example/jedis-example/src/main/java/io/github/biezhi/jedis/MGetExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.jedis; 2 | 3 | import redis.clients.jedis.Jedis; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Redis mget 操作 9 | * 10 | * @author biezhi 11 | * @date 2018/1/19 12 | */ 13 | public class MGetExample { 14 | 15 | public static void main(String[] args) { 16 | 17 | try (Jedis jedis = JedisUtil.getInstance().getJedis()) { 18 | jedis.rpush("ids", "aa"); 19 | jedis.rpush("ids", "bb"); 20 | jedis.rpush("ids", "cc"); 21 | 22 | List ids = jedis.lrange("ids", 0, -1); 23 | 24 | jedis.set("aa", "{'name':'zhoujie','age':20}"); 25 | jedis.set("bb", "{'name':'yilin','age':28}"); 26 | jedis.set("cc", "{'name':'lucy','age':21}"); 27 | List list = jedis.mget(ids.toArray(new String[ids.size()])); 28 | System.out.println(list); 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /cache-example/jedis-example/src/main/java/io/github/biezhi/jedis/PageExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.jedis; 2 | 3 | import redis.clients.jedis.Jedis; 4 | 5 | import java.util.List; 6 | 7 | /** 8 | * Redis 分页 操作 9 | * 10 | * @author biezhi 11 | * @date 2018/1/19 12 | */ 13 | public class PageExample { 14 | 15 | public static void main(String[] args) { 16 | 17 | try (Jedis jedis = JedisUtil.getInstance().getJedis()) { 18 | int pageNo = 6; 19 | int pageSize = 6; 20 | jedis.del("a"); 21 | for (int i = 1; i <= 30; i++) { 22 | jedis.rpush("a", i + ""); 23 | } 24 | 25 | // 因为redis中list元素位置基数是0 26 | int start = pageSize * (pageNo - 1); 27 | int end = start + pageSize - 1; 28 | 29 | // 从start算起,start算一个元素,到结束那个元素 30 | List results = jedis.lrange("a", start, end); 31 | for (String str : results) { 32 | System.out.println(str); 33 | } 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /cache-example/jedis-example/src/main/java/io/github/biezhi/jedis/PipelineExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.jedis; 2 | 3 | import redis.clients.jedis.Jedis; 4 | import redis.clients.jedis.Pipeline; 5 | 6 | /** 7 | * Redis Pipeline 操作 8 | * 9 | * @author biezhi 10 | * @date 2018/1/19 11 | */ 12 | public class PipelineExample { 13 | 14 | public static void main(String[] args) { 15 | 16 | try (Jedis jedis = JedisUtil.getInstance().getJedis()) { 17 | long start = System.currentTimeMillis(); 18 | jedis.flushDB(); 19 | Pipeline p = jedis.pipelined(); 20 | for (int i = 0; i < 10000; i++) { 21 | p.set("age2" + i, i + ""); 22 | System.out.println(p.get("age2" + i)); 23 | } 24 | p.sync();// 这段代码获取所有的response 25 | 26 | long end = System.currentTimeMillis(); 27 | 28 | System.out.println("use pipeline cost:" + (end - start) + "ms"); 29 | 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /cache-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | cache-example 13 | pom 14 | 15 | jedis-example 16 | ehcache-example 17 | guava-cache-example 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /common-beans/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | common-beans 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /common-beans/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | common-beans 13 | 14 | 15 | 16 | io.github.benas 17 | random-beans 18 | 3.7.0 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /common-beans/src/main/java/io/github/biezhi/model/Address.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.model; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class Address { 7 | 8 | private String zipCode; 9 | private String city; 10 | private String country; 11 | 12 | } -------------------------------------------------------------------------------- /common-beans/src/main/java/io/github/biezhi/model/Gender.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.model; 2 | 3 | public enum Gender { 4 | MALE, FEMALE 5 | } -------------------------------------------------------------------------------- /common-beans/src/main/java/io/github/biezhi/model/Human.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.model; 2 | 3 | import lombok.Data; 4 | 5 | import java.io.Serializable; 6 | 7 | @Data 8 | public class Human implements Serializable { 9 | 10 | protected Long id; 11 | protected String name; 12 | 13 | } -------------------------------------------------------------------------------- /common-beans/src/main/java/io/github/biezhi/model/Person.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.model; 2 | 3 | import lombok.Data; 4 | import lombok.ToString; 5 | 6 | import java.util.Date; 7 | import java.util.List; 8 | 9 | @Data 10 | @ToString(callSuper = true) 11 | public class Person extends Human { 12 | 13 | private Gender gender; 14 | private Address address; 15 | private Date birthDate; 16 | private String phoneNumber; 17 | private List nicknames; 18 | 19 | } -------------------------------------------------------------------------------- /common-beans/src/main/java/io/github/biezhi/utils/PrintUtils.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.utils; 2 | 3 | /** 4 | * @author biezhi 5 | * @date 2018/1/15 6 | */ 7 | public class PrintUtils { 8 | 9 | public static void print(String msg, Object out){ 10 | System.out.println("------------------------- " + msg + " -------------------------"); 11 | System.out.println("结果 => " + out.toString()); 12 | System.out.println("------------------------- END -------------------------\r\n"); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /compress-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | compress-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /compress-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | compress-example 13 | 14 | 15 | 16 | org.apache.commons 17 | commons-compress 18 | 1.14 19 | 20 | 21 | org.tukaani 22 | xz 23 | 1.6 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /compress-example/src/main/java/io/github/biezhi/compress/gzip/GzipApache.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.compress.gzip; 2 | 3 | import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream; 4 | import org.apache.commons.compress.compressors.gzip.GzipCompressorOutputStream; 5 | import org.apache.commons.compress.utils.IOUtils; 6 | 7 | import java.io.File; 8 | import java.io.FileInputStream; 9 | import java.io.FileOutputStream; 10 | import java.io.IOException; 11 | 12 | public class GzipApache { 13 | 14 | private GzipApache() {} 15 | 16 | public static void compressGZIP(File input, File output) throws IOException { 17 | try (GzipCompressorOutputStream out = new GzipCompressorOutputStream(new FileOutputStream(output))){ 18 | IOUtils.copy(new FileInputStream(input), out); 19 | } 20 | } 21 | 22 | public static void decompressGZIP(File input, File output) throws IOException { 23 | try (GzipCompressorInputStream in = new GzipCompressorInputStream(new FileInputStream(input))){ 24 | IOUtils.copy(in, new FileOutputStream(output)); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /compress-example/src/main/java/io/github/biezhi/compress/gzip/GzipProgram.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.compress.gzip; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | public class GzipProgram { 7 | 8 | public static void main(String... args) throws IOException { 9 | 10 | // class for resource classloading 11 | Class clazz = GzipApache.class; 12 | 13 | // create files to read and write 14 | File example = new File(clazz.getResource("/example.xml").getFile()); 15 | File output = new File("tmp/example.xml.gz"); 16 | File decompressed = new File("tmp/decompressed.xml"); 17 | 18 | 19 | // Java GZIP example compression decompression 20 | GzipJava.compressGZIP(example, output); 21 | GzipJava.decompressGzip(output, decompressed); 22 | 23 | // Apache GZIP example compression decompression 24 | GzipApache.compressGZIP(example, output); 25 | GzipApache.decompressGZIP(output, decompressed); 26 | 27 | } 28 | } -------------------------------------------------------------------------------- /compress-example/src/main/resources/dir/dir-resource1.txt: -------------------------------------------------------------------------------- 1 | # example file for zip generation -------------------------------------------------------------------------------- /compress-example/src/main/resources/dir/dir-resource2.txt: -------------------------------------------------------------------------------- 1 | # example file for zip generation -------------------------------------------------------------------------------- /compress-example/src/main/resources/dir/sub-dir/sub-dir-resource1.txt: -------------------------------------------------------------------------------- 1 | # example file for zip generation -------------------------------------------------------------------------------- /compress-example/src/main/resources/dir/sub-dir/sub-dir-resource2.txt: -------------------------------------------------------------------------------- 1 | # example file for zip generation -------------------------------------------------------------------------------- /compress-example/src/main/resources/example.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | Reading XML Document using JDom 7 | 0.0 8 | 9 | 10 | Getting Started with JDom 11 | 0.0 12 | 13 | 14 | 15 | 18 | 19 | 12.0 20 | 21 | 22 | -------------------------------------------------------------------------------- /compress-example/src/main/resources/in/dir/dir-resource1.txt: -------------------------------------------------------------------------------- 1 | # example file for zip generation -------------------------------------------------------------------------------- /compress-example/src/main/resources/in/dir/dir-resource2.txt: -------------------------------------------------------------------------------- 1 | # example file for zip generation -------------------------------------------------------------------------------- /compress-example/src/main/resources/in/dir/sub-dir/sub-dir-resource1.txt: -------------------------------------------------------------------------------- 1 | # example file for zip generation -------------------------------------------------------------------------------- /compress-example/src/main/resources/in/dir/sub-dir/sub-dir-resource2.txt: -------------------------------------------------------------------------------- 1 | # example file for zip generation -------------------------------------------------------------------------------- /compress-example/src/main/resources/in/resource1.txt: -------------------------------------------------------------------------------- 1 | # example file for zip generation -------------------------------------------------------------------------------- /compress-example/src/main/resources/in/resource2.txt: -------------------------------------------------------------------------------- 1 | # example file for zip generation -------------------------------------------------------------------------------- /compress-example/src/main/resources/in/resource3.txt: -------------------------------------------------------------------------------- 1 | # example file for zip generation -------------------------------------------------------------------------------- /compress-example/src/main/resources/resource1.txt: -------------------------------------------------------------------------------- 1 | # example file for zip generation -------------------------------------------------------------------------------- /compress-example/src/main/resources/resource2.txt: -------------------------------------------------------------------------------- 1 | # example file for zip generation -------------------------------------------------------------------------------- /compress-example/src/main/resources/resource3.txt: -------------------------------------------------------------------------------- 1 | # example file for zip generation -------------------------------------------------------------------------------- /crawler-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | crawler-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /crawler-example/crawler-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /crawler-example/crawler4j-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | crawler4j-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /crawler-example/crawler4j-example/crawler4j-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /crawler-example/crawler4j-example/src/main/java/io/github/biezhi/crawler4j/localdata/CrawlStat.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.crawler4j.localdata; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class CrawlStat { 7 | private int totalProcessedPages; 8 | private long totalLinks; 9 | private long totalTextSize; 10 | 11 | public void incTotalLinks(int count) { 12 | this.totalLinks += count; 13 | } 14 | 15 | public void incTotalTextSize(int count) { 16 | this.totalTextSize += count; 17 | } 18 | } -------------------------------------------------------------------------------- /crawler-example/crawler4j-example/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /crawler-example/elves-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | elves-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /crawler-example/elves-example/elves-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /crawler-example/elves-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | crawler-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | elves-example 13 | 14 | 15 | 16 | io.github.biezhi 17 | elves 18 | 0.0.2 19 | 20 | 21 | -------------------------------------------------------------------------------- /crawler-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | crawler-example 13 | pom 14 | 15 | webmagic-example 16 | crawler4j-example 17 | elves-example 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /crawler-example/webmagic-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | webmagic-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /crawler-example/webmagic-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | crawler-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | webmagic-example 13 | 14 | 15 | 16 | us.codecraft 17 | webmagic-core 18 | 0.7.3 19 | 20 | 21 | us.codecraft 22 | webmagic-extension 23 | 0.7.3 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /crawler-example/webmagic-example/src/main/java/io/github/biezhi/webmagic/model/Blog.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.webmagic.model; 2 | 3 | /** 4 | * @author code4crafter@gmail.com
5 | * Date: 13-8-2
6 | * Time: 上午8:10
7 | */ 8 | public interface Blog { 9 | 10 | public String getTitle(); 11 | 12 | public String getContent(); 13 | } -------------------------------------------------------------------------------- /crawler-example/webmagic-example/src/main/java/io/github/biezhi/webmagic/model/OschinaAnswer.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.webmagic.model; 2 | 3 | import us.codecraft.webmagic.Page; 4 | import us.codecraft.webmagic.Site; 5 | import us.codecraft.webmagic.model.*; 6 | import us.codecraft.webmagic.model.annotation.ExtractBy; 7 | import us.codecraft.webmagic.model.annotation.HelpUrl; 8 | import us.codecraft.webmagic.model.annotation.TargetUrl; 9 | 10 | /** 11 | * @author code4crafter@gmail.com
12 | */ 13 | @TargetUrl("http://www.oschina.net/question/\\d+_\\d+*") 14 | @HelpUrl("http://www.oschina.net/question/*") 15 | @ExtractBy(value = "//ul[@class='list']/li[@class='Answer']", multi = true) 16 | public class OschinaAnswer implements AfterExtractor{ 17 | 18 | @ExtractBy("//img/@title") 19 | private String user; 20 | 21 | @ExtractBy("//div[@class='detail']") 22 | private String content; 23 | 24 | public static void main(String[] args) { 25 | OOSpider.create(Site.me(), OschinaAnswer.class).addUrl("http://www.oschina.net/question/567527_120597").run(); 26 | } 27 | 28 | @Override 29 | public void afterProcess(Page page) { 30 | 31 | } 32 | } -------------------------------------------------------------------------------- /crawler-example/webmagic-example/src/main/java/io/github/biezhi/webmagic/model/QQMeishi.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.webmagic.model; 2 | 3 | import us.codecraft.webmagic.Site; 4 | import us.codecraft.webmagic.model.ConsolePageModelPipeline; 5 | import us.codecraft.webmagic.model.OOSpider; 6 | import us.codecraft.webmagic.model.annotation.ExtractBy; 7 | import us.codecraft.webmagic.model.annotation.TargetUrl; 8 | 9 | /** 10 | * @author code4crafter@gmail.com 11 | */ 12 | @TargetUrl("http://meishi.qq.com/beijing/c/all[\\-p2]*") 13 | @ExtractBy(value = "//ul[@id=\"promos_list2\"]/li",multi = true) 14 | public class QQMeishi { 15 | 16 | @ExtractBy("//div[@class=info]/a[@class=title]/h4/text()") 17 | private String shopName; 18 | 19 | @ExtractBy("//div[@class=info]/a[@class=title]/text()") 20 | private String promo; 21 | 22 | public static void main(String[] args) { 23 | OOSpider.create(Site.me(), new ConsolePageModelPipeline(), QQMeishi.class).addUrl("http://meishi.qq.com/beijing/c/all").thread(4).run(); 24 | } 25 | 26 | } -------------------------------------------------------------------------------- /crawler-example/webmagic-example/src/main/java/io/github/biezhi/webmagic/samples/GithubRepo.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.webmagic.samples; 2 | 3 | /** 4 | * @author code4crafer@gmail.com 5 | */ 6 | public class GithubRepo { 7 | 8 | private String name; 9 | 10 | private String author; 11 | 12 | private String readme; 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public void setName(String name) { 19 | this.name = name; 20 | } 21 | 22 | public String getAuthor() { 23 | return author; 24 | } 25 | 26 | public void setAuthor(String author) { 27 | this.author = author; 28 | } 29 | 30 | public String getReadme() { 31 | return readme; 32 | } 33 | 34 | public void setReadme(String readme) { 35 | this.readme = readme; 36 | } 37 | } -------------------------------------------------------------------------------- /crawler-example/webmagic-example/src/main/java/io/github/biezhi/webmagic/samples/HuxiuProcessor.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.webmagic.samples; 2 | 3 | import us.codecraft.webmagic.Site; 4 | import us.codecraft.webmagic.Page; 5 | import us.codecraft.webmagic.Spider; 6 | import us.codecraft.webmagic.processor.PageProcessor; 7 | 8 | import java.util.List; 9 | 10 | /** 11 | * @author code4crafter@gmail.com
12 | */ 13 | public class HuxiuProcessor implements PageProcessor { 14 | @Override 15 | public void process(Page page) { 16 | List requests = page.getHtml().links().regex(".*article.*").all(); 17 | page.addTargetRequests(requests); 18 | page.putField("title",page.getHtml().xpath("//div[@class='clearfix neirong']//h1/text()")); 19 | page.putField("content",page.getHtml().xpath("//div[@id='neirong_box']/tidyText()")); 20 | } 21 | 22 | @Override 23 | public Site getSite() { 24 | return Site.me().setDomain("www.huxiu.com"); 25 | } 26 | 27 | public static void main(String[] args) { 28 | Spider.create(new HuxiuProcessor()).addUrl("http://www.huxiu.com/").run(); 29 | } 30 | 31 | } -------------------------------------------------------------------------------- /crawler-example/webmagic-example/src/main/java/io/github/biezhi/webmagic/samples/TianyaPageProcesser.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.webmagic.samples; 2 | 3 | import us.codecraft.webmagic.Page; 4 | import us.codecraft.webmagic.Site; 5 | import us.codecraft.webmagic.processor.PageProcessor; 6 | 7 | import java.util.List; 8 | 9 | /** 10 | * @author code4crafter@gmail.com
11 | */ 12 | public class TianyaPageProcesser implements PageProcessor { 13 | 14 | @Override 15 | public void process(Page page) { 16 | List strings = page.getHtml().regex("]*href=[\"']{1}(/post-free.*?\\.shtml)[\"']{1}").all(); 17 | page.addTargetRequests(strings); 18 | page.putField("title", page.getHtml().xpath("//div[@id='post_head']//span[@class='s_title']//b")); 19 | page.putField("body", page.getHtml().smartContent()); 20 | } 21 | 22 | @Override 23 | public Site getSite() { 24 | //To change body of implemented methods use File | Settings | File Templates. 25 | return Site.me().setDomain("http://bbs.tianya.cn/"); 26 | } 27 | } -------------------------------------------------------------------------------- /crawler-example/webmagic-example/src/main/java/io/github/biezhi/webmagic/samples/formatter/StringTemplateFormatter.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.webmagic.samples.formatter; 2 | 3 | import us.codecraft.webmagic.model.formatter.ObjectFormatter; 4 | 5 | /** 6 | * @author yihua.huang@dianping.com 7 | */ 8 | public class StringTemplateFormatter implements ObjectFormatter { 9 | 10 | private String template; 11 | 12 | @Override 13 | public String format(String raw) throws Exception { 14 | return String.format(template, raw); 15 | } 16 | 17 | @Override 18 | public Class clazz() { 19 | return String.class; 20 | } 21 | 22 | @Override 23 | public void initParam(String[] extra) { 24 | template = extra[0]; 25 | } 26 | } -------------------------------------------------------------------------------- /crawler-example/webmagic-example/src/main/java/io/github/biezhi/webmagic/samples/scheduler/LevelLimitScheduler.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.webmagic.samples.scheduler; 2 | 3 | import us.codecraft.webmagic.Request; 4 | import us.codecraft.webmagic.Task; 5 | import us.codecraft.webmagic.scheduler.PriorityScheduler; 6 | 7 | /** 8 | * @author code4crafter@gmail.com 9 | */ 10 | public class LevelLimitScheduler extends PriorityScheduler { 11 | 12 | private int levelLimit = 3; 13 | 14 | public LevelLimitScheduler(int levelLimit) { 15 | this.levelLimit = levelLimit; 16 | } 17 | 18 | @Override 19 | public synchronized void push(Request request, Task task) { 20 | if (((Integer) request.getExtra("_level")) <= levelLimit) { 21 | super.push(request, task); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /crawler-example/webmagic-example/src/main/resources/crawl.js: -------------------------------------------------------------------------------- 1 | var system = require('system'); 2 | var url = system.args[1]; 3 | 4 | var page = require('webpage').create(); 5 | page.settings.loadImages = false; 6 | page.settings.resourceTimeout = 5000; 7 | 8 | page.open(url, function (status) { 9 | if (status != 'success') { 10 | console.log("HTTP request failed!"); 11 | } else { 12 | console.log(page.content); 13 | } 14 | 15 | page.close(); 16 | phantom.exit(); 17 | }); -------------------------------------------------------------------------------- /crawler-example/webmagic-example/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /crawler-example/webmagic-example/webmagic-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /email-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | email-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /email-example/commons-email-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | commons-email-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /email-example/commons-email-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | email-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | commons-email-example 13 | 14 | 15 | 16 | org.apache.commons 17 | commons-email 18 | 1.5 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /email-example/commons-email-example/src/main/java/io/github/biezhi/email/SendTextExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.email; 2 | 3 | import org.apache.commons.mail.DefaultAuthenticator; 4 | import org.apache.commons.mail.Email; 5 | import org.apache.commons.mail.EmailException; 6 | import org.apache.commons.mail.SimpleEmail; 7 | 8 | /** 9 | * Hello send email 10 | *

11 | * 最简单的邮件发送示例 12 | * 13 | * @author biezhi 14 | * @date 2018/1/15 15 | */ 16 | public class SendTextExample { 17 | 18 | public static void main(String[] args) throws EmailException { 19 | Email email = new SimpleEmail(); 20 | email.setHostName("smtp.googlemail.com"); 21 | email.setSmtpPort(465); 22 | email.setAuthenticator(new DefaultAuthenticator("username", "password")); 23 | email.setSSLOnConnect(true); 24 | email.setFrom("user@gmail.com"); 25 | email.setSubject("TestMail"); 26 | email.setMsg("This is a test mail ... :-)"); 27 | email.addTo("foo@bar.com"); 28 | email.send(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /email-example/commons-email-example/src/main/java/io/github/biezhi/email/SendWithAttachExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.email; 2 | 3 | import org.apache.commons.mail.*; 4 | 5 | /** 6 | * 发送带有附件的电子邮件 7 | * 8 | * @author biezhi 9 | * @date 2018/1/15 10 | */ 11 | public class SendWithAttachExample { 12 | 13 | public static void main(String[] args) throws EmailException { 14 | // 创建附件 15 | EmailAttachment attachment = new EmailAttachment(); 16 | attachment.setPath("mypictures/john.jpg"); 17 | attachment.setDisposition(EmailAttachment.ATTACHMENT); 18 | attachment.setDescription("Picture of John"); 19 | attachment.setName("John"); 20 | 21 | // 创建 Email Message 22 | MultiPartEmail email = new MultiPartEmail(); 23 | email.setHostName("mail.myserver.com"); 24 | email.addTo("jdoe@somewhere.org", "John Doe"); 25 | email.setFrom("me@apache.org", "Me"); 26 | email.setSubject("The picture"); 27 | email.setMsg("Here is the picture you wanted"); 28 | 29 | // 追加附件 30 | email.attach(attachment); 31 | 32 | // 发送 33 | email.send(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /email-example/email-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /email-example/ohmyemail-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | ohmyemail-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /email-example/ohmyemail-example/ohmyemail-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /email-example/ohmyemail-example/src/main/resources/register.html: -------------------------------------------------------------------------------- 1 |

2 |

亲爱的{{ username }}, 欢迎加入JavaChina!

3 |

当您收到这封信的时候,您已经可以正常登录了。

4 |

请点击链接登录首页: http://java-china.org/xxxxx

5 |

如果您的email程序不支持链接点击,请将上面的地址拷贝至您的浏览器(如IE)的地址栏进入。

6 |

如果您还想申请管理员权限,可以联系管理员 {{ email }}

7 |

我们对您产生的不便,深表歉意。

8 |

希望您在JavaChina度过快乐的时光!

9 |

10 |

-----------------------

11 |

12 |

(这是一封自动产生的email,请勿回复。)

13 |
-------------------------------------------------------------------------------- /email-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | email-example 13 | pom 14 | 15 | ohmyemail-example 16 | commons-email-example 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /embedded-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | embedded-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /embedded-example/embedded-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | embedded-jetty-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/README.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | [Jetty 权威指南](http://ykgarfield.github.io/jetty-9.2.3.v20140905-zh/) -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/embedded-jetty-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/src/main/java/io/github/biezhi/jetty/OneConnector.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.jetty; 2 | 3 | import org.eclipse.jetty.server.Server; 4 | import org.eclipse.jetty.server.ServerConnector; 5 | 6 | /** 7 | * 实例化,配置和添加单个的 HTTP connector 实例到 server 8 | */ 9 | public class OneConnector { 10 | public static void main(String[] args) throws Exception { 11 | // The Server 12 | Server server = new Server(); 13 | 14 | // HTTP connector 15 | ServerConnector http = new ServerConnector(server); 16 | http.setHost("localhost"); 17 | http.setPort(8080); 18 | http.setIdleTimeout(30000); 19 | 20 | // Set the connector 21 | server.addConnector(http); 22 | 23 | // Set a handler 24 | server.setHandler(new HelloHandler()); 25 | 26 | // Start the server 27 | server.start(); 28 | server.join(); 29 | } 30 | } -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/src/main/java/io/github/biezhi/jetty/OneServletContext.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.jetty; 2 | 3 | import io.github.biezhi.jetty.servlets.DumpServlet; 4 | import org.eclipse.jetty.server.Server; 5 | import org.eclipse.jetty.servlet.DefaultServlet; 6 | import org.eclipse.jetty.servlet.ServletContextHandler; 7 | 8 | public class OneServletContext { 9 | public static void main(String[] args) throws Exception { 10 | Server server = new Server(8080); 11 | 12 | ServletContextHandler context = new ServletContextHandler( 13 | ServletContextHandler.SESSIONS); 14 | context.setContextPath("/"); 15 | context.setResourceBase(System.getProperty("java.io.tmpdir")); 16 | server.setHandler(context); 17 | 18 | // Add dump servlet 19 | context.addServlet(DumpServlet.class, "/dump/*"); 20 | // Add default servlet 21 | context.addServlet(DefaultServlet.class, "/"); 22 | 23 | server.start(); 24 | server.join(); 25 | } 26 | } -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/src/main/java/io/github/biezhi/jetty/ResourceHandlerFromFileSystem.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.jetty; 2 | 3 | import org.eclipse.jetty.server.Server; 4 | import org.eclipse.jetty.server.handler.ResourceHandler; 5 | import org.eclipse.jetty.util.resource.PathResource; 6 | 7 | import java.io.File; 8 | import java.nio.file.Path; 9 | 10 | public class ResourceHandlerFromFileSystem { 11 | public static void main(String[] args) throws Exception { 12 | Server server = new Server(8080); 13 | 14 | Path webRootPath = new File("webapps/static-root/").toPath().toRealPath(); 15 | 16 | System.err.println("WebRoot is " + webRootPath); 17 | 18 | ResourceHandler handler = new ResourceHandler(); 19 | handler.setBaseResource(new PathResource(webRootPath)); 20 | handler.setDirectoriesListed(true); 21 | 22 | server.setHandler(handler); 23 | 24 | server.start(); 25 | server.join(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/src/main/java/io/github/biezhi/jetty/SimplestServer.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.jetty; 2 | 3 | import org.eclipse.jetty.server.Server; 4 | 5 | /** 6 | * 下面的代码从 SimplestServer.java 实例化和运行最简单可用的 Jetty 服务器: 7 | * 这个运行一个 HTTP 服务器在 8080 端口上.它不是一个有用的服务器,因为它没有 handlers,因此为每个请求返回一个 404 错误. 8 | *

9 | * 1. 创建一个 Server 实例. 10 | * 2. 添加/配置 Connectors. 11 | * 3. 添加/配置 Handlers 和/或 Contexts 和/或 Servlets. 12 | * 4. 启动 Server. 13 | * 5. 在服务器上等待或者使用你的线程做一些其它的事情. 14 | */ 15 | public class SimplestServer { 16 | 17 | public static void main(String[] args) throws Exception { 18 | Server server = new Server(8080); 19 | server.start(); 20 | server.dumpStdErr(); 21 | server.join(); 22 | } 23 | 24 | } -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/src/main/java/io/github/biezhi/jetty/WebAppContextFromFileSystem.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.jetty; 2 | 3 | import org.eclipse.jetty.server.Server; 4 | import org.eclipse.jetty.webapp.WebAppContext; 5 | 6 | import java.io.File; 7 | import java.nio.file.Path; 8 | 9 | public class WebAppContextFromFileSystem { 10 | public static void main(String[] args) throws Exception { 11 | Server server = new Server(8080); 12 | 13 | Path warPath = new File("webapps/hello.war").toPath().toRealPath(); 14 | System.err.println("WAR File is " + warPath); 15 | 16 | WebAppContext webapp = new WebAppContext(); 17 | webapp.setContextPath("/"); 18 | webapp.setWar(warPath.toUri().toASCIIString()); 19 | webapp.setParentLoaderPriority(true); 20 | 21 | server.setHandler(webapp); 22 | 23 | server.start(); 24 | server.join(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/src/main/java/io/github/biezhi/jetty/handlers/HelloHandler.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.jetty.handlers; 2 | 3 | import org.eclipse.jetty.server.Request; 4 | import org.eclipse.jetty.server.handler.AbstractHandler; 5 | 6 | import javax.servlet.ServletException; 7 | import javax.servlet.http.HttpServletRequest; 8 | import javax.servlet.http.HttpServletResponse; 9 | import java.io.IOException; 10 | 11 | public class HelloHandler extends AbstractHandler { 12 | private final String msg; 13 | 14 | public HelloHandler(String msg) { 15 | this.msg = msg; 16 | } 17 | 18 | @Override 19 | public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { 20 | response.setContentType("text/plain"); 21 | response.getWriter().printf("%s%n", msg); 22 | baseRequest.setHandled(true); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/src/main/java/io/github/biezhi/jetty/servlets/HelloServlet.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.jetty.servlets; 2 | 3 | import javax.servlet.ServletConfig; 4 | import javax.servlet.ServletException; 5 | import javax.servlet.http.HttpServlet; 6 | import javax.servlet.http.HttpServletRequest; 7 | import javax.servlet.http.HttpServletResponse; 8 | import java.io.IOException; 9 | 10 | @SuppressWarnings("serial") 11 | public class HelloServlet extends HttpServlet { 12 | private String msg; 13 | 14 | @Override 15 | public void init(ServletConfig config) throws ServletException { 16 | super.init(config); 17 | 18 | msg = config.getInitParameter("message"); 19 | if (msg == null) { 20 | msg = "User"; 21 | } 22 | } 23 | 24 | @Override 25 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 26 | response.setContentType("text/plain"); 27 | response.getWriter().printf("%s%n", msg); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/src/main/resources/hello-webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | hello webapp 7 | 8 | hello 9 | org.eclipse.demo.HelloServlet 10 | 11 | 12 | 13 | hello 14 | /hello 15 | 16 | 17 | 18 | hello.html 19 | 20 | -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/src/main/resources/hello-webapp/hello.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Hello Example 4 | 5 | 6 |

This is the classpath's hello-webapp /hello.html

7 |

8 | See the /hello servlet output 9 | 10 |

11 | 12 | -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/src/main/resources/jetty-logging.properties: -------------------------------------------------------------------------------- 1 | org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog 2 | org.eclipse.jetty.LEVEL=INFO 3 | 4 | org.eclipse.jetty.io.LEVEL=INFO 5 | org.eclipse.jetty.util.component.LEVEL=INFO 6 | org.eclipse.jetty.util.thread.LEVEL=INFO 7 | org.eclipse.jetty.util.resource.LEVEL=DEBUG 8 | org.eclipse.jetty.servlet.LEVEL=DEBUG 9 | org.eclipse.jetty.server.handler.LEVEL=DEBUG 10 | # org.eclipse.jetty.util.ssl.SslContextFactory.LEVEL=DEBUG 11 | # org.eclipse.jetty.io.LEVEL=DEBUG 12 | # org.eclipse.jetty.websocket.LEVEL=DEBUG 13 | # org.eclipse.jetty.websocket.LEVEL=INFO 14 | # org.eclipse.jetty.websocket.LEVEL=WARN 15 | # org.eclipse.jetty.websocket.common.io.LEVEL=DEBUG 16 | 17 | -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/src/main/resources/ssl/keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellokaton/java-library-examples/f3961656748b5bb7dbe52f07925b92f1d3dd58ed/embedded-example/embedded-jetty-example/src/main/resources/ssl/keystore -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/src/main/resources/static-root/hello.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Hello from src/main/resources/static-root/ 4 | 5 | 6 |

Hello from src/main/resources/static-root/

7 | 8 | -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/src/main/resources/websocket-statics/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: sans-serif; 3 | } 4 | 5 | div { 6 | border: 0px solid black; 7 | } 8 | 9 | div#console { 10 | clear: both; 11 | width: 40em; 12 | height: 20em; 13 | overflow: auto; 14 | background-color: #f0f0f0; 15 | padding: 4px; 16 | border: 1px solid black; 17 | } 18 | 19 | div#console .info { 20 | color: black; 21 | } 22 | 23 | div#console .error { 24 | color: red; 25 | } 26 | 27 | div#console .client { 28 | color: blue; 29 | } 30 | 31 | div#console .server { 32 | color: magenta; 33 | } 34 | -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/src/main/webapps/alt-root/alt-hello.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Alt Hello from webapps/alt-root/ 4 | 5 | 6 |

Alt Hello from webapps/alt-root/

7 | 8 | -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/src/main/webapps/alt-root/index.htm: -------------------------------------------------------------------------------- 1 | 2 | 3 | ALT Static Content 4 | 5 | 6 |

Nothing to see here, move along...

7 | 8 | -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/src/main/webapps/static-root/css/main.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-family: sans-serif; 3 | } 4 | 5 | .avatar { 6 | float: left; 7 | } 8 | 9 | .time { 10 | height: 50px; 11 | width: 400px; 12 | background-color: red; 13 | border-radius: 25px; 14 | text-align: center; 15 | vertical-align: middle; 16 | font-size: 25px; 17 | line-height: 50px; 18 | animation: 19 | pulse 3s ease infinite alternate; 20 | } 21 | 22 | @keyframes pulse { 23 | 0%, 100% { 24 | background-color: red; 25 | } 26 | 50% { 27 | background-color: orange; 28 | } 29 | } 30 | 31 | 32 | -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/src/main/webapps/static-root/hello.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Hello from webapps/static-root/ 4 | 5 | 6 |

Hello from webapps/static-root/

7 | 8 | -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/src/main/webapps/static-root/images/jetty-avatar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellokaton/java-library-examples/f3961656748b5bb7dbe52f07925b92f1d3dd58ed/embedded-example/embedded-jetty-example/src/main/webapps/static-root/images/jetty-avatar.png -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/src/main/webapps/static-root/images/jetty-logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellokaton/java-library-examples/f3961656748b5bb7dbe52f07925b92f1d3dd58ed/embedded-example/embedded-jetty-example/src/main/webapps/static-root/images/jetty-logo.png -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/src/main/webapps/static-root/js/jquery-2.1.4.js.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellokaton/java-library-examples/f3961656748b5bb7dbe52f07925b92f1d3dd58ed/embedded-example/embedded-jetty-example/src/main/webapps/static-root/js/jquery-2.1.4.js.gz -------------------------------------------------------------------------------- /embedded-example/embedded-jetty-example/src/main/webapps/static-root/js/jquery.timer.js.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hellokaton/java-library-examples/f3961656748b5bb7dbe52f07925b92f1d3dd58ed/embedded-example/embedded-jetty-example/src/main/webapps/static-root/js/jquery.timer.js.gz -------------------------------------------------------------------------------- /embedded-example/mapdb-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | mapdb-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /embedded-example/mapdb-example/mapdb-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /embedded-example/mapdb-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | embedded-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | mapdb-example 13 | 14 | 15 | -------------------------------------------------------------------------------- /embedded-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | embedded-example 13 | pom 14 | 15 | embedded-jetty-example 16 | mapdb-example 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /encrypt-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | encrypt-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /encrypt-example/encrypt-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /encrypt-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | encrypt-example 13 | 14 | 15 | -------------------------------------------------------------------------------- /excel-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | excel-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /excel-example/excel-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /excel-example/jxl-excel-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | jxl-excel-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /excel-example/jxl-excel-example/jxl-excel-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /excel-example/jxl-excel-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | excel-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | jxl-excel-example 13 | 14 | 15 | -------------------------------------------------------------------------------- /excel-example/poi-excel-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | poi-excel-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /excel-example/poi-excel-example/poi-excel-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /excel-example/poi-excel-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | excel-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | poi-excel-example 13 | 14 | 15 | -------------------------------------------------------------------------------- /excel-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | excel-example 13 | pom 14 | 15 | poi-excel-example 16 | jxl-excel-example 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /gui-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | gui-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /gui-example/gui-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /gui-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | gui-example 13 | 14 | 15 | -------------------------------------------------------------------------------- /http-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | http-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /http-example/http-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /http-example/httpclient4-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | httpclient4-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /http-example/httpclient4-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | http-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | httpclient4-example 13 | 14 | 15 | 16 | org.apache.httpcomponents 17 | httpclient 18 | 4.3.6 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /http-example/httpclient4-example/src/main/java/io/github/biezhi/httpclient4/NoRedirectExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.httpclient4; 2 | 3 | import org.apache.http.client.methods.CloseableHttpResponse; 4 | import org.apache.http.client.methods.HttpGet; 5 | import org.apache.http.impl.client.CloseableHttpClient; 6 | import org.apache.http.impl.client.HttpClientBuilder; 7 | 8 | import java.io.IOException; 9 | 10 | /** 11 | * 禁止重定向 12 | * 13 | * @author biezhi 14 | * @date 2018/1/15 15 | */ 16 | public class NoRedirectExample { 17 | 18 | public static void main(String[] args) throws IOException { 19 | CloseableHttpClient httpclient = HttpClientBuilder.create().disableRedirectHandling().build(); 20 | 21 | try (CloseableHttpResponse response = httpclient.execute(new HttpGet("http://httpbin.org/redirect/6"))) { 22 | System.out.println(response.getStatusLine()); 23 | System.out.println(response.getStatusLine().getStatusCode() == 302); 24 | } 25 | } 26 | 27 | } 28 | -------------------------------------------------------------------------------- /http-example/ohmyrequest-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | ohmyrequest-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /http-example/ohmyrequest-example/ohmyrequest-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /http-example/ohmyrequest-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | http-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | ohmyrequest-example 13 | 14 | 15 | -------------------------------------------------------------------------------- /http-example/okhttp3-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | okhttp3-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /http-example/okhttp3-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | http-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | okhttp3-example 13 | 14 | 15 | 16 | com.squareup.okhttp3 17 | okhttp 18 | 3.9.1 19 | 20 | 21 | 22 | org.riversun 23 | okhttp3-cookie-helper 24 | 1.0.0 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /http-example/okhttp3-example/src/main/java/io/github/biezhi/okhttp3/AuthorizationExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.okhttp3; 2 | 3 | import okhttp3.Credentials; 4 | import okhttp3.OkHttpClient; 5 | import okhttp3.Request; 6 | import okhttp3.Response; 7 | 8 | import java.io.IOException; 9 | 10 | /** 11 | * Authorization 认证示例 12 | * 13 | * @author biezhi 14 | * @date 2018/1/15 15 | */ 16 | public class AuthorizationExample { 17 | 18 | public static void main(String[] args) throws IOException { 19 | OkHttpClient client = new OkHttpClient(); 20 | 21 | Request request = new Request.Builder() 22 | .url("http://httpbin.org/basic-auth/biezhi/passwd") 23 | .addHeader("Authorization", Credentials.basic("biezhi", "passwd")) 24 | .build(); 25 | 26 | try (Response response = client.newCall(request).execute()) { 27 | System.out.println(response.body().string()); 28 | } 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /http-example/okhttp3-example/src/main/java/io/github/biezhi/okhttp3/NoRedirectExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.okhttp3; 2 | 3 | import okhttp3.OkHttpClient; 4 | import okhttp3.Request; 5 | import okhttp3.Response; 6 | 7 | import java.io.IOException; 8 | 9 | /** 10 | * 禁止重定向 11 | * 12 | * @author biezhi 13 | * @date 2018/1/15 14 | */ 15 | public class NoRedirectExample { 16 | 17 | public static void main(String[] args) throws IOException { 18 | 19 | OkHttpClient client = new OkHttpClient().newBuilder() 20 | .followRedirects(false) 21 | .build(); 22 | 23 | Request request = new Request.Builder() 24 | .url("http://t.co/I5YYd9tddw") 25 | .build(); 26 | 27 | try (Response response = client.newCall(request).execute()) { 28 | System.out.println(response.body().string()); 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /http-example/okhttp3-example/src/main/java/io/github/biezhi/okhttp3/PostExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.okhttp3; 2 | 3 | import okhttp3.*; 4 | 5 | import java.io.IOException; 6 | 7 | /** 8 | * 基础 Post 请求示例 9 | * 10 | * @author biezhi 11 | * @date 2018/1/15 12 | */ 13 | public class PostExample { 14 | 15 | public static void main(String[] args) throws IOException { 16 | 17 | OkHttpClient client = new OkHttpClient(); 18 | 19 | RequestBody formBody = new FormBody.Builder() 20 | .add("username", "biezhi") 21 | .add("password", "123456") 22 | .build(); 23 | 24 | Request request = new Request.Builder() 25 | .url("http://httpbin.org/post") 26 | .post(formBody) 27 | .build(); 28 | 29 | try (Response response = client.newCall(request).execute()) { 30 | System.out.println(response.body().string()); 31 | } 32 | 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /http-example/okhttp3-example/src/main/java/io/github/biezhi/okhttp3/TimeoutExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.okhttp3; 2 | 3 | import okhttp3.OkHttpClient; 4 | import okhttp3.Request; 5 | import okhttp3.Response; 6 | 7 | import java.io.IOException; 8 | import java.util.concurrent.TimeUnit; 9 | 10 | /** 11 | * 设置超时 12 | * 13 | * @author biezhi 14 | * @date 2018/1/15 15 | */ 16 | public class TimeoutExample { 17 | 18 | public static void main(String[] args) throws IOException { 19 | 20 | OkHttpClient client = new OkHttpClient.Builder() 21 | .readTimeout(1, TimeUnit.SECONDS) 22 | .build(); 23 | 24 | Request request = new Request.Builder() 25 | .url("http://example.org/delay/2") 26 | .build(); 27 | 28 | try (Response response = client.newCall(request).execute()) { 29 | System.out.println(response.body().string()); 30 | } 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /http-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | http-example 13 | pom 14 | 15 | okhttp3-example 16 | httpclient4-example 17 | ohmyrequest-example 18 | unirest-example 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /http-example/unirest-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | unirest-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /http-example/unirest-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | http-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | unirest-example 13 | 14 | 15 | 16 | com.mashape.unirest 17 | unirest-java 18 | 1.4.9 19 | 20 | 21 | com.fasterxml.jackson.core 22 | jackson-databind 23 | 2.8.9 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /http-example/unirest-example/src/main/java/io/github/biezhi/unirest/AuthenticationExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.unirest; 2 | 3 | import com.mashape.unirest.http.HttpResponse; 4 | import com.mashape.unirest.http.JsonNode; 5 | import com.mashape.unirest.http.Unirest; 6 | import com.mashape.unirest.http.exceptions.UnirestException; 7 | 8 | /** 9 | * Unirest Basic认证示例 10 | * 11 | * @author biezhi 12 | * @date 2018/1/15 13 | */ 14 | public class AuthenticationExample { 15 | 16 | public static void main(String[] args) throws UnirestException { 17 | HttpResponse jsonResponse = Unirest.get("http://httpbin.org/basic-auth/biezhi/123456") 18 | .basicAuth("biezhi", "123456").asJson(); 19 | 20 | System.out.println(jsonResponse.getBody().toString()); 21 | } 22 | } -------------------------------------------------------------------------------- /http-example/unirest-example/src/main/java/io/github/biezhi/unirest/CustomBodyExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.unirest; 2 | 3 | import com.mashape.unirest.http.HttpResponse; 4 | import com.mashape.unirest.http.JsonNode; 5 | import com.mashape.unirest.http.Unirest; 6 | import com.mashape.unirest.http.exceptions.UnirestException; 7 | 8 | /** 9 | * Unirest 自定义Body请求示例 10 | * 11 | * @author biezhi 12 | * @date 2018/1/15 13 | */ 14 | public class CustomBodyExample { 15 | 16 | public static void main(String[] args) throws UnirestException { 17 | HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post") 18 | .header("accept", "application/json") 19 | .body("{\"parameter\":\"value\", \"foo\":\"bar\"}") 20 | .asJson(); 21 | 22 | System.out.println(jsonResponse.getBody().toString()); 23 | } 24 | } -------------------------------------------------------------------------------- /http-example/unirest-example/src/main/java/io/github/biezhi/unirest/FileUploadExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.unirest; 2 | 3 | import com.mashape.unirest.http.HttpResponse; 4 | import com.mashape.unirest.http.JsonNode; 5 | import com.mashape.unirest.http.Unirest; 6 | import com.mashape.unirest.http.exceptions.UnirestException; 7 | 8 | import java.io.File; 9 | 10 | /** 11 | * Unirest 文件上传示例 12 | * 13 | * @author biezhi 14 | * @date 2018/1/15 15 | */ 16 | public class FileUploadExample { 17 | 18 | public static void main(String[] args) throws UnirestException { 19 | HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post") 20 | .header("accept", "application/json") 21 | .field("parameter", "value") 22 | .field("file", new File("/tmp/file")) 23 | .asJson(); 24 | 25 | System.out.println(jsonResponse.getBody().toString()); 26 | } 27 | } -------------------------------------------------------------------------------- /http-example/unirest-example/src/main/java/io/github/biezhi/unirest/RouteParamExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.unirest; 2 | 3 | import com.mashape.unirest.http.HttpResponse; 4 | import com.mashape.unirest.http.JsonNode; 5 | import com.mashape.unirest.http.Unirest; 6 | import com.mashape.unirest.http.exceptions.UnirestException; 7 | 8 | /** 9 | * Unirest 路由参数示例 10 | * 11 | * @author biezhi 12 | * @date 2018/1/15 13 | */ 14 | public class RouteParamExample { 15 | 16 | public static void main(String[] args) throws UnirestException { 17 | HttpResponse response = Unirest.get("http://httpbin.org/{method}") 18 | .routeParam("method", "get") 19 | .queryString("name", "biezhi") 20 | .asJson(); 21 | 22 | System.out.println(response.getBody().toString()); 23 | } 24 | } -------------------------------------------------------------------------------- /http-example/unirest-example/src/main/java/io/github/biezhi/unirest/UnirestExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.unirest; 2 | 3 | import com.mashape.unirest.http.HttpResponse; 4 | import com.mashape.unirest.http.JsonNode; 5 | import com.mashape.unirest.http.Unirest; 6 | import com.mashape.unirest.http.exceptions.UnirestException; 7 | 8 | /** 9 | * Unirest 请求示例 10 | * 11 | * @author biezhi 12 | * @date 2018/1/15 13 | */ 14 | public class UnirestExample { 15 | 16 | public static void main(String[] args) throws UnirestException { 17 | HttpResponse jsonResponse = Unirest.post("http://httpbin.org/post") 18 | .header("accept", "application/json") 19 | .queryString("apiKey", "123") 20 | .field("parameter", "value") 21 | .field("foo", "bar") 22 | .asJson(); 23 | 24 | System.out.println(jsonResponse.getBody().toString()); 25 | } 26 | } -------------------------------------------------------------------------------- /http-example/unirest-example/src/main/java/io/github/biezhi/unirest/model/Author.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.unirest.model; 2 | 3 | /** 4 | * @author biezhi 5 | * @date 2018/1/15 6 | */ 7 | public class Author { 8 | } 9 | -------------------------------------------------------------------------------- /http-example/unirest-example/src/main/java/io/github/biezhi/unirest/model/Book.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.unirest.model; 2 | 3 | import lombok.Data; 4 | 5 | /** 6 | * @author biezhi 7 | * @date 2018/1/15 8 | */ 9 | @Data 10 | public class Book { 11 | private String id; 12 | } 13 | -------------------------------------------------------------------------------- /json-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | json-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /json-example/fastjson-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | fastjson-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /json-example/fastjson-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | json-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | fastjson-example 13 | 14 | 15 | 16 | com.alibaba 17 | fastjson 18 | 1.2.44 19 | 20 | 21 | -------------------------------------------------------------------------------- /json-example/gson-exmaple/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | gson-exmaple 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /json-example/gson-exmaple/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | json-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | gson-exmaple 13 | 14 | 15 | 16 | com.google.code.gson 17 | gson 18 | 2.8.2 19 | 20 | 21 | -------------------------------------------------------------------------------- /json-example/gson-exmaple/src/main/java/io/github/biezhi/json/gson/ArraysAndListsExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.json.gson; 2 | 3 | import com.google.gson.Gson; 4 | import io.github.biezhi.json.gson.model.RestaurantMenuItem; 5 | import io.github.biezhi.json.gson.model.RestaurantWithMenu; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | /** 11 | * @author biezhi 12 | * @date 2018/1/26 13 | */ 14 | public class ArraysAndListsExample { 15 | 16 | public static void main(String[] args) { 17 | List menu = new ArrayList<>(); 18 | menu.add(new RestaurantMenuItem("Spaghetti", 7.99f)); 19 | menu.add(new RestaurantMenuItem("Steak", 12.99f)); 20 | menu.add(new RestaurantMenuItem("Salad", 5.99f)); 21 | 22 | RestaurantWithMenu restaurant = new RestaurantWithMenu("Future Studio Steak House", menu); 23 | 24 | Gson gson = new Gson(); 25 | String restaurantJson = gson.toJson(restaurant); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /json-example/gson-exmaple/src/main/java/io/github/biezhi/json/gson/ExposeExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.json.gson; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.GsonBuilder; 5 | import io.github.biezhi.json.gson.model.UserSimple; 6 | 7 | /** 8 | * 使用 @Expose 忽略字段 9 | * 10 | * @author biezhi 11 | * @date 2018/2/2 12 | */ 13 | public class ExposeExample { 14 | 15 | public static void main(String[] args) { 16 | 17 | GsonBuilder builder = new GsonBuilder(); 18 | builder.excludeFieldsWithoutExposeAnnotation(); 19 | Gson gson = builder.create(); 20 | 21 | UserSimple userSimple = new UserSimple("biezhi", "biezhi.me@gmail.com", 18, true); 22 | 23 | System.out.println(gson.toJson(userSimple)); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /json-example/gson-exmaple/src/main/java/io/github/biezhi/json/gson/FloatExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.json.gson; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.GsonBuilder; 5 | import io.github.biezhi.json.gson.model.UserFloat; 6 | 7 | /** 8 | * 解析特殊类型 Float 和 Double 9 | * 10 | * @author biezhi 11 | * @date 2018/2/2 12 | */ 13 | public class FloatExample { 14 | public static void main(String[] args) { 15 | UserFloat user = new UserFloat("Norman", Float.POSITIVE_INFINITY); 16 | 17 | Gson gson = new Gson(); 18 | 19 | // will throw an exception 20 | // String usersJson = gson.toJson(user); 21 | // System.out.println("userJson:" + usersJson); 22 | 23 | GsonBuilder gsonBuilder = new GsonBuilder(); 24 | gsonBuilder.serializeSpecialFloatingPointValues(); 25 | gson = gsonBuilder.create(); 26 | UserFloat userFloat = new UserFloat("Norman", Float.POSITIVE_INFINITY); 27 | String usersJson = gson.toJson(userFloat); 28 | System.out.println("userJson:" + usersJson); 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /json-example/gson-exmaple/src/main/java/io/github/biezhi/json/gson/SerializeCollections.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.json.gson; 2 | 3 | import java.lang.reflect.Type; 4 | import java.util.Arrays; 5 | import java.util.Collection; 6 | 7 | import com.google.gson.Gson; 8 | import com.google.gson.GsonBuilder; 9 | import com.google.gson.reflect.TypeToken; 10 | 11 | /** 12 | * 序列化、发序列化集合 13 | * 14 | * @author biezhi 15 | * @date 2018/1/16 16 | */ 17 | public class SerializeCollections { 18 | 19 | public static void main(String[] args) { 20 | Gson gson = new GsonBuilder().create(); 21 | Collection integers = Arrays.asList(1, 2, 3); 22 | 23 | // serialization => [1,2,3] 24 | gson.toJson(integers); 25 | 26 | // deserialization 27 | Type collectionType = new TypeToken>() {}.getType(); 28 | Collection integers2 = gson.fromJson("[1,2,3]", collectionType); 29 | System.out.println(integers2); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /json-example/gson-exmaple/src/main/java/io/github/biezhi/json/gson/SerializeEnums.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.json.gson; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.GsonBuilder; 5 | 6 | import io.github.biezhi.json.gson.model.Health; 7 | 8 | /** 9 | * 序列化、发序列化枚举 10 | * 11 | * @author biezhi 12 | * @date 2018/1/16 13 | */ 14 | public class SerializeEnums { 15 | 16 | public static void main(String[] args) { 17 | Health health = new Health("host", "ip", Health.Status.UP); 18 | Gson gson = new GsonBuilder().setPrettyPrinting().create(); 19 | String result = gson.toJson(health); 20 | System.out.println(result); 21 | 22 | String input = "{\n" + 23 | " \"hostname\": \"host\",\n" + 24 | " \"ip\": \"ip\",\n" + 25 | " \"startTime\": 1457088308405,\n" + 26 | " \"upTime\": 62,\n" + 27 | " \"status\": \"1\"\n" + 28 | "}"; 29 | Health health2 = gson.fromJson(input, Health.class); 30 | System.out.println(health2); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /json-example/gson-exmaple/src/main/java/io/github/biezhi/json/gson/model/Animal.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.json.gson.model; 2 | 3 | public class Animal { 4 | 5 | private T animal; 6 | 7 | public T getAnimal() { 8 | return animal; 9 | } 10 | 11 | public void setAnimal(T animal) { 12 | this.animal = animal; 13 | } 14 | } -------------------------------------------------------------------------------- /json-example/gson-exmaple/src/main/java/io/github/biezhi/json/gson/model/Box.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.json.gson.model; 2 | 3 | public class Box { 4 | 5 | private T boxContent; 6 | 7 | public Box(T t) { 8 | this.boxContent = t; 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /json-example/gson-exmaple/src/main/java/io/github/biezhi/json/gson/model/Dog.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.json.gson.model; 2 | 3 | public class Dog { 4 | 5 | private String name; 6 | 7 | public Dog(String name) { 8 | this.name = name; 9 | } 10 | 11 | public String getName() { 12 | return name; 13 | } 14 | } -------------------------------------------------------------------------------- /json-example/gson-exmaple/src/main/java/io/github/biezhi/json/gson/model/RestaurantMenuItem.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.json.gson.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.NoArgsConstructor; 5 | 6 | @NoArgsConstructor 7 | @AllArgsConstructor 8 | public class RestaurantMenuItem { 9 | String description; 10 | float price; 11 | } -------------------------------------------------------------------------------- /json-example/gson-exmaple/src/main/java/io/github/biezhi/json/gson/model/RestaurantWithMenu.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.json.gson.model; 2 | 3 | import lombok.AllArgsConstructor; 4 | import lombok.NoArgsConstructor; 5 | 6 | import java.util.List; 7 | 8 | @NoArgsConstructor 9 | @AllArgsConstructor 10 | public class RestaurantWithMenu { 11 | String name; 12 | 13 | List menu; 14 | //RestaurantMenuItem[] menu; // alternative, either one is fine 15 | } -------------------------------------------------------------------------------- /json-example/gson-exmaple/src/main/java/io/github/biezhi/json/gson/model/UserFloat.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.json.gson.model; 2 | 3 | public class UserFloat { 4 | String name; 5 | Float weight; 6 | 7 | public UserFloat(String name, Float weight) { 8 | this.name = name; 9 | this.weight = weight; 10 | } 11 | } -------------------------------------------------------------------------------- /json-example/gson-exmaple/src/main/java/io/github/biezhi/json/gson/model/UserSimple.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.json.gson.model; 2 | 3 | import com.google.gson.annotations.Expose; 4 | import lombok.AllArgsConstructor; 5 | import lombok.Data; 6 | import lombok.NoArgsConstructor; 7 | 8 | @Data 9 | @NoArgsConstructor 10 | @AllArgsConstructor 11 | public class UserSimple { 12 | 13 | /** 14 | * equals serialize & deserialize 15 | */ 16 | @Expose() 17 | String name; 18 | 19 | /** 20 | * equals neither serialize nor deserialize 21 | */ 22 | @Expose(serialize = false, deserialize = false) 23 | String email; 24 | 25 | /** 26 | * equals only deserialize 27 | */ 28 | @Expose(serialize = false) 29 | int age; 30 | 31 | /** 32 | * equals only serialize 33 | * 34 | * 使用 transient 来描述字段,将不能被序列化和反序列化 35 | */ 36 | @Expose(deserialize = false) 37 | /*transient*/ boolean isDeveloper; 38 | 39 | } -------------------------------------------------------------------------------- /json-example/jackson-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | jackson-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /json-example/jackson-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | json-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | jackson-example 13 | 14 | 15 | 16 | com.fasterxml.jackson.core 17 | jackson-databind 18 | 2.8.9 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /json-example/jackson-example/src/main/java/io/github/biezhi/json/jackson/AnnotationFieldExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.json.jackson; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import io.github.biezhi.json.jackson.model.Employee; 5 | import io.github.biezhi.utils.PrintUtils; 6 | 7 | import java.io.IOException; 8 | 9 | /** 10 | * Jackson 注解设置JSON字段示例 11 | * 12 | * @author biezhi 13 | * @date 2018/1/15 14 | */ 15 | public class AnnotationFieldExample { 16 | 17 | private static final ObjectMapper mapper = new ObjectMapper(); 18 | 19 | public static void main(String[] args) throws IOException { 20 | Employee employee = new Employee(); 21 | employee.setName("biezhi"); 22 | employee.setDept("Admin"); 23 | 24 | String jsonString = mapper.writeValueAsString(employee); 25 | PrintUtils.print("转换成JSON", jsonString); 26 | 27 | Employee e = mapper.readValue(jsonString, Employee.class); 28 | PrintUtils.print("JSON转换为对象", e); 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /json-example/jackson-example/src/main/java/io/github/biezhi/json/jackson/FileReadWriteExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.json.jackson; 2 | 3 | import com.fasterxml.jackson.core.type.TypeReference; 4 | import com.fasterxml.jackson.databind.ObjectMapper; 5 | import io.github.biezhi.model.Person; 6 | import io.github.biezhi.utils.BeanData; 7 | import io.github.biezhi.utils.PrintUtils; 8 | 9 | import java.io.File; 10 | import java.io.IOException; 11 | import java.util.List; 12 | 13 | /** 14 | * Jackson 文件读写示例 15 | * 16 | * @author biezhi 17 | * @date 2018/1/15 18 | */ 19 | public class FileReadWriteExample { 20 | 21 | private static final ObjectMapper mapper = new ObjectMapper(); 22 | 23 | public static void main(String[] args) throws IOException { 24 | List persons = BeanData.randPersons(1); 25 | mapper.writeValue(new File("jackson_persons.json"), persons); 26 | 27 | List personList = mapper.readValue(new File("jackson_persons.json"), new TypeReference>(){}); 28 | PrintUtils.print("写入文件读取JSON数据", persons.size() == personList.size()); 29 | PrintUtils.print("写入文件读取JSON数据", personList); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /json-example/jackson-example/src/main/java/io/github/biezhi/json/jackson/IgnoreUnknownExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.json.jackson; 2 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; 4 | import io.github.biezhi.json.jackson.model.Employee4; 5 | import io.github.biezhi.utils.PrintUtils; 6 | 7 | import java.io.IOException; 8 | 9 | /** 10 | * Jackson 注解忽略未知字段示例 11 | * 12 | * @author biezhi 13 | * @date 2018/1/15 14 | */ 15 | public class IgnoreUnknownExample { 16 | 17 | private static final ObjectMapper mapper = new ObjectMapper(); 18 | 19 | public static void main(String[] args) throws IOException { 20 | String s = "{\"name\":\"biezhi\",\"phone\":\"111-111-1111\"}"; 21 | System.out.println("JSON input: " + s); 22 | Employee4 e2 = mapper.readValue(s, Employee4.class); 23 | PrintUtils.print("JSON转换为对象", e2); 24 | } 25 | 26 | } 27 | -------------------------------------------------------------------------------- /json-example/jackson-example/src/main/java/io/github/biezhi/json/jackson/model/Employee.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.json.jackson.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonProperty; 4 | import lombok.Data; 5 | 6 | @Data 7 | public class Employee { 8 | 9 | @JsonProperty("employee-name") 10 | private String name; 11 | 12 | @JsonProperty("employee-dept") 13 | private String dept; 14 | 15 | } -------------------------------------------------------------------------------- /json-example/jackson-example/src/main/java/io/github/biezhi/json/jackson/model/Employee2.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.json.jackson.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnore; 4 | import lombok.Data; 5 | 6 | @Data 7 | public class Employee2 { 8 | 9 | private String name; 10 | 11 | private String dept; 12 | 13 | @JsonIgnore 14 | private String address; 15 | } -------------------------------------------------------------------------------- /json-example/jackson-example/src/main/java/io/github/biezhi/json/jackson/model/Employee3.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.json.jackson.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import lombok.Data; 5 | 6 | @Data 7 | @JsonIgnoreProperties({"dept", "address"}) 8 | public class Employee3 { 9 | 10 | private String name; 11 | private String dept; 12 | private String address; 13 | } -------------------------------------------------------------------------------- /json-example/jackson-example/src/main/java/io/github/biezhi/json/jackson/model/Employee4.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.json.jackson.model; 2 | 3 | import com.fasterxml.jackson.annotation.JsonIgnoreProperties; 4 | import lombok.Data; 5 | 6 | @Data 7 | @JsonIgnoreProperties(ignoreUnknown = true) 8 | public class Employee4 { 9 | 10 | private String name; 11 | private String dept; 12 | private String address; 13 | 14 | } -------------------------------------------------------------------------------- /json-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | json-example 13 | pom 14 | 15 | 16 | fastjson-example 17 | gson-exmaple 18 | jackson-example 19 | 20 | 21 | 22 | 23 | io.github.biezhi 24 | common-beans 25 | 1.0-SNAPSHOT 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /log-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | log-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /log-example/commons-logging-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | commons-logging-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /log-example/commons-logging-example/commons-logging-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /log-example/commons-logging-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | log-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | commons-logging-example 13 | 14 | 15 | 16 | commons-logging 17 | commons-logging 18 | 1.2 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /log-example/commons-logging-example/src/main/java/io/github/biezhi/commons/logging/Example1.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.commons.logging; 2 | 3 | import org.apache.commons.logging.Log; 4 | import org.apache.commons.logging.LogFactory; 5 | 6 | /** 7 | * 基础示例 8 | */ 9 | public class Example1 { 10 | 11 | private static Log log = LogFactory.getLog(Example1.class); 12 | 13 | public static void main(String[] args) { 14 | // debug不输出,默认为 info 级别 15 | log.debug("我爱编程,编程使我快乐。"); 16 | log.info("我爱编程,编程使我快乐。"); 17 | log.warn("我爱编程,编程使我快乐。"); 18 | log.error("我爱编程,编程使我快乐。"); 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /log-example/commons-logging-example/src/main/java/io/github/biezhi/commons/logging/Example2.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.commons.logging; 2 | 3 | import org.apache.commons.logging.Log; 4 | import org.apache.commons.logging.LogFactory; 5 | 6 | /** 7 | * 自定义属性 8 | *

9 | * 自定义日期格式化 10 | */ 11 | public class Example2 { 12 | private static Log log = null; 13 | 14 | static { 15 | System.setProperty("java.util.logging.SimpleFormatter.format", "[%1$tF %1$tT] [%4$s] %5$s %n"); 16 | log = LogFactory.getLog(Example2.class); 17 | } 18 | 19 | public static void main(String[] args) { 20 | log.info("我爱编程,编程使我快乐。"); 21 | } 22 | 23 | } -------------------------------------------------------------------------------- /log-example/log-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /log-example/log4j-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | log4j-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /log-example/log4j-example/log4j-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /log-example/log4j-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | log-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | log4j-example 13 | 14 | 15 | 16 | log4j 17 | log4j 18 | 1.2.17 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /log-example/log4j-example/src/main/java/io/github/biezhi/log4j/Example.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.log4j; 2 | 3 | import org.apache.log4j.Logger; 4 | 5 | public class Example { 6 | 7 | final static Logger LOGGER = Logger.getLogger(Example.class); 8 | 9 | public static void main(String[] args) { 10 | LOGGER.debug("我爱编程,编程使我快乐。"); 11 | LOGGER.info("我爱编程,编程使我快乐。"); 12 | LOGGER.warn("我爱编程,编程使我快乐。"); 13 | LOGGER.error("我爱编程,编程使我快乐。"); 14 | } 15 | 16 | } -------------------------------------------------------------------------------- /log-example/log4j-example/src/main/resources/log4j.properties: -------------------------------------------------------------------------------- 1 | # Set root logger level to DEBUG. myAppender is a reference (can be any name) 2 | log4j.rootLogger=DEBUG, myAppender 3 | # myAppender is set to be a ConsoleAppender. 4 | log4j.appender.myAppender=org.apache.log4j.ConsoleAppender 5 | # Assigning layout pattern to myAppender. 6 | log4j.appender.myAppender.layout=org.apache.log4j.PatternLayout 7 | # Formatting pattern, see also org.apache.log4j.PatternLayout docs for right side specifiers: 8 | log4j.appender.myAppender.layout.ConversionPattern=%d{yy-MM-dd HH:mm:ss:SSS} %5p %t %c{2}:%L - %m%n 9 | 10 | # 保存文件 11 | 12 | #log4j.rootLogger=INFO, myFile 13 | #log4j.appender.myFile=org.apache.log4j.FileAppender 14 | #log4j.appender.myFile.File=d:\\logs\\someName.txt 15 | #log4j.appender.myFile.layout=org.apache.log4j.PatternLayout 16 | #log4j.appender.myFile.layout.ConversionPattern=%d{yy-MM-dd HH:mm:ss:SSS} %5p %t %c{2}:%L - %m%n -------------------------------------------------------------------------------- /log-example/logback-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | logback-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /log-example/logback-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | log-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | logback-example 13 | 14 | 15 | 16 | ch.qos.logback 17 | logback-classic 18 | 1.2.3 19 | 20 | 21 | -------------------------------------------------------------------------------- /log-example/logback-example/src/main/java/io/github/biezhi/logback/LogbackExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.logback; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | public class LogbackExample { 7 | 8 | private final static Logger LOGGER = LoggerFactory.getLogger(LogbackExample.class); 9 | 10 | public static void main(String[] args) { 11 | LOGGER.debug("我爱编程,编程使我快乐。"); 12 | LOGGER.info("我爱编程,编程使我快乐。"); 13 | LOGGER.warn("我爱编程,编程使我快乐。"); 14 | LOGGER.error("我爱编程,编程使我快乐。"); 15 | } 16 | 17 | } -------------------------------------------------------------------------------- /log-example/logback-example/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n 8 | 9 | 10 | 11 | 12 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /log-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | log-example 13 | pom 14 | 15 | log4j-example 16 | logback-example 17 | commons-logging-example 18 | slf4j-example 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /log-example/slf4j-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | slf4j-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /log-example/slf4j-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | log-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | slf4j-example 13 | 14 | 15 | 16 | org.slf4j 17 | slf4j-api 18 | 1.7.25 19 | 20 | 21 | ch.qos.logback 22 | logback-classic 23 | 1.2.3 24 | 25 | 26 | -------------------------------------------------------------------------------- /log-example/slf4j-example/src/main/java/io/github/biezhi/slf4j/Hello.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.slf4j; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | /** 7 | * @author biezhi 8 | * @date 2018/1/16 9 | */ 10 | public class Hello { 11 | 12 | private static Logger LOGGER = LoggerFactory.getLogger(Hello.class); 13 | 14 | public static void doSomething() { 15 | LOGGER.info("在 Hello 类中的 INFO 消息"); 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /log-example/slf4j-example/src/main/java/io/github/biezhi/slf4j/Slf4jExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.slf4j; 2 | 3 | import org.slf4j.Logger; 4 | import org.slf4j.LoggerFactory; 5 | 6 | /** 7 | * Slf4j + logback 示例 8 | * 9 | * @author biezhi 10 | * @date 2018/1/16 11 | */ 12 | public class Slf4jExample { 13 | 14 | private static final Logger LOGGER = LoggerFactory.getLogger(Slf4jExample.class); 15 | 16 | public static void main(String[] args) { 17 | LOGGER.debug("我爱编程,编程使我快乐。"); 18 | LOGGER.info("我爱编程,编程使我快乐。"); 19 | LOGGER.warn("我爱编程,编程使我快乐。"); 20 | LOGGER.error("我爱编程,编程使我快乐。"); 21 | Hello.doSomething(); 22 | } 23 | 24 | } 25 | -------------------------------------------------------------------------------- /log-example/slf4j-example/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | %d{yyyy-MM-dd HH:mm:ss:SSS} %5p %t %c{2}:%L - %m%n 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /metrics-example/README.md: -------------------------------------------------------------------------------- 1 | 2 | - [Metrics 是个什么鬼 之入门教程](http://wuchong.me/blog/2015/08/01/getting-started-with-metrics/) 3 | - [Metrics介绍和Spring的集成](http://colobu.com/2014/08/08/Metrics-and-Spring-Integration/) 4 | 5 | -------------------------------------------------------------------------------- /metrics-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | metrics-example 13 | 14 | 15 | 16 | io.dropwizard.metrics 17 | metrics-core 18 | 4.0.2 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /metrics-example/src/main/java/io/github/biezhi/metrics/GaugeExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.metrics; 2 | 3 | import com.codahale.metrics.ConsoleReporter; 4 | import com.codahale.metrics.Gauge; 5 | import com.codahale.metrics.MetricRegistry; 6 | 7 | import java.util.LinkedList; 8 | import java.util.Queue; 9 | import java.util.concurrent.TimeUnit; 10 | 11 | /** 12 | * 衡量一个待处理队列中任务的个数 13 | */ 14 | public class GaugeExample { 15 | 16 | public static Queue q = new LinkedList<>(); 17 | 18 | public static void main(String[] args) throws InterruptedException { 19 | MetricRegistry registry = new MetricRegistry(); 20 | ConsoleReporter reporter = ConsoleReporter.forRegistry(registry).build(); 21 | reporter.start(1, TimeUnit.SECONDS); 22 | registry.register(MetricRegistry.name(GaugeExample.class, "queue", "size"), 23 | (Gauge) () -> q.size()); 24 | 25 | while (true) { 26 | Thread.sleep(1000); 27 | q.add("Job-xxx"); 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /metrics-example/src/main/java/io/github/biezhi/metrics/TimerExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.metrics; 2 | 3 | import com.codahale.metrics.ConsoleReporter; 4 | import com.codahale.metrics.MetricRegistry; 5 | import com.codahale.metrics.Timer; 6 | 7 | import java.util.Random; 8 | import java.util.concurrent.TimeUnit; 9 | 10 | /** 11 | * Timer其实是 Histogram 和 Meter 的结合, histogram 某部分代码/调用的耗时, meter统计TPS。 12 | */ 13 | public class TimerExample { 14 | 15 | public static Random random = new Random(); 16 | 17 | public static void main(String[] args) throws InterruptedException { 18 | MetricRegistry registry = new MetricRegistry(); 19 | ConsoleReporter reporter = ConsoleReporter.forRegistry(registry).build(); 20 | reporter.start(1, TimeUnit.SECONDS); 21 | Timer timer = registry.timer(MetricRegistry.name(TimerExample.class, "get-latency")); 22 | Timer.Context ctx; 23 | while (true) { 24 | ctx = timer.time(); 25 | Thread.sleep(random.nextInt(1000)); 26 | ctx.stop(); 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /mq-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | mq-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /mq-example/kafka-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | kafka-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /mq-example/kafka-example/kafka-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /mq-example/kafka-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | mq-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | kafka-example 13 | 14 | 15 | -------------------------------------------------------------------------------- /mq-example/mq-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /mq-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | mq-example 13 | pom 14 | 15 | kafka-example 16 | rocketmq-example 17 | rabbitmq-example 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /mq-example/rabbitmq-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | rabbitmq-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /mq-example/rabbitmq-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | mq-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | rabbitmq-example 13 | 14 | 15 | -------------------------------------------------------------------------------- /mq-example/rabbitmq-example/rabbitmq-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /mq-example/rocketmq-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | rocketmq-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /mq-example/rocketmq-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | mq-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | rocketmq-example 13 | 14 | 15 | -------------------------------------------------------------------------------- /mq-example/rocketmq-example/rocketmq-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /network-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | network-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /network-example/mina-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | mina-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /network-example/mina-example/mina-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /network-example/mina-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | network-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | mina-example 13 | 14 | 15 | -------------------------------------------------------------------------------- /network-example/netty-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | netty-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /network-example/netty-example/netty-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /network-example/netty-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | network-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | netty-example 13 | 14 | 15 | -------------------------------------------------------------------------------- /network-example/network-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /network-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | network-example 13 | pom 14 | 15 | netty-example 16 | mina-example 17 | 18 | 19 | 20 | -------------------------------------------------------------------------------- /orm-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | orm-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /orm-example/blade-jdbc-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | blade-jdbc-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /orm-example/blade-jdbc-example/blade-jdbc-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /orm-example/blade-jdbc-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | orm-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | blade-jdbc-example 13 | 14 | 15 | -------------------------------------------------------------------------------- /orm-example/dbutils-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | dbutils-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /orm-example/dbutils-example/dbutils-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /orm-example/dbutils-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | orm-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | dbutils-example 13 | 14 | 15 | -------------------------------------------------------------------------------- /orm-example/hibernate-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | hibernate-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /orm-example/hibernate-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | orm-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | hibernate-example 13 | 14 | 15 | 16 | org.hibernate 17 | hibernate-core 18 | 5.2.10.Final 19 | 20 | 21 | com.h2database 22 | h2 23 | 1.4.193 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /orm-example/hibernate-example/src/main/java/io/github/biezhi/hibernate/Person.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.hibernate; 2 | 3 | import lombok.Data; 4 | import javax.persistence.Column; 5 | import javax.persistence.Entity; 6 | import javax.persistence.GeneratedValue; 7 | import javax.persistence.Id; 8 | 9 | /** 10 | * @author biezhi 11 | * @date 2018/1/16 12 | */ 13 | @Data 14 | @Entity 15 | public class Person { 16 | @Id 17 | @GeneratedValue 18 | private int id; 19 | @Column(name = "FULL_NAME") 20 | private String name; 21 | private int age; 22 | 23 | public Person() { 24 | } 25 | 26 | public Person(String name, int age) { 27 | this.name = name; 28 | this.age = age; 29 | } 30 | } -------------------------------------------------------------------------------- /orm-example/hibernate-example/src/main/resources/hibernate.cfg.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | 7 | 8 | org.h2.Driver 9 | jdbc:h2:mem:test;DB_CLOSE_DELAY=-1 10 | org.hibernate.dialect.H2Dialect 11 | true 12 | create 13 | 14 | 15 | -------------------------------------------------------------------------------- /orm-example/jooq-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | jooq-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /orm-example/jooq-example/jooq-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /orm-example/jooq-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | orm-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | jooq-example 13 | 14 | 15 | -------------------------------------------------------------------------------- /orm-example/mybatis-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | mybatis-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /orm-example/mybatis-example/src/main/java/io/github/biezhi/mybatis/mapper/VillageMapper.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.mybatis.mapper; 2 | 3 | import org.apache.ibatis.annotations.Update; 4 | 5 | /** 6 | * @author biezhi 7 | * @date 2018/1/16 8 | */ 9 | public interface VillageMapper { 10 | @Update("CREATE TABLE `village` (\n" + 11 | "\t`id` INT(10) NOT NULL AUTO_INCREMENT,\n" + 12 | "\t`name` VARCHAR(50) NULL DEFAULT NULL,\n" + 13 | "\t`district` VARCHAR(50) NULL DEFAULT NULL,\n" + 14 | "\tPRIMARY KEY (`id`)\n" + 15 | ")") 16 | void schema(); 17 | } 18 | -------------------------------------------------------------------------------- /orm-example/mybatis-example/src/main/java/io/github/biezhi/mybatis/model/TransactionToken.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.mybatis.model; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class TransactionToken { 7 | private Long id = -1L; 8 | private String transaction = ""; 9 | private String token = ""; 10 | 11 | } -------------------------------------------------------------------------------- /orm-example/mybatis-example/src/main/java/io/github/biezhi/mybatis/model/Village.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.mybatis.model; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class Village { 7 | private Integer id; 8 | private String name; 9 | private String district; 10 | } -------------------------------------------------------------------------------- /orm-example/mybatis-example/src/main/java/io/github/biezhi/mybatis/utils/MyBatisUtil.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.mybatis.utils; 2 | 3 | import io.github.biezhi.mybatis.mapper.TransactionTokenMapper; 4 | import org.apache.ibatis.io.Resources; 5 | import org.apache.ibatis.session.SqlSessionFactory; 6 | import org.apache.ibatis.session.SqlSessionFactoryBuilder; 7 | 8 | import java.io.IOException; 9 | import java.io.InputStream; 10 | 11 | public class MyBatisUtil { 12 | 13 | private static SqlSessionFactory sqlSessionFactory; 14 | 15 | static { 16 | String resource = "mybatis-config.xml"; 17 | InputStream inputStream; 18 | try { 19 | inputStream = Resources.getResourceAsStream(resource); 20 | sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream); 21 | sqlSessionFactory.getConfiguration().addMapper(TransactionTokenMapper.class); 22 | } catch (IOException e) { 23 | e.printStackTrace(); 24 | } 25 | } 26 | 27 | public static SqlSessionFactory getSqlSessionFactory() { 28 | return sqlSessionFactory; 29 | } 30 | } -------------------------------------------------------------------------------- /orm-example/mybatis-example/src/main/resources/log4j.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /orm-example/orm-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /orm-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | orm-example 13 | pom 14 | 15 | mybatis-example 16 | hibernate-example 17 | sql2o-example 18 | dbutils-example 19 | blade-jdbc-example 20 | jooq-example 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /orm-example/sql2o-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | sql2o-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /orm-example/sql2o-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | orm-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | sql2o-example 13 | 14 | 15 | -------------------------------------------------------------------------------- /orm-example/sql2o-example/sql2o-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /qrcode-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | qrcode-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /qrcode-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | qrcode-example 13 | pom 14 | 15 | 16 | zxing-example 17 | qrgen-example 18 | 19 | 20 | -------------------------------------------------------------------------------- /qrcode-example/qrcode-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /qrcode-example/qrgen-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | qrgen-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /qrcode-example/qrgen-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | qrcode-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | qrgen-example 13 | 14 | 15 | 16 | net.glxn.qrgen 17 | javase 18 | 2.0 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /qrcode-example/qrgen-example/src/main/java/io/github/biezhi/qrgen/URLQRCodeExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.qrgen; 2 | 3 | import net.glxn.qrgen.core.image.ImageType; 4 | import net.glxn.qrgen.javase.QRCode; 5 | import java.io.*; 6 | 7 | public class URLQRCodeExample { 8 | 9 | public static void main(String... args){ 10 | ByteArrayOutputStream bout = 11 | QRCode.from("https://github.com/biezhi") 12 | .withSize(250, 250) 13 | .to(ImageType.PNG) 14 | .stream(); 15 | try { 16 | OutputStream out = new FileOutputStream("qr-code.png"); 17 | bout.writeTo(out); 18 | out.flush(); 19 | out.close(); 20 | 21 | } catch (IOException e) { 22 | e.printStackTrace(); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /qrcode-example/zxing-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | zxing-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /qrcode-example/zxing-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | qrcode-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | zxing-example 13 | 14 | 15 | 16 | com.google.zxing 17 | core 18 | 3.3.1 19 | 20 | 21 | com.google.zxing 22 | javase 23 | 3.3.1 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /rss-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | rss-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /rss-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | rss-example 13 | 14 | 15 | -------------------------------------------------------------------------------- /rss-example/rss-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /task-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | task-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /task-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | task-example 13 | pom 14 | 15 | quartz-example 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /task-example/quartz-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | quartz-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /task-example/quartz-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | task-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | quartz-example 13 | 14 | 15 | 16 | org.quartz-scheduler 17 | quartz 18 | 2.3.0 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /task-example/quartz-example/src/main/java/io/github/biezhi/quartz/CronTriggerExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.quartz; 2 | 3 | import io.github.biezhi.quartz.job.HelloJob; 4 | import org.quartz.*; 5 | import org.quartz.impl.StdSchedulerFactory; 6 | 7 | import java.time.LocalDateTime; 8 | 9 | /** 10 | * cron 表达式触发器例子 11 | */ 12 | public class CronTriggerExample { 13 | 14 | public static void main(String[] args) throws SchedulerException, InterruptedException { 15 | 16 | JobDetail job = JobBuilder.newJob(HelloJob.class).withIdentity("myjob1", "mygroup1").build(); 17 | System.out.println("启动时间: " + LocalDateTime.now().toString()); 18 | 19 | // 每5秒调用一次 20 | Trigger trigger = TriggerBuilder.newTrigger().withIdentity("mytrigger2", "mygroup2") 21 | .withSchedule(CronScheduleBuilder.cronSchedule("0/5 * * * * ?")) 22 | .build(); 23 | 24 | Scheduler scheduler = new StdSchedulerFactory().getScheduler(); 25 | scheduler.start(); 26 | scheduler.scheduleJob(job, trigger); 27 | // 30 秒后关闭 28 | Thread.sleep(30_000); 29 | scheduler.shutdown(true); 30 | } 31 | } -------------------------------------------------------------------------------- /task-example/quartz-example/src/main/java/io/github/biezhi/quartz/job/ExceptionJob.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.quartz.job; 2 | 3 | import org.quartz.Job; 4 | import org.quartz.JobExecutionContext; 5 | import org.quartz.JobExecutionException; 6 | 7 | public class ExceptionJob implements Job { 8 | 9 | @Override 10 | public void execute(JobExecutionContext context) throws JobExecutionException { 11 | System.out.println("五秒一次的体验..."); 12 | throw new JobExecutionException("异常消息: XXX出错了"); 13 | } 14 | 15 | } -------------------------------------------------------------------------------- /task-example/quartz-example/src/main/java/io/github/biezhi/quartz/job/HelloJob.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.quartz.job; 2 | 3 | import java.time.LocalDateTime; 4 | 5 | import org.quartz.Job; 6 | import org.quartz.JobDetail; 7 | import org.quartz.JobExecutionContext; 8 | import org.quartz.JobKey; 9 | 10 | public class HelloJob implements Job { 11 | 12 | @Override 13 | public void execute(JobExecutionContext context) { 14 | JobDetail jobDetail = context.getJobDetail(); 15 | JobKey key = jobDetail.getKey(); 16 | System.out.println("当前 Job Key: " + key + ", 当前时间: " + LocalDateTime.now().toString()); 17 | } 18 | 19 | } -------------------------------------------------------------------------------- /task-example/task-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /template-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | template-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /template-example/freemarker-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | freemarker-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /template-example/freemarker-example/freemarker-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /template-example/freemarker-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | template-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | freemarker-example 13 | 14 | 15 | 16 | org.freemarker 17 | freemarker 18 | 2.3.23 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /template-example/freemarker-example/src/main/resources/hello.ftl: -------------------------------------------------------------------------------- 1 | FreeMarker Template example: ${message} 2 | 3 | ======================= 4 | === County List ==== 5 | ======================= 6 | <#list countries as country> 7 | ${country_index + 1}. ${country} 8 | -------------------------------------------------------------------------------- /template-example/jetbrick-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | jetbrick-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /template-example/jetbrick-example/jetbrick-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /template-example/jetbrick-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | template-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | jetbrick-example 13 | 14 | 15 | -------------------------------------------------------------------------------- /template-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | template-example 13 | pom 14 | 15 | freemarker-example 16 | velocity-example 17 | jetbrick-example 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /template-example/template-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /template-example/velocity-example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | velocity-example 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.m2e.core.maven2Builder 10 | 11 | 12 | 13 | 14 | 15 | org.eclipse.m2e.core.maven2Nature 16 | 17 | 18 | -------------------------------------------------------------------------------- /template-example/velocity-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | template-example 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | velocity-example 13 | 14 | 15 | -------------------------------------------------------------------------------- /template-example/velocity-example/velocity-example.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /tensorflow-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | tensorflow-example 13 | 14 | 15 | io.github.biezhi.tensorflow.HelloTF 16 | 17 | 18 | 19 | 20 | org.tensorflow 21 | tensorflow 22 | 1.5.0 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /yaml-example/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | java-library-examples 7 | io.github.biezhi 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | yaml-example 13 | 14 | 15 | 16 | org.yaml 17 | snakeyaml 18 | 1.19 19 | 20 | 21 | -------------------------------------------------------------------------------- /yaml-example/src/main/java/io/github/biezhi/yaml/JavaToYamlExample.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.yaml; 2 | 3 | import org.yaml.snakeyaml.Yaml; 4 | 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | /** 9 | * Map 转 yaml配置 10 | */ 11 | public class JavaToYamlExample { 12 | 13 | public static void main(String[] args) { 14 | Map> map = createMap(); 15 | Yaml yaml = new Yaml(); 16 | String output = yaml.dump(map); 17 | System.out.println(output); 18 | } 19 | 20 | private static Map> createMap() { 21 | Map> map = new HashMap<>(); 22 | for (int i = 1; i <= 3; i++) { 23 | Map map2 = new HashMap<>(); 24 | map2.put("key1" + i, "value1" + i); 25 | map2.put("key2" + i, "value2" + i); 26 | map2.put("key3" + i, "value4" + i); 27 | map.put("key" + i, map2); 28 | } 29 | return map; 30 | } 31 | } -------------------------------------------------------------------------------- /yaml-example/src/main/java/io/github/biezhi/yaml/LoadList.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.yaml; 2 | 3 | import org.yaml.snakeyaml.Yaml; 4 | 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | 8 | public class LoadList { 9 | 10 | public static void main(String[] args) throws IOException { 11 | loadFromFile("/fruits.yml"); 12 | } 13 | 14 | private static void loadFromFile(String path) throws IOException { 15 | System.out.printf("-- loading from %s --%n", path); 16 | Yaml yaml = new Yaml(); 17 | try (InputStream in = LoadList.class.getResourceAsStream(path)) { 18 | Iterable itr = yaml.loadAll(in); 19 | for (Object o : itr) { 20 | System.out.println("Loaded object type:" + o.getClass()); 21 | System.out.println(o); 22 | } 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /yaml-example/src/main/java/io/github/biezhi/yaml/model/Person.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.yaml.model; 2 | 3 | import lombok.Data; 4 | 5 | @Data 6 | public class Person { 7 | 8 | private String name; 9 | private String phone; 10 | private String address; 11 | 12 | } -------------------------------------------------------------------------------- /yaml-example/src/main/java/io/github/biezhi/yaml/model/Persons.java: -------------------------------------------------------------------------------- 1 | package io.github.biezhi.yaml.model; 2 | 3 | import lombok.Data; 4 | 5 | import java.util.List; 6 | 7 | @Data 8 | public class Persons { 9 | 10 | private List persons; 11 | 12 | } -------------------------------------------------------------------------------- /yaml-example/src/main/resources/fruits.yml: -------------------------------------------------------------------------------- 1 | - Apple 2 | - Banana 3 | - Orange -------------------------------------------------------------------------------- /yaml-example/src/main/resources/fruitsGroup.yml: -------------------------------------------------------------------------------- 1 | Morning: 2 | - Apple 3 | - Banana 4 | - Pear 5 | 6 | Evening: 7 | - Orange 8 | - Grape 9 | - Pineapple -------------------------------------------------------------------------------- /yaml-example/src/main/resources/person.yml: -------------------------------------------------------------------------------- 1 | name: biezhi 2 | phone: 111-111-1112 3 | address: ShangHai, China -------------------------------------------------------------------------------- /yaml-example/src/main/resources/persons.yml: -------------------------------------------------------------------------------- 1 | persons: 2 | - name: Joe 3 | phone: 111-111-1111 4 | address: Park Dr, Charlie Hill 5 | 6 | - name: Trish 7 | phone: 111-111-11111 8 | address: Small Vine, River Town --------------------------------------------------------------------------------