Java Distributed File Management system-mydfsserver

Source: Internet
Author: User

Dear Bo Friends, my name is Warkeway, good at Java and C + + language, now in Wuxi. Worked as a project manager, Java Programmer, Android development engineer, Java instructor. If there are technical problems we can discuss together. I qq:1058633117 QQ e-mail: [Email protected] Tel: 15295432682

This is the file Upload management system I wrote, the file upload system. Can be easily integrated in javaweb or other applications. Already open source on GitHub. The project is an app written in the Java language, and I'm named Mydfsserver, using a Java class library with sockets, DataOutputStream, DataInputStream, threads, thread pools, which are already used in some projects, and very stable.

GitHub Project Address: Https://github.com/believeus/MyDfsServer.git.

First step: Download the install Git tool.

Step two: Use the command git clone https://github.com/believeus/MyDfsServer.git to download the source code locally. (You won't need to add a base to git).

Step three: Integrate into the project.

Way one: Integrate spring in the Web environment
First step: Configured in the spring configuration file, the service starts with the Tomcat load Web App launch and shuts down as Tomcat shuts down
<?xml version= "1.0" encoding= "UTF-8"?>
<beans xmlns= "Http://www.springframework.org/schema/beans"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:p= "http://www.springframework.org/schema/p"
xmlns:aop= "HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP"
xsi:schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans-2.5.xsd
HTTP://WWW.SPRINGFRAMEWORK.ORG/SCHEMA/AOP http://www.springframework.org/schema/aop/spring-aop-2.5.xsd ">
<bean id= "Mydfsstorageserver" class= "Mydfs.storage.server.MydfsStorageServer"
Lazy-init= "false" init-method= "StartServer"
destroy-method= "Stopserver" >
<property name= "host" value= "127.0.0.1"/>
<property name= "Port" value= "9999"/>
<property name= "Workers" value= "ten"/>
<property name= "BasePath" value= "E:/data/mydfs/store"/>
</bean>
<bean id= "Mydfstrackerserver" class= "Mydfs.storage.server.MydfsTrackerServer" scope= "prototype" >
<property name= "host" value= "127.0.0.1"/>
<property name= "Port" value= "9999"/>
</bean>
</beans>

Step Two: Configure in Web. xml
<!--Begin author:wuqiwei:data:2014-06-05 Addreason: Embedded small Distributed File system integration--
<servlet>
<servlet-name>storageClient</servlet-name>
<servlet-class>mydfs.storage.server.MydfsServerServlet</servlet-class>
<!--127.0.0.1:9999 is the IP and port that points to the Dfsserver service, respectively
<init-param>
<param-name>mydfsServerHost:Port</param-name>
<param-value>127.0.0.1:9999</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>storageClient</servlet-name>
<url-pattern>/group/M00/*</url-pattern>
</servlet-mapping>
<!--End author:wuqiwei:data:2014-06-05 Addreason: Embedded small Distributed File system integration--

Step three: Write Java code
First parameter: InputStream uploaded file stream the second parameter: extention: The suffix name of the file
String storepath= mydfstrackerserver.upload (InputStream, extention);


Mode two: Start as a separate service
First step: An executable Mydfsserver.jar file is generated after the Ant jar executes
Step Two: Java-jar Mydfsserver.jar
Mydfsserver.jar file with mydfs.properties file, IP and port related configuration can be configured
Default port 9999 host default 127.0.0.1 threads Worker default is 5 base path basepath default: e:/data/mydfs/store/
Step three: Write the client code to put Mydfsserver.jar into the client's environment variable
Mydfstrackerserver client=new mydfstrackerserver ("127.0.0.1", 9999);


Method Three: Hard-coded
If it is not in the spring Web environment, use the method in the code
0. Start the service
First parameter: Port number to start the second parameter: Picture storage address the third parameter: number of worker threads fourth parameter: Listening IP address
Mydfsstorageserver storageserver=new Mydfsstorageserver (9999, "D:/data/mydfs/store", 4, "127.0.0.1");
Storageserver.startserver ();
1. Upload a picture to get the path after uploading the image
Mydfstrackerserver client=new mydfstrackerserver ("localhost", 9999);
InputStream InputStream = new FileInputStream ("d:/20130412062742872.jpg");
String Storepath = Client.upload (inputstream, "JPG");
System.out.println (Storepath);
2. Get the uploaded picture data
Mydfstrackerserver client=new mydfstrackerserver ("127.0.0.1", 9999);
String url= "http://www.jobs.com/group/M00/EF/2C/3696-CCD2-43E7-9854-6B51F6AA2315.jpg?w=100&h=100";
InputStream inputstream=client.receivedata (URL);
3. Delete uploaded image data
Mydfstrackerserver client=new mydfstrackerserver ("127.0.0.1", 9999);
String url= "http://www.jobs.com/group/M00/78/79/53D9-34E2-4110-BDBA-8BF808E2C4BD.swf";
Boolean success = Client.removedata (URL);
System.out.println ("Delete condition:" +success);


Java Distributed File Management system-mydfsserver

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.