March 9th, 2010 / No Comments » / by featheast
Working with Azure recently, sometimes when you are trying to upload large files into the Azure storage service, you cannot simply push it. For files larger than 64MB, you have to split the file into small trunks, and upload each of them as a blob list. It’s not hard to understand the concept however split large files may not seem to be easy for junior developers.
Here is a simple code to split large files into small pieces which may be helpful if tbis is what you want to achieve:
class FileSplit {
private File f;
private FileInputStream fis;
private String path;
private String fileName;
int count;
public FileSplit(File f) {
this.f = f;
fileName = f.getName();
count = 0;
path = f.getParent();
}
public int split() {
try {
log.info(”Start to split files”);
fis = new FileInputStream(f);
byte buf[] = new byte[4 * 1000 * 1000];
int num = 0;
while ((num = fis.read(buf)) != -1) {
if (createSplitFile(buf, 0, num) == -1) {
return 0;
}
count++;
log.info(”Finished one piece”);
}
log.info(”All finished”);
} catch (Exception e) {
log.severe(e.getMessage());
} finally {
if (fis != null) {
try {
fis.close();
} catch (Exception e) {
log.severe(e.getMessage());
}
}
}
return count;
}
private int createSplitFile(byte buf[], int zero, int num) {
FileOutputStream fosTemp = null;
try {
fosTemp = new FileOutputStream(path + “/” + count + “.tmppt”);
fosTemp.write(buf, zero, num);
fosTemp.flush();
} catch (Exception e) {
return -1;
} finally {
try {
fosTemp.close();
} catch (Exception e) {
log.severe(e.getMessage());
}
}
return 1;
}
}
Posted in: Java
Tags: File, Java, Large, Split
March 8th, 2010 / No Comments » / by featheast
While cloud computing is the buzzword around world, Amazon is no doubt one of the most important competitors in this field. The products S3 and CloudFront both play their vital role for cloud storages and services.
However, there is always some misunderstandings between these two services. Here is a simple clarification which may be a little bit helpful.
Amazon S3 is a storage service, which means it is solely used to store the data in some cloud out there, and you have no choice to replicate this data in any other places. The Amazon S3 will provide you a URL which points to this specific piece of data, and each time you will be routed to the same IP to acquire this data.
Amazon CloudFront is a CDN service, which replicates all your data into different locations around the world. When you are in NY, the nearest node to download your data will be in US not in Europe; when you are in London, CloudFront will route you to Dublin which is far less distance than in US. This effectively shortened the length for data transmission.
As above we can see that most of the time, you will be under the assumption that you have to use both of these two services at the same time to improve your data’s efficiency.
Posted in: Amazon
Tags: Amazon, CloudFront, S3
March 8th, 2010 / No Comments » / by featheast
Although Google is branded as a searching company, now it has come into every corner of IT world. I just realized that without Google, I will be kind of in a situation that cannot live comfortable any more. Using Gmail to send and receive mails, using Google Docs to create, edit and share documents, using Google Calendar to arrange weekly and daily schedule, using Google Reader to read the latest information and news around, using Google Map to discover and explore neighborhood and destinations, using Google Buzz and Wave to socialize, and more importantly for me, using Google App Engine to earn money.
Recently, I have a thought to take participant in the open-source world, as a result the first thing came into my mind is to create some small project on the Google Code, which is previously dominated by SourceForge. After some attempting, I have constructed a very small project with the name of “restfulhttpclient”. It is written in Java, with the IDE of Netbeans 6.8. Consequently, the checking out code will in the structure in Netbeans.
It is not difficult to adopt Google Code as SVN repository, since it provides the most basic functions to host code, and once you have an account and create a project there, you just need simply using your familiar SVN client to commit and check out your code.
However, I do have some questions here, the one that confused me most is that why should I name my project in all lowercase characters. Some one may argue it will be easier for lowercase letters to display in the address URI and for people to type in, but I believe a simple mapping and checking mechanism will not be that hard.
Another thing is actually for each of the project, there are two different URIs mapping to this project. One in the format of ***.googlecode.com, and the other is code.google.com/p/***. Whenever you try to upload your file, it is better to choose the first one, since the latter one will give you a 400 bad request response.
All right, if you have some interest, try to download my project in a while ( not finished yet).
http://code.google.com/p/restfulhttpclient
The reason why it is called restful http client is simply because of I have to use those basic functions as work. As developing a project full of Restful web services, invoking a http request will be the most common task. A handy GUI tool will be really nice if it can covers those most usual functions. Even a lot of similar products are out there, I cannot find one that most suits me. Either some of them have too many capabilities that made them extremely difficult to master, or some just ignores certain part of the function that I have to use. In this project, users can send GET, POST, PUT and DELETE request to server, you can add specific headers, and basic authentication informations. The response code and message will also be displayed on the panel once received by the client.
Posted in: Google
Tags: Client, Google Code, Http, Netbeans, RESTful, restfulhttpclient, SVN
December 20th, 2009 / No Comments » / by featheast
I’m going to read these two books in the coming weeks until the next vacation, and going to write any ideas and thoughts during the reading. Hopefully this way can force me to have reading tasks more regularly and more frequently.
Book 1. Learning Python, Mark Lutz and David Ascher, O’Reilly
Book 2. Beginning Unix, Paul Love, Joe Merlino, Jeremy C. Reed, Craig Zimmerman, Paul Weinstein, Wrox
Posted in: Study
December 13th, 2009 / No Comments » / by featheast
When using Restlet library to invoke RESTful method, sometimes you need to parse the request header for further use. And luckily, though there is explicit ways to solve this problem, we can still get what we need.
Calling getRequestAttributes().get(”org.restlet.http.headers”); will return all the headers in the request. However, the type of returned result is “org.restlet.data.Form”. Consequently, we need to convert it into the Form format, and then using the getFirstValue(”") method to retrieve the value. One catch there is the key is always start with capital letter, for instant even is “location” in the header, you have to use “Location” instead.
Form headers = (Form) getRequestAttributes().get(”org.restlet.http.headers”);
location = headers.getFirstValue(”Location”);
Posted in: Uncategorized
Tags: Header, Request, RESTful, Restlet
December 9th, 2009 / No Comments » / by featheast
Sometimes, you may encounter a problem like this:
is not accessible due to restriction on required library /usr/lib/jvm/java-6-sun-1.6.0.15/jre/lib/rt.jar.
After several times checking, there is no reason to properly explain and your program gets to stuck since no compilation is allowed when error existed.
One way to work around this issue is by resetting the configuration in the Eclipse project properties. Right click the project name, get into its properties and the Java compiler tab. There is an Errors/Warnings line listing there, select it, and update the Forbidden Reference (access rules) into Warning in the Deprecated and restricted API. Then rebuild the project, and problem solved.
Similar errors can be handled in the same way.
Posted in: Eclipse
Tags: Access Restriction, Eclipse, Forbidden Reference
December 8th, 2009 / No Comments » / by featheast
Well, with GAE it is easy to develop applications on the cloud. But various limitations sometimes make people feel really uncomfortable when their usual behavior being considered as illegal according to the Google Laws.
You are not allowed to use any library related to .net package which may possibly generate more threads. But in order to make any invocation of other RESTful web services, we need to do something to both satisfy the requirement of Google and us.
In the official document, GAE recommends to use the HttpURLConnection class, which is a little bit too simpler to use, which means it brings various problems when dealing with complicated data types.
Here I will invoke a remote RESTful web service which will accept the format of JSON. Here is the code:
try {
URL url = new URL(”http://localhost:8183/users/” +user+”/content”);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestMethod(”POST”);
connection.setRequestProperty(”Content-Type”, “application/json”);
String json = content.toJSON().toString();
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
writer.write(json);
writer.close();
if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
System.out.println(”sssssss”);
} else {
System.out.println(connection.getResponseMessage());
System.out.println(”ffffffff”);
}
} catch (Exception e) {
e.printStackTrace();
}
Looks easy, ha, yep, quite straightforward. Remember to add those content-type in the connection for the receiver to recognize the format you are sending. While you are only allowed to send String or Char[], so hurry up and write your own parsing functions.
Posted in: Google App Engine
Tags: Google App Engine, JSON, RESTful
November 2nd, 2009 / No Comments » / by featheast
It’s the first day that I work in Australia, and also in the uni. Currently I have two titles, one is a master student who is going to graduate later this year, and another is a casual research assistant in the department of cs. At this moment, I am really happy to have a perfect environment to start with my career, and also thanks to my “boss” James giving me infinite help on my first day.
Anyway, I have never try to use Linux before, and after one day living with Ubuntu, I guess in the future I might be a big fan of the Linux family although Win7 has just come out of the water. I prefer this feeling with professional study and work, and I’m more happy to get payed by this.
I’m going to write more in this blog to record my working life in Melbourne, and also some technique skills or tips or summaries as I walk through this project.
Posted in: Work
July 8th, 2009 / No Comments » / by featheast
After re-install my computer, I lost all the mail information. While I was a little unsatisfied with the character encoding with Foxmail, I decided to take a try with Thunderbird, which originally I found from Lars.
It is a great application with email receiving and sending. However, two problems blocks me a little while for configuration. One is each time you close the box, it will really exit but not minimize to the system tray. Actually this is pretty annoying that at first I just feel strange how can I not receiving any mails for half a day. OK, so what you need to do is download a plug-in to enable the minimize ability. Just Google it and you will definitely find it.
Another serious problem is I can only download those unread emails from GMail which always affects my working when I try to fetch those old mails. At first I thought it is a problem with the configuration of Thunderbird, and finally I figured out I owe an apology to Thunderbird. Yep, it is just one single click on the setting with GMail.
Log into your GMail account, in the setting panel and Forwarding and POP/IMAP tab, you will see a POP Download option, select it to enable POP for all mails, then start your client to receive. Done.
I guess this solution will be suitable for all kinds of client applications.
Posted in: Google
Tags: Download, GMail, Old Mail, Read Mail, Thunderbird
June 29th, 2009 / No Comments » / by featheast
1. Strictly follow the standards of W3C. You can validate your web page by the tool at: http://validator.w3c.org/.
2. Decrease the ratio of markup to content, improve the page load time and improve the communication of the information hierarchy of your page.
3. Image Replacement:
Replace the img tag which shows the logo or the most important information of this page with a <h1> tag. The content of <h1> tag will be the details introduction of the page or the logo, with indentation to place that can not display on the screen, and a background image setted to be the real image file with its name renamed to be more meaningful. This strategy can only be used once for any certain page since it is better to limit the <h1> tag into only once for a page.
4. Signals of Quality:
1) Number of inbound links to the page from reputable sources, which is the way Google does.
2) Web standards are not 100 percent gurantee of top page ranking, but important to it. Therefore pages should follow the standards as closely as possible.
5. Highly valued tags for search engines:
1) <title>, keep it concise and natural. <title> page title | organization or site name | short keyword-rich phrase </title>
2) <strong> and <en>, elevating certain part of the content’s ranking within the information hierarchy
3) <a>, title attribute inside <a> tag, and also include target keywords in the link labels. An inbound link with the same keyword in the label as your site target is extremely effective.
6. Meta:
1) keywords in <meta> is useless, while description is still important. Limit the characters in <description> between 100 to 150 which is better for search engines to display.
2) use lang for multilingual site, like <meta name=”description” lang=”en-us” content=”” /> and <meta name=”description” lang=”zh-cn” content=”” />
3) No need to use robots in tag. <meta name=”robots” content=”all” />
4) Never use refresh attribute since it might be penalized for bait-and-switch strategy.
5) Always include content-type.
6) Use <meta name=”robots” value=”noindex,nofollow” /> to prevent certain page be indexed by the search engine.
Add class=”robots-nocontent” to those tags that you wish to hide like ads.
7. Making Images Visible:
1) When the image is just used for decoration, apply it to css file as a background.
2) Always use alt attribute to give short introduction of the image
3) If alt is not long enough, use longdesc instead, which can link to a footnote to have more details.
Posted in: Study
Tags: aaron walter, Buiding findable website, image replacement, meta, seo, tag