2016-06-28 1 views
0

현재 폴더 안에있는 파일 집합에서 .torrent을 생성하는 작은 도구를 구현하려고합니다. 그것은 단일 파일에 대해 완벽하게 작동합니다.Java로 여러 파일로 토런트 파일을 만드는 방법은 무엇입니까?

이 사이트에 따르면 : Torrent_file 여러 파일이 파일 집합 안에 저장됩니다. 여기

내가 지금까지 무엇을했는지 있습니다 :

public Map<Object, Object> getFiles(File dict) throws IOException, NoSuchAlgorithmException { 

    Map<Object, Object> files = new HashMap<Object, Object>(); 
    FileOutputStream fos = new FileOutputStream(merged); 

    for (File fileEntry : dict.listFiles()) 
    { 
     if (fileEntry.isFile()) 
     { 
      Map<String, Object> file = new HashMap<String, Object>(); 
      file.put("path", fileEntry.getName()); 
      file.put("length", fileEntry.length()); 

      FileInputStream fis = new FileInputStream(fileEntry); 
      byte[] byteArray = new byte[(int) fileEntry.length()]; 
      fis.read(byteArray, 0, (int) fileEntry.length()); 
      fos.write(byteArray); 
      fos.flush(); 
      files.put(file.get("path"), file.get("length")); 
     } 

    } 
    fos.close(); 
    pieces = hashPieces(merged, pieceLength); 
    return files; 
} 

내가 각 개별 파일에 대한지도를 만든 다음 모든 파일을 포함하는 다른 맵에이지도를 넣어보십시오. 그런 다음 조각 해시를 계산하기 위해 하나의 큰 파일에 파일 배열로 파일을 병합합니다. 그러나 파일 구조 부분은 예상대로 작동하지 않습니다. 어떻게 든 내가 파일 목록을 조립하는 방법을 모른다

// ... 
    Map<String, Object> info = new HashMap<String, Object>(); 
    info.put("name", sharedFile.getName()); 
    if (sharedFile.isDirectory()) { 
     Map<Object, Object> path = getFiles(sharedFile); 
     info.put("files", path); 
    } 
    // ... 

:

여러 파일 방법

은에 의해 호출됩니다. 나는 그것이지도로 끝내야 만한다는 것을 알고 있지만, 내가 키와 가치로 선택해야하는 것에 필사적이다.

+0

위키 백과는 비트 토 런트 프로토콜에 대한 기술 정보에 대한 맹렬한 출처입니다. 대신 https://wiki.theory.org/BitTorrentSpecification#Metainfo_File_Structure를 사용해보십시오. – Encombe

답변

0

정보 맵의 files 키 아래의 값은 맵이 아니며, 각 맵이 하나의 파일을 설명하는 맵 목록입니다.