-
Notifications
You must be signed in to change notification settings - Fork 270
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
86 changed files
with
3,107 additions
and
3,059 deletions.
There are no files selected for viewing
This file contains 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,5 +1,24 @@ | ||
<!--- | ||
PLEASE NOTE: | ||
Before creating an issue, please think about wheter you are really reporting an issue or just have a question/problem. The latter are better suited for Stackoverflow or gitter (https://gitter.im/libaums). The best approach for a question or problem regarding libaums is to ask on Stackoverflow and hint me to the question via gitter! | ||
|
||
If you are sure that you would like to open an issue, please delete all of this message and continue. | ||
Thank you! | ||
--> | ||
|
||
### Problem | ||
|
||
|
||
### Expected behavior | ||
|
||
|
||
### Actual behavior | ||
|
||
|
||
#### Stacktrace of Excpetion | ||
|
||
``` | ||
(if exists) | ||
``` | ||
|
||
|
||
### Code where problem occurs | ||
|
This file contains 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
This file contains 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,6 +1,7 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
|
||
buildscript { | ||
ext.kotlin_version = '1.3.41' | ||
repositories { | ||
jcenter() | ||
maven { | ||
|
@@ -13,13 +14,14 @@ buildscript { | |
google() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:3.3.1' | ||
classpath 'com.android.tools.build:gradle:3.4.2' | ||
|
||
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' | ||
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' | ||
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.3' | ||
classpath 'com.dicedmelon.gradle:jacoco-android:0.1.4' | ||
|
||
classpath 'org.codehaus.groovy:groovy-all:2.4.15' | ||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | ||
|
||
// NOTE: Do not place your application dependencies here; they belong | ||
// in the individual module build.gradle files | ||
|
@@ -43,7 +45,7 @@ ext { | |
|
||
developerId = 'mjdev' | ||
developerName = 'mjahnen' | ||
developerEmail = '[email protected]' | ||
developerEmail = '[email protected]' | ||
|
||
licenseName = 'The Apache Software License, Version 2.0' | ||
licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' | ||
|
This file contains 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
This file contains 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
108 changes: 0 additions & 108 deletions
108
httpserver/src/main/java/com/github/mjdev/libaums/server/http/UsbFileHttpServer.java
This file was deleted.
Oops, something went wrong.
109 changes: 109 additions & 0 deletions
109
httpserver/src/main/java/com/github/mjdev/libaums/server/http/UsbFileHttpServer.kt
This file contains 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 |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
* (C) Copyright 2016 mjahnen <[email protected]> | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package com.github.mjdev.libaums.server.http | ||
|
||
import android.util.Log | ||
import android.util.LruCache | ||
|
||
import com.github.mjdev.libaums.fs.UsbFile | ||
import com.github.mjdev.libaums.server.http.exception.NotAFileException | ||
import com.github.mjdev.libaums.server.http.server.HttpServer | ||
|
||
|
||
import java.io.FileNotFoundException | ||
import java.io.IOException | ||
|
||
/** | ||
* This class allows to start a HTTP web server which can serve [com.github.mjdev.libaums.fs.UsbFile]s | ||
* to another app. | ||
* | ||
* For instance it can make an image available to the Web Browser without copying it to the internal | ||
* storage, or a video file to a video file as a HTTP stream. | ||
*/ | ||
class UsbFileHttpServer(private val rootFile: UsbFile, private val server: HttpServer) : UsbFileProvider { | ||
private val fileCache = LruCache<String, UsbFile>(100) | ||
|
||
val baseUrl: String | ||
get() { | ||
var hostname: String? = server.hostname | ||
if (hostname == null) { | ||
hostname = "localhost" | ||
} | ||
return "http://" + hostname + ":" + server.listeningPort + "/" | ||
} | ||
|
||
val isAlive: Boolean | ||
get() = server.isAlive | ||
|
||
init { | ||
server.setUsbFileProvider(this) | ||
} | ||
|
||
@Throws(IOException::class) | ||
fun start() { | ||
server.start() | ||
} | ||
|
||
@Throws(IOException::class) | ||
fun stop() { | ||
server.stop() | ||
fileCache.evictAll() | ||
} | ||
|
||
@Throws(IOException::class) | ||
override fun determineFileToServe(uri: String): UsbFile { | ||
var fileToServe: UsbFile? = fileCache.get(uri) | ||
|
||
if (fileToServe == null) { | ||
Log.d(TAG, "Searching file on USB (URI: $uri)") | ||
if (!rootFile.isDirectory) { | ||
Log.d(TAG, "Serving root file") | ||
if ("/" != uri && "/" + rootFile.name != uri) { | ||
Log.d(TAG, "Invalid request, respond with 404") | ||
throw FileNotFoundException("Not found $uri") | ||
} | ||
|
||
|
||
fileToServe = rootFile | ||
} else { | ||
fileToServe = rootFile.search(uri.substring(1)) | ||
} | ||
} else { | ||
Log.d(TAG, "Using lru cache for $uri") | ||
} | ||
|
||
|
||
if (fileToServe == null) { | ||
Log.d(TAG, "fileToServe == null") | ||
throw FileNotFoundException("Not found $uri") | ||
} | ||
|
||
if (fileToServe.isDirectory) { | ||
throw NotAFileException() | ||
} | ||
|
||
fileCache.put(uri, fileToServe) | ||
|
||
return fileToServe | ||
} | ||
|
||
companion object { | ||
|
||
private val TAG = UsbFileHttpServer::class.java.simpleName | ||
} | ||
} |
Oops, something went wrong.