← 返回首页
Add method to send files. by Katsute · Pull Request #102 · Ktt-Development/simplehttpserver · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus
This repository was archived by the owner on Jul 31, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (3) .md  (1) All 2 file types selected Viewed files
Conversations
Failed to load comments. Retry
Loading
Jump to
Jump to file
Failed to load files. Retry
Loading
Diff view
Unified
Split
Hide whitespace
Apply and reload
Show whitespace
Diff view
Unified
Split
Hide whitespace
Apply and reload
2 changes: 1 addition & 1 deletion README.md
Show comments View file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# SimpleHttpServer
[![Maven Central](https://img.shields.io/maven-central/v/com.kttdevelopment/simplehttpserver)](https://mvnrepository.com/artifact/com.kttdevelopment/simplehttpserver)
[![Deploy](https://github.com/Ktt-Development/simplehttpserver/workflows/Deploy/badge.svg)](https://github.com/orgs/Ktt-Development/packages?repo_name=simplehttpserver)
[![Java CI](https://github.com/Ktt-Development/simplehttpserver/workflows/Java%20CI/badge.svg)](https://github.com/Ktt-Development/simplehttpserver/actions?query=workflow%3A%22Java+CI%22)
[![Maven Central](https://img.shields.io/maven-central/v/com.kttdevelopment/simplehttpserver)](https://mvnrepository.com/artifact/com.kttdevelopment/simplehttpserver)
[![version](https://img.shields.io/github/v/release/ktt-development/simplehttpserver?include_prereleases)](https://github.com/Ktt-Development/simplehttpserver/releases)
[![license](https://img.shields.io/github/license/Ktt-Development/simplehttpserver)](https://github.com/Ktt-Development/simplehttpserver/blob/main/LICENSE)

Expand Down
Show comments View file Delete file Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
import com.kttdevelopment.simplehttpserver.var.RequestMethod;
import com.sun.net.httpserver.*;

import java.io.IOException;
import java.io.OutputStream;
import java.io.*;
import java.net.InetSocketAddress;
import java.net.URI;
import java.util.Map;
Expand Down Expand Up @@ -46,7 +45,7 @@
*
* @see HttpExchange
* @since 02.00.00
* @version 03.04.03
* @version 4.0.0
* @author Ktt Development
*/
@SuppressWarnings("SpellCheckingInspection")
Expand Down Expand Up @@ -386,6 +385,10 @@ static SimpleHttpExchange create(final HttpExchange exchange){
* @see #send(String, boolean)
* @see #send(String, int)
* @see #send(String, int, boolean)
* @see #send(File)
* @see #send(File, boolean)
* @see #send(File, int)
* @see #send(File, int, boolean)
* @since 02.00.00
* @author Ktt Development
*/
Expand All @@ -406,6 +409,10 @@ static SimpleHttpExchange create(final HttpExchange exchange){
* @see #send(String, boolean)
* @see #send(String, int)
* @see #send(String, int, boolean)
* @see #send(File)
* @see #send(File, boolean)
* @see #send(File, int)
* @see #send(File, int, boolean)
* @since 02.00.00
* @author Ktt Development
*/
Expand All @@ -427,6 +434,10 @@ static SimpleHttpExchange create(final HttpExchange exchange){
* @see #send(String, boolean)
* @see #send(String, int)
* @see #send(String, int, boolean)
* @see #send(File)
* @see #send(File, boolean)
* @see #send(File, int)
* @see #send(File, int, boolean)
* @since 02.00.00
* @author Ktt Development
*/
Expand All @@ -448,6 +459,10 @@ static SimpleHttpExchange create(final HttpExchange exchange){
* @see #send(String, boolean)
* @see #send(String, int)
* @see #send(String, int, boolean)
* @see #send(File)
* @see #send(File, boolean)
* @see #send(File, int)
* @see #send(File, int, boolean)
* @since 02.00.00
* @author Ktt Development
*/
Expand All @@ -470,6 +485,10 @@ static SimpleHttpExchange create(final HttpExchange exchange){
* @see #send(String, boolean)
* @see #send(String, int)
* @see #send(String, int, boolean)
* @see #send(File)
* @see #send(File, boolean)
* @see #send(File, int)
* @see #send(File, int, boolean)
* @since 02.00.00
* @author Ktt Development
*/
Expand All @@ -490,6 +509,10 @@ static SimpleHttpExchange create(final HttpExchange exchange){
* @see #send(String, boolean)
* @see #send(String, int)
* @see #send(String, int, boolean)
* @see #send(File)
* @see #send(File, boolean)
* @see #send(File, int)
* @see #send(File, int, boolean)
* @since 02.00.00
* @author Ktt Development
*/
Expand All @@ -511,6 +534,10 @@ static SimpleHttpExchange create(final HttpExchange exchange){
* @see #send(String)
* @see #send(String, int)
* @see #send(String, int, boolean)
* @see #send(File)
* @see #send(File, boolean)
* @see #send(File, int)
* @see #send(File, int, boolean)
* @since 02.00.00
* @author Ktt Development
*/
Expand All @@ -532,6 +559,10 @@ static SimpleHttpExchange create(final HttpExchange exchange){
* @see #send(String)
* @see #send(String, boolean)
* @see #send(String, int, boolean)
* @see #send(File)
* @see #send(File, boolean)
* @see #send(File, int)
* @see #send(File, int, boolean)
* @since 02.00.00
* @author Ktt Development
*/
Expand All @@ -554,11 +585,115 @@ static SimpleHttpExchange create(final HttpExchange exchange){
* @see #send(String)
* @see #send(String, boolean)
* @see #send(String, int)
* @see #send(File)
* @see #send(File, boolean)
* @see #send(File, int)
* @see #send(File, int, boolean)
* @since 02.00.00
* @author Ktt Development
*/
public abstract void send(final String response, final int responseCode, final boolean gzip) throws IOException;

/**
* Sends a file to the client.
*
* @param file file to send
* @throws IOException internal server error or file read error
*
* @see #sendResponseHeaders(int, long)
* @see #send(int)
* @see #send(byte[])
* @see #send(byte[], boolean)
* @see #send(byte[], int)
* @see #send(byte[], int, boolean)
* @see #send(String)
* @see #send(String, boolean)
* @see #send(String, int)
* @see #send(String, int, boolean)
* @see #send(File, boolean)
* @see #send(File, int)
* @see #send(File, int, boolean)
* @since 4.0.0
* @author Ktt Development
*/
public abstract void send(final File file) throws IOException;

/**
* Sends a file to the client.
*
* @param file file to send
* @param gzip if the response should be gziped before sending it to the client
* @throws IOException internal server error or file read error
*
* @see #sendResponseHeaders(int, long)
* @see #send(int)
* @see #send(byte[])
* @see #send(byte[], boolean)
* @see #send(byte[], int)
* @see #send(byte[], int, boolean)
* @see #send(String)
* @see #send(String, boolean)
* @see #send(String, int)
* @see #send(String, int, boolean)
* @see #send(File)
* @see #send(File, int)
* @see #send(File, int, boolean)
* @since 4.0.0
* @author Ktt Development
*/
public abstract void send(final File file, final boolean gzip) throws IOException;

/**
* Sends a file with response code to the client.
*
* @param file file to send
* @param responseCode response code
* @throws IOException internal server error or file read error
*
* @see #sendResponseHeaders(int, long)
* @see #send(int)
* @see #send(byte[])
* @see #send(byte[], boolean)
* @see #send(byte[], int)
* @see #send(byte[], int, boolean)
* @see #send(String)
* @see #send(String, boolean)
* @see #send(String, int)
* @see #send(String, int, boolean)
* @see #send(File)
* @see #send(File, boolean)
* @see #send(File, int, boolean)
* @since 4.0.0
* @author Ktt Development
*/
public abstract void send(final File file, final int responseCode) throws IOException;

/**
* Sends a file with response code to the client.
*
* @param file file to send
* @param responseCode response code
* @param gzip if the response should be gziped before sending it to the client
* @throws IOException internal server error or file read error
*
* @see #sendResponseHeaders(int, long)
* @see #send(int)
* @see #send(byte[])
* @see #send(byte[], boolean)
* @see #send(byte[], int)
* @see #send(byte[], int, boolean)
* @see #send(String)
* @see #send(String, boolean)
* @see #send(String, int)
* @see #send(String, int, boolean)
* @see #send(File)
* @see #send(File, boolean)
* @see #send(File, int)
* @since 4.0.0
* @author Ktt Development
*/
public abstract void send(final File file, final int responseCode, final boolean gzip) throws IOException;

//

/**
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.io.*;
import java.net.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.*;
import java.util.function.Function;
import java.util.regex.Matcher;
Expand All @@ -17,7 +18,7 @@
*
* @see SimpleHttpExchange
* @since 02.00.00
* @version 03.05.00
* @version 4.0.0
* @author Ktt Development
*/
@SuppressWarnings("SpellCheckingInspection")
Expand Down Expand Up @@ -390,6 +391,26 @@ public final void send(final String response, final int responseCode, final bool
send(response.getBytes(StandardCharsets.UTF_8),responseCode,gzip);
}

@Override
public final void send(final File file) throws IOException{
send(Files.readAllBytes(file.toPath()));
}

@Override
public final void send(final File file, final boolean gzip) throws IOException{
send(Files.readAllBytes(file.toPath()), true);
}

@Override
public final void send(final File file, final int responseCode) throws IOException{
send(Files.readAllBytes(file.toPath()),responseCode);
}

@Override
public final void send(final File file, final int responseCode, final boolean gzip) throws IOException{
send(Files.readAllBytes(file.toPath()),responseCode,gzip);
}

//

@Override
Expand Down
Loading
Toggle all file notes Toggle all file annotations

Footer

© 2026 GitHub, Inc.