[Tutorial] Downloading Files

Discussion in 'Resources' started by Cirno, May 3, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Cirno

    This works for plugins as well, it is not limited to clients only.

    I'm simply explaining how to download files by Java code.

    Downloading files as in actually downloading the file. In Java, it's quite simple but difficult to understand.

    Here's a small bit from my own code in the client.
    Code:JAVA
    1. if(!newsong.exists()){
    2. ReadableByteChannel rbc = Channels.newChannel(new URL("Removed.").openStream());
    3. newsong.createNewFile();
    4. fos = new FileOutputStream(fixinstall(song));
    5. fos.getChannel().transferFrom(rbc, 0, 1 << 24);
    6. fos.flush();
    7. fos.close();
    8. }

    ReadableByteChannel reads the bytes (e.g data) from a file. The file could be anything, music, text files, heck, you can probably make a program to sync essays between two computers!

    Obviously, we need to create a file, or else Java will babel about NullPointerException.

    We need to define a FileOutputStream, I defined mine as "fos". Note that fixinstall is my own function, and it's not an actual function in any CraftBukkit known to date. FileOutputStream is basiclly what outputs your new file. You set it to anywhere, the plugins folder, your desktop, just anywhere and give it any name. Be sure to use the same file extension, unless you're being "pro" and trying to disguise it.

    fos.getChannel.transferFrom(...) is the actual transfer process. Do NOT change any of the values withen, except for rbc if you changed your name of your ReadableByteChannel.

    Run the newly made code and go to wherever you designated the FileOutputStream; you'll probably see a file. Open it and it'll work!

    I do not support distribution of viruses or malaware in anyway. If you are a moderator or admin, feel free to delete this thread, since I know it's potential use as a virus downloader is high.

    Reason why I did this thread (open)
    I had looked this up because I was making a custom client that can download music like SpoutCraft can, except, I don't need a server to get a "plz download dis" command. However, I'm never releasing this client because it's illegal to distribute Minecraft, weather modded or vanilla. I am not intending to advertise my client; I'm merely saying I don't want people annoying me to distribute it.
     
    M1sT3rM4n likes this.
  2. Offline

    PandazNWafflez

    Just releasing the modified class files is fine, that's what modders do, that way people still have to purchase the game.
     
  3. Offline

    JesiKat

    Why do we need to know about your client? What if the file is larger than 1 << 24 bytes? What if you have a slow connection and the stream isn't read fully on the first go? Why don't you [edit: explain that you need to/should] close the FileOutputStream when you're done with it? :c
     
  4. Offline

    Cirno

    It is techniclly illegal. Minecraft is copyrighted. It's like saying I want to distribute part of the FBI confidential files, only not that serious.

    This is directly from the Minecraft ToS/Policy
    1: I thought I had put that part in spoilers... It's now in a spoiler.
    2: It doesn't HAVE to be 1 << 24 bytes. You can adjust 24 bytes; I've tried it with 48 bytes and it doesn't effect it. I just use 24 for no reason.
    3: I highly doubt anyone would be downloading gigabyte files from any kind of plugin. Even so, I'm not really understanding that question, so is it like, the stream doesn't read all the way at first?
    4: That part was a mistake; I had just copied and pasted from my own code and noticed a } was missing, so I slapped it in.
     
    M1sT3rM4n likes this.
Thread Status:
Not open for further replies.

Share This Page