MLDonkey download Chinese file garbled solution

Source: Internet
Author: User

MLDonkey download Chinese files garbled solution

 

Author: kongxx

MLDonkey is currently on the Linux more popular donkey, but its core class library is not very good to deal with Chinese, which also let a lot of Chinese donkey-raising, the following is my use of mldonkey process documents have a Chinese method, But this method is only after downloading the file to perform the conversion, in the download process still can't see Chinese, this I will find a way to deal with:

Note: The current version only supports a Chinese encoding of two bytes when adding a file.

This method uses a class that is written in the Java language, with the following code:

Import java.net.*;

Import java.io.*;

public class Mldonkeyutil {

/**

* MLDonkey File Download store path

*/

Private String incoming = "/usr/local/mldonkey/incoming";

public static void Main (string[] args) throws Exception {

Mldonkeyutil util = new Mldonkeyutil ();

Util.convert ();

}

private void convert () {

File dir = new file (incoming);

file[] files = dir.listfiles ();

for (int i = 0; i < files.length; i++) {

String strdest = Convert (Files[i].getname ());

if (!files[i].getname (). Equals (strdest)) {

Print (Files[i].getname () + ">>>" + strdest);

File Fdest = new file (files[i].getparent () + file.separator + strdest);

Files[i].renameto (fdest);

}

}

}

Private String Convert (string s) {

int location = 0;

String ret = "";

while (true) {

if (location + 8 <= s.length ()) {

String subStr = s.substring (location, location + 8);

if (check (SUBSTR)) {

RET + + "%" + Convert2hex (substr.substring (1, 4)) + "%"

+ Convert2hex (substr.substring (5, 8));

Location = location + 8;

} else {

RET + s.substring (location, location + 1);

Location = location + 1;

}

} else {

RET + s.substring (location);

break;

}

}

Return Urldecoder.decode (ret);

}

/**

* Check match type (_NNN_NNN)

* @param s

* @return

*/

Private Boolean check (String s) {

if (S.length ()!= 8) {

return false;

}

if (S.charat (0)!= ' _ ' | | S.charat (4)!= ' _ ') {

return false;

}

if (Isnum (S.charat (1)) && Isnum (S.charat (2)) && Isnum (S.charat (3))

&& Isnum (S.charat (5)) && Isnum (S.charat (6)) && Isnum (S.charat (7)) {

return true;

}

return false;

}

Private Boolean Isnum (char c) {

if (c >= && C <= 57) {

return true;

}

return false;

}

private String Convert2hex (string s) {

int i = Integer.parseint (s);

if (I < 0 | | | i > 255) {

throw new IllegalArgumentException ();

}

return integer.tohexstring (i);

}

private void print (String str) {

System.out.println (str);

}

}

Change the incoming in this class to the MLDonkey incoming directory, and then enter the following command on the Linux command line to compile and execute.

Compile

#javac Mldonkeyutil.java

Perform

#java Mldonkeyutil

If there are files in the directory that need to be renamed in Chinese, the program automatically converts and outputs the name of the file before and after the conversion.

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.