Jump to: navigation, search

Difference between revisions of "Main Page"

(Added Nova Virtual page)
(25 intermediate revisions by 9 users not shown)
Line 1: Line 1:
 
__NOTOC__
 
__NOTOC__
{{:Header}}
+
+8801713083079
= [[OpenStack]] Open Source Cloud Wiki =
 
  
'''The OpenStack [[Open]] Source Cloud Mission:''' to produce the ubiquitous Open Source Cloud Computing platform that will meet the needs of public and private clouds regardless of size, by being simple to implement and massively scalable.
+
1. Download files data from many
 +
URLs and save them to the local
 +
files in the directory of your choice:
  
This wiki is intended to provide a repository and initial forum for discussions, requirements, and architectural development in progress. Read more about [[HowToUseTheWiki|how to use the wiki]].
+
This Java program lets you download files from one or more URLs and save them in the directory where you want. This program takes destination directory for the files to save as first command line argument and URLs for the files as next command line arguments separated by space. Java provides URLConnection class that represents a communication link between the application and a URL. Invoking the openConnection method on a URL creates URLConnection object. Now get [[InputStream]] object from that connection and read the data. Finally write the data to the local file.
  
<<Columns(2, start)>>
+
[[FileDataDownload]].java:
  
== Compute (Nova) ==
+
import java.io.*;
* [https://launchpad.net/nova Project on Launchpad]
+
import java.net.*;
* [http://nova.openstack.org Developer documentation]
+
public class [[FileDataDownload]] {
 +
final static int size=1024;
 +
public static void
 +
[[FileDownload]](String fileAddress, String
 +
localFileName, String destinationDir) {
 +
[[OutputStream]] os = null;
 +
URLConnection URLConn = null;
  
== Development, start here ==
+
// URLConnection class represents a communication link between the
 +
// application and a URL.
  
* [[GettingStarted|Getting Started]]
+
[[InputStream]] is = null;
** [[CodingStandards|Coding Standards]]
+
try {
** [[BasicDesignTenets|Design Tenets]]
+
URL fileUrl;
** [[[LifeWithBzrAndLaunchpad|| Learning bzr and Launchpad ]]]
+
byte[] buf;
** [[[ReleaseCycle|| Explanation of the Release cycle ]]]
+
int [[ByteRead]],[[ByteWritten]]=0;
* [[GettingTheCode|Getting the Code (using Launchpad and bzr)]]
+
fileUrl= new URL(fileAddress);
* [[SAIOInstructions | Object Storage (Swift), all in one for development ]]
+
os = new [[BufferedOutputStream]](new
* [[[NovaInstall|| Compute (Nova) Installation, single machine for development ]]]
+
[[FileOutputStream]](destinationDir+”\\”+
 +
localFileName));
 +
//The URLConnection object is
 +
created by invoking the
  
== What's New ==
+
// openConnection method on a URL.
  
* [[NovaVirtually]] - Provides virtual images for running Nova in a sandbox.
+
URLConn = fileUrl.openConnection();
* [[NovaDatabaseSchema]] - Describes the Nova database schema.
+
is = URLConn.getInputStream();
* [[Summit]] - Thanks all for a great Summit! Read more in a [[BexarDeveloperTopics/Summary|Summary]].
+
buf = new byte[size];
* [[NovaInstall/Video]] - Screencast recording of [[OpenStack]] Compute installation on Ubuntu 10.04.
+
while (([[ByteRead]] = is.read(buf)) != -1) {
* [[NovaFeatureMatrix|Feature Matrix]] - Fill out a feature matrix for [[OpenStack]] Compute.
+
os.write(buf, 0, [[ByteRead]]);
* [[Wanted]] - Use this classifieds-style page to post help wanted for projects.  
+
[[ByteWritten]] += [[ByteRead]];
 +
}
 +
System.out.println(“Downloaded
 +
Successfully.”);
 +
System.out.println(“File name
 +
:\””+localFileName+ “\”\nNo of
 +
bytes :” + [[ByteWritten]]);
 +
}
 +
catch (Exception e) {
 +
e.printStackTrace();
 +
}
 +
finally {
 +
try {
 +
is.close();
 +
os.close();
 +
}
 +
catch (IOException e) {
 +
e.printStackTrace();
 +
</nowiki></pre>
 +
public static void fileDownload(String
 +
fileAddress, String destinationDir)
 +
{
  
== Foundation ==
+
// Find the index of last occurance of character ‘/’ and ‘.’.
  
* [[Open]] - What openness means to us.
+
int lastIndexOfSlash =
* [[Governance]] - How we will govern all OpenStack projects.
+
fileAddress.lastIndexOf(‘/’);
* [[Release|Release Schedule]] - Dates for upcoming release milestones.
+
int lastIndexOfPeriod =
* [[Documentation]] - Starting point for technical documentation.
+
fileAddress.lastIndexOf(‘.’);
* [[Process]] - How we do what we do.
 
  
<<Columns(2)>>
+
// Find the name of file to be downloaded from the address.
== Object Storage (Swift) ==
 
  
* [https://launchpad.net/swift Project on Launchpad]
+
String fileName=fileAddress.substring
* [http://swift.openstack.org Developer documentation]
+
(lastIndexOfSlash + 1);
  
== Deployment, start here ==
+
// Check whether path or file name is given correctly.
  
* [[PythonDevelopmentEnvironment|Development Environment]]
+
if (lastIndexOfPeriod >=1 && lastIndexOfSlash >= 0 &&
* [[InstallInstructions|Install Instructions]]
+
lastIndexOfSlash < fileAddress.length()
* [[[ConfigureSwift||Configuring Object Storage (Swift)]]]
+
-1 1)
* [[Answers | Questions and Answers]]
+
{
 +
[[FileDownload]](fileAddress,fileName,
 +
destinationDir);
 +
}
 +
else
 +
{
 +
System.err.println(“Specify correct path or file name.”);
 +
}}
 +
public static void main(String[] args)
 +
{
  
== People and Community ==
+
// Check whether there are atleast
 +
two arguments.
  
* [[Meetings | Weekly Team Meeting]]
+
if(args.length==2)
* [[[HowToContribute|| How to Contribute ]]]
+
{
* [http://planet.openstack.org/ Planet OpenStack] - Aggregation of community and developer blogs around OpenStack.  
+
for (int i = 1; i < args.length; i++) {
* [[People|Who we are]]
+
fileDownload(args[i],args[0]);
* [[[MailingLists|| OpenStack] Mailing Lists]]
+
}
* [[OpenStackUsersGroup]]
+
}
* [[[WeeklyNewsletter|| Newsletter & Data Tracking]]]
+
else{System.err.println(“Provide
 +
\”Destination directory path\” and \”file
 +
names\” separated by space.”);
 +
}
 +
}
 +
}
  
<<Columns(2, end)>>
+
Compile and Run:
 +
 
 +
In this example, the location for the
 +
directory where file “jsf.htm” is to be
 +
saved is “c:\download”.
 +
 
 +
C:\[[JavaJazzup]]>javac [[FileDataDownload]].java
 +
C:\[[JavaJazzup]]>java [[FileDataDownload]]
 +
c:\download http://localhost:8080/
 +
tomahawk_tags/pages/jsf.htm

Revision as of 11:32, 19 April 2011

+8801713083079

1. Download files data from many URLs and save them to the local files in the directory of your choice:

This Java program lets you download files from one or more URLs and save them in the directory where you want. This program takes destination directory for the files to save as first command line argument and URLs for the files as next command line arguments separated by space. Java provides URLConnection class that represents a communication link between the application and a URL. Invoking the openConnection method on a URL creates URLConnection object. Now get InputStream object from that connection and read the data. Finally write the data to the local file.

FileDataDownload.java:

import java.io.*; import java.net.*; public class FileDataDownload { final static int size=1024; public static void FileDownload(String fileAddress, String localFileName, String destinationDir) { OutputStream os = null; URLConnection URLConn = null;

// URLConnection class represents a communication link between the // application and a URL.

InputStream is = null; try { URL fileUrl; byte[] buf; int ByteRead,ByteWritten=0; fileUrl= new URL(fileAddress); os = new BufferedOutputStream(new FileOutputStream(destinationDir+”\\”+ localFileName)); //The URLConnection object is created by invoking the

// openConnection method on a URL.

URLConn = fileUrl.openConnection(); is = URLConn.getInputStream(); buf = new byte[size]; while ((ByteRead = is.read(buf)) != -1) { os.write(buf, 0, ByteRead); ByteWritten += ByteRead; } System.out.println(“Downloaded Successfully.”); System.out.println(“File name

\””+localFileName+ “\”\nNo of

bytes :” + ByteWritten); } catch (Exception e) { e.printStackTrace(); } finally { try { is.close(); os.close(); } catch (IOException e) { e.printStackTrace(); </nowiki></pre>

public static void fileDownload(String

fileAddress, String destinationDir) {

// Find the index of last occurance of character ‘/’ and ‘.’.

int lastIndexOfSlash = fileAddress.lastIndexOf(‘/’); int lastIndexOfPeriod = fileAddress.lastIndexOf(‘.’);

// Find the name of file to be downloaded from the address.

String fileName=fileAddress.substring (lastIndexOfSlash + 1);

// Check whether path or file name is given correctly.

if (lastIndexOfPeriod >=1 && lastIndexOfSlash >= 0 && lastIndexOfSlash < fileAddress.length() -1 1) { FileDownload(fileAddress,fileName, destinationDir); } else { System.err.println(“Specify correct path or file name.”); }} public static void main(String[] args) {

// Check whether there are atleast two arguments.

if(args.length==2) { for (int i = 1; i < args.length; i++) { fileDownload(args[i],args[0]); } } else{System.err.println(“Provide \”Destination directory path\” and \”file names\” separated by space.”); } } }

Compile and Run:

In this example, the location for the directory where file “jsf.htm” is to be saved is “c:\download”.

C:\JavaJazzup>javac FileDataDownload.java C:\JavaJazzup>java FileDataDownload c:\download http://localhost:8080/ tomahawk_tags/pages/jsf.htm