Hadoop的SequenceFile讀寫實例

 1     SequenceFile可以處理hdfs上大量小文件,它可以作為大量小文件的容器。HDFS和MapReduce是針對大文件優化的,所以通過SequenceFile類型將小文件包裝起來可以獲得更高效的存儲和處理。存儲
 2 在SequenceFile中的鍵和值并不一定是Writable類型,只要能被Serialization序列化和反序列化,任何類型都可以。
 3 
 4   SequenceFile的優點是:以鍵值對方式存儲、支持壓縮、合并大量小文件。
 5 
 6    
 7         Configuration conf = new Configuration();
 8         FileSystem fs = FileSystem.get(new URI("hdfs://single32:9000"), conf);
 9         Path targetPath = new Path("/sfs");
10         
11         //在HDFS上創建不使用壓縮的SequenceFile
12         final Option optPath = SequenceFile.Writer.file(targetPath);
13         final Option optKeyClass = SequenceFile.Writer.keyClass(Text.class);
14         final Option optValueClass = SequenceFile.Writer.valueClass(BytesWritable.class);
15         final SequenceFile.Writer writer = SequenceFile.createWriter(conf, optPath, optKeyClass, optValueClass);
16         final Collection<File> listFiles = FileUtils.listFiles(new File("/usr/local/"), new String[]{"txt"}, false);
17         Text key = null;
18         BytesWritable value = null;
19         for (File file : listFiles) {
20             key = new Text(file.getPath());
21             value = new BytesWritable(FileUtils.readFileToByteArray(file));
22             writer.append(key, value);
23         }
24         IOUtils.closeStream(writer);
25 
26         //讀取HDFS上指定目錄下的SequenceFile文件
27         final SequenceFile.Reader reader = new SequenceFile.Reader(fs, targetPath, conf);
28         final Text outputKey = new Text();
29         final BytesWritable outputValue = new BytesWritable();
30         while(reader.next(outputKey, outputValue)){
31             final File file = new File("/usr/"+outputKey.toString());
32             FileUtils.writeByteArrayToFile(file, outputValue.getBytes());
33         }
34         IOUtils.closeStream(reader);
35   

?

轉載于:https://www.cnblogs.com/mengyao/archive/2013/02/03/4456148.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/274364.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/274364.shtml
英文地址,請注明出處:http://en.pswp.cn/news/274364.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

臉部細微表情識別_您可以僅使用面部表情來控制字體嗎?

臉部細微表情識別原型 (The prototype) Facetype is the name of Adam’s interactive project, in which the emotions detected from a person’s facial gestures control a variable font. To each detected emotion corresponds a specific typeface, which keeps transfo…

ssky-keygen + ssh-copy-id 無密碼登陸遠程LINUX主機

使用下例中ssky-keygen和ssh-copy-id&#xff0c;僅需通過3個步驟的簡單設置而無需輸入密碼就能登錄遠程Linux主機。 ssh-keygen 創建公鑰和密鑰。 ssh-copy-id 把本地主機的公鑰復制到遠程主機的authorized_keys文件上。ssh-copy-id 也會給遠程主機的用戶主目錄&#xff08;ho…

uva10891Game of sum

題意:經典的取石子游戲是這樣的:有一堆石子&#xff0c;A、B兩個人輪流取&#xff0c;每次取一顆&#xff0c;只能從邊上取&#xff0c;每個石子有相應的價值&#xff0c;A、B兩人都想使得自己的價值最多&#xff0c;兩個人足夠聰明&#xff0c;問最后價值分別是多少 本題則是可…

用戶體驗設計師能為seo做_用戶體驗設計師可以從產品設計歷史中學到什么

用戶體驗設計師能為seo做Many things have changed from tool design in the prehistoric era to today’s digital product design. However, we can see surprisingly many similarities. Especially when it comes down to one particular aspect: usability.從史前時代的工…

函數指針

顧名思義&#xff0c;指針函數即返回指針的函數。其一般定義形式如下&#xff1a; 類型名 *函數名(函數參數表列); 其中&#xff0c;后綴運算符括號“()”表示這是一個函數&#xff0c;其前綴運算符星號“*”表示此函數為指針型函數&#xff0c;其函數值為指針&#xff0c;即它…

orton效果_如何使圖片發光:Orton效果

orton效果Have you ever seen an impossibly dream-like landscape photo? One with a slow burning, glowing sunset. That’s really the best way to describe it, the image looks as if it’s glowing. You might be thinking, “wow, I wish I was that good and could …

UVA10785 The Mad Numerologist

雖然是sorting的壓軸&#xff0c;但是比起前面真心水題。這個專題結合前面string的很多&#xff0c;排序相對簡單了&#xff0c;qsort基本解決。 題目&#xff1a; The Mad Numerologist Numerology is a science that is used by many people to find out a mans personality,…

蘋果人機交互指南_蘋果人機界面設計指南的10個見解

蘋果人機交互指南重點 (Top highlight)I’ve been developing an IOS app for the past few months and have been constantly referring to Apple’s Human Interface Design Guidelines. I would consider it a must-read for any aspiring or current UI/UX designer.在過去…

也來學學插件式開發

上一家公司有用到插件式開發來做一個工具箱&#xff0c;類似于QQ電腦管家&#xff0c;有很多工具列表&#xff0c;點一下工具下載后就可以開始使用了。可惜在那家公司待的時候有點短&#xff0c;沒有好好研究一下。現在有空&#xff0c;自己在網上找了些資料&#xff0c;也來試…

同態加法_我對同態的想法

同態加法Early February, I uploaded this shot onto Dribbble. Nothing fancy –– just two screens experimenting with “2月初&#xff0c;我將這張照片上傳到Dribbble。 沒什么幻想–只有兩個屏幕在嘗試“ Neumorphism,” or soft UI. Little did I know that this post…

php內核探索

引自&#xff1a;http://www.nowamagic.net/librarys/veda/detail/1285 SAPI:Server Application Programming Interface 服務器端應用編程端口。研究過PHP架構的同學應該知道這個東東的重要性&#xff0c;它提供了一個接口&#xff0c;使得PHP可以和其他應用進行交互數據。 本…

hp-ux鎖定用戶密碼_UX設計101:用戶研究-入門需要了解的一切

hp-ux鎖定用戶密碼這是什么&#xff1f; (What is this?) This session is part of a learning curriculum that I designed to incrementally skill up and empower a team of Designers and Researchers whose skillset and ways of working needed to evolve to keep up wi…

等比數列前N項和的公式推導

設等比數列的前n項和為S(n), 等比數列的第一項為a1&#xff0c;比值為q。 &#xff08;1&#xff09;S(n) a1 a1 * q a1 * q ^ 2 .... a1 * q ^ (n - 1);&#xff08;2&#xff09;S(n1) a1 a1 * q a1 * q ^ 2 .... a1 * q ^ (n - 1) a1 * q ^ n;由&#xff08;2&am…

extjs6 引入ux_關于UX以及如何擺脫UX的6種常見誤解

extjs6 引入uxDo you ever browse social media, internet, or talk to colleagues and hear them say something UX related you disagree with so much that you just want to lecture them on the spot?您是否曾經瀏覽過社交媒體&#xff0c;互聯網或與同事交談&#xff0c…

Cocos2D-HTML5開源2D游戲引擎

http://www.programmer.com.cn/12198/ Cocos2D-HTML5是基于HTML5規范集的Cocos2D引擎的分支&#xff0c;于2012年5月發布。Cocos2D-HTML5的作者林順將在本文中介紹Cocos2D-HTML5的框架、API、跨平臺能力以及強大的性能。Cocos2D-HTML5是Cocos2D系列引擎隨著互聯網技術演進而產生…

illustrator下載_Illustrator筆工具練習

illustrator下載Adobe Illustrator is a fantastic vector creation tool and you can create a lot of things without ever using the Pen Tool. However, if you want to use Illustrator at its full potential, I personally believe that you need to master and become …

怎么更好練習數位板_如何設計更好的儀表板

怎么更好練習數位板重點 (Top highlight)Dashboard noun \?dash-?b?rd\ A screen on the front of a usually horse-drawn vehicle to intercept water, mud, or snow.儀表盤 名詞\ ?dash-?b?rd \\通常在馬拉的車輛前部的屏幕&#xff0c;用來攔截水&#xff0c;泥或雪。…

學習正則表達式

deerchao的blog Be and aware of who you are. 正則表達式30分鐘入門教程 來園子之前寫的一篇正則表達式教程&#xff0c;部分翻譯自codeproject的The 30 Minute Regex Tutorial。 由于評論里有過長的URL,所以本頁排版比較混亂,推薦你到原處查看,看完了如果有問題,再到這里來提…

人物肖像速寫_去哪兒? 優步肖像之旅

人物肖像速寫In early 2018, the Uber brand team started a rebranding exercise, exploring a fresh take on what it means to be a global transportation and technology company. A new logo was developed in tandem with a bespoke sans-serif typeface called Uber Mo…

js獲取和設置屬性

function square(num){ var total num*num;//局部變量 return total;}var total 50;//全局變量var number square(20);alert(total);//結果為50function square(num){ total num*num;//全局變量 return total;}var total 50;//全局變量var number square(20)…