repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
baby2431/renovate2
rx-renovate/src/main/java/renovate/rxjava/adapter/SingleResponse.java
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // }
import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Response; import rx.Single;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class SingleResponse<T> implements CallAdapter<T, Single<Response<T>>> { @Override
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // } // Path: rx-renovate/src/main/java/renovate/rxjava/adapter/SingleResponse.java import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Response; import rx.Single; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class SingleResponse<T> implements CallAdapter<T, Single<Response<T>>> { @Override
public Single<Response<T>> adapt(Call<T> call, AdapterParam param) {
baby2431/renovate2
rx-renovate/src/main/java/renovate/rxjava/adapter/SingleResponse.java
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // }
import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Response; import rx.Single;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class SingleResponse<T> implements CallAdapter<T, Single<Response<T>>> { @Override
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // } // Path: rx-renovate/src/main/java/renovate/rxjava/adapter/SingleResponse.java import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Response; import rx.Single; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class SingleResponse<T> implements CallAdapter<T, Single<Response<T>>> { @Override
public Single<Response<T>> adapt(Call<T> call, AdapterParam param) {
baby2431/renovate2
rx-renovate/src/main/java/renovate/rxjava/subscribe/CallArbiter.java
// Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // }
import renovate.Call; import renovate.Response; import rx.Producer; import rx.Subscriber; import rx.Subscription; import rx.exceptions.*; import rx.plugins.RxJavaPlugins; import java.util.concurrent.atomic.AtomicInteger;
package renovate.rxjava.subscribe; final class CallArbiter<T> extends AtomicInteger implements Subscription, Producer { private static final int STATE_WAITING = 0; private static final int STATE_REQUESTED = 1; private static final int STATE_HAS_RESPONSE = 2; private static final int STATE_TERMINATED = 3;
// Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // } // Path: rx-renovate/src/main/java/renovate/rxjava/subscribe/CallArbiter.java import renovate.Call; import renovate.Response; import rx.Producer; import rx.Subscriber; import rx.Subscription; import rx.exceptions.*; import rx.plugins.RxJavaPlugins; import java.util.concurrent.atomic.AtomicInteger; package renovate.rxjava.subscribe; final class CallArbiter<T> extends AtomicInteger implements Subscription, Producer { private static final int STATE_WAITING = 0; private static final int STATE_REQUESTED = 1; private static final int STATE_HAS_RESPONSE = 2; private static final int STATE_TERMINATED = 3;
private final Call<T> call;
baby2431/renovate2
rx-renovate/src/main/java/renovate/rxjava/subscribe/CallArbiter.java
// Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // }
import renovate.Call; import renovate.Response; import rx.Producer; import rx.Subscriber; import rx.Subscription; import rx.exceptions.*; import rx.plugins.RxJavaPlugins; import java.util.concurrent.atomic.AtomicInteger;
package renovate.rxjava.subscribe; final class CallArbiter<T> extends AtomicInteger implements Subscription, Producer { private static final int STATE_WAITING = 0; private static final int STATE_REQUESTED = 1; private static final int STATE_HAS_RESPONSE = 2; private static final int STATE_TERMINATED = 3; private final Call<T> call;
// Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // } // Path: rx-renovate/src/main/java/renovate/rxjava/subscribe/CallArbiter.java import renovate.Call; import renovate.Response; import rx.Producer; import rx.Subscriber; import rx.Subscription; import rx.exceptions.*; import rx.plugins.RxJavaPlugins; import java.util.concurrent.atomic.AtomicInteger; package renovate.rxjava.subscribe; final class CallArbiter<T> extends AtomicInteger implements Subscription, Producer { private static final int STATE_WAITING = 0; private static final int STATE_REQUESTED = 1; private static final int STATE_HAS_RESPONSE = 2; private static final int STATE_TERMINATED = 3; private final Call<T> call;
private final Subscriber<? super Response<T>> subscriber;
baby2431/renovate2
rx-renovate2/src/main/java/renovate/rxjava2/adapter/FlowableBody.java
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // }
import io.reactivex.BackpressureStrategy; import io.reactivex.Flowable; import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class FlowableBody<T> implements CallAdapter<T, Flowable<T>> { @Override
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // Path: rx-renovate2/src/main/java/renovate/rxjava2/adapter/FlowableBody.java import io.reactivex.BackpressureStrategy; import io.reactivex.Flowable; import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class FlowableBody<T> implements CallAdapter<T, Flowable<T>> { @Override
public Flowable<T> adapt(Call<T> call, AdapterParam param) {
baby2431/renovate2
rx-renovate2/src/main/java/renovate/rxjava2/adapter/FlowableBody.java
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // }
import io.reactivex.BackpressureStrategy; import io.reactivex.Flowable; import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class FlowableBody<T> implements CallAdapter<T, Flowable<T>> { @Override
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // Path: rx-renovate2/src/main/java/renovate/rxjava2/adapter/FlowableBody.java import io.reactivex.BackpressureStrategy; import io.reactivex.Flowable; import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class FlowableBody<T> implements CallAdapter<T, Flowable<T>> { @Override
public Flowable<T> adapt(Call<T> call, AdapterParam param) {
baby2431/renovate2
rx-renovate/src/main/java/renovate/rxjava/adapter/SingleResult.java
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Result.java // public final class Result<T> { // @SuppressWarnings("ConstantConditions") // Guarding public API nullability. // public static <T> Result<T> error(Throwable error) { // if (error == null) throw new NullPointerException("error == null"); // return new Result<>(null, error); // } // // @SuppressWarnings("ConstantConditions") // Guarding public API nullability. // public static <T> Result<T> response(Response<T> response) { // if (response == null) throw new NullPointerException("response == null"); // return new Result<>(response, null); // } // // private final Response<T> response; // private final Throwable error; // // private Result(Response<T> response, Throwable error) { // this.response = response; // this.error = error; // } // // /** // * The response received from executing an HTTP request. Only present when {@link #isError()} is // * false, null otherwise. // */ // // public Response<T> response() { // return response; // } // // /** // * The error experienced while attempting to execute an HTTP request. Only present when {@link // * #isError()} is true, null otherwise. // * If the error is an {@link IOException} then there was a problem with the transport to the // * remote server. Any other exception type indicates an unexpected failure and should be // * considered fatal (configuration error, programming error, etc.). // */ // // public Throwable error() { // return error; // } // // /** {@code true} if the request resulted in an error. See {@link #error()} for the cause. */ // public boolean isError() { // return error != null; // } // // @Override // public String toString() { // if (error != null) { // return "Result{isError=true, error=\"" + error + "\"}"; // } // return "Result{isError=false, response=" + response + '}'; // } // }
import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Result; import rx.Single;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class SingleResult<T> implements CallAdapter<T, Single<Result<T>>> { @Override
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Result.java // public final class Result<T> { // @SuppressWarnings("ConstantConditions") // Guarding public API nullability. // public static <T> Result<T> error(Throwable error) { // if (error == null) throw new NullPointerException("error == null"); // return new Result<>(null, error); // } // // @SuppressWarnings("ConstantConditions") // Guarding public API nullability. // public static <T> Result<T> response(Response<T> response) { // if (response == null) throw new NullPointerException("response == null"); // return new Result<>(response, null); // } // // private final Response<T> response; // private final Throwable error; // // private Result(Response<T> response, Throwable error) { // this.response = response; // this.error = error; // } // // /** // * The response received from executing an HTTP request. Only present when {@link #isError()} is // * false, null otherwise. // */ // // public Response<T> response() { // return response; // } // // /** // * The error experienced while attempting to execute an HTTP request. Only present when {@link // * #isError()} is true, null otherwise. // * If the error is an {@link IOException} then there was a problem with the transport to the // * remote server. Any other exception type indicates an unexpected failure and should be // * considered fatal (configuration error, programming error, etc.). // */ // // public Throwable error() { // return error; // } // // /** {@code true} if the request resulted in an error. See {@link #error()} for the cause. */ // public boolean isError() { // return error != null; // } // // @Override // public String toString() { // if (error != null) { // return "Result{isError=true, error=\"" + error + "\"}"; // } // return "Result{isError=false, response=" + response + '}'; // } // } // Path: rx-renovate/src/main/java/renovate/rxjava/adapter/SingleResult.java import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Result; import rx.Single; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class SingleResult<T> implements CallAdapter<T, Single<Result<T>>> { @Override
public Single<Result<T>> adapt(Call<T> call, AdapterParam param) {
baby2431/renovate2
rx-renovate/src/main/java/renovate/rxjava/adapter/SingleResult.java
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Result.java // public final class Result<T> { // @SuppressWarnings("ConstantConditions") // Guarding public API nullability. // public static <T> Result<T> error(Throwable error) { // if (error == null) throw new NullPointerException("error == null"); // return new Result<>(null, error); // } // // @SuppressWarnings("ConstantConditions") // Guarding public API nullability. // public static <T> Result<T> response(Response<T> response) { // if (response == null) throw new NullPointerException("response == null"); // return new Result<>(response, null); // } // // private final Response<T> response; // private final Throwable error; // // private Result(Response<T> response, Throwable error) { // this.response = response; // this.error = error; // } // // /** // * The response received from executing an HTTP request. Only present when {@link #isError()} is // * false, null otherwise. // */ // // public Response<T> response() { // return response; // } // // /** // * The error experienced while attempting to execute an HTTP request. Only present when {@link // * #isError()} is true, null otherwise. // * If the error is an {@link IOException} then there was a problem with the transport to the // * remote server. Any other exception type indicates an unexpected failure and should be // * considered fatal (configuration error, programming error, etc.). // */ // // public Throwable error() { // return error; // } // // /** {@code true} if the request resulted in an error. See {@link #error()} for the cause. */ // public boolean isError() { // return error != null; // } // // @Override // public String toString() { // if (error != null) { // return "Result{isError=true, error=\"" + error + "\"}"; // } // return "Result{isError=false, response=" + response + '}'; // } // }
import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Result; import rx.Single;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class SingleResult<T> implements CallAdapter<T, Single<Result<T>>> { @Override
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Result.java // public final class Result<T> { // @SuppressWarnings("ConstantConditions") // Guarding public API nullability. // public static <T> Result<T> error(Throwable error) { // if (error == null) throw new NullPointerException("error == null"); // return new Result<>(null, error); // } // // @SuppressWarnings("ConstantConditions") // Guarding public API nullability. // public static <T> Result<T> response(Response<T> response) { // if (response == null) throw new NullPointerException("response == null"); // return new Result<>(response, null); // } // // private final Response<T> response; // private final Throwable error; // // private Result(Response<T> response, Throwable error) { // this.response = response; // this.error = error; // } // // /** // * The response received from executing an HTTP request. Only present when {@link #isError()} is // * false, null otherwise. // */ // // public Response<T> response() { // return response; // } // // /** // * The error experienced while attempting to execute an HTTP request. Only present when {@link // * #isError()} is true, null otherwise. // * If the error is an {@link IOException} then there was a problem with the transport to the // * remote server. Any other exception type indicates an unexpected failure and should be // * considered fatal (configuration error, programming error, etc.). // */ // // public Throwable error() { // return error; // } // // /** {@code true} if the request resulted in an error. See {@link #error()} for the cause. */ // public boolean isError() { // return error != null; // } // // @Override // public String toString() { // if (error != null) { // return "Result{isError=true, error=\"" + error + "\"}"; // } // return "Result{isError=false, response=" + response + '}'; // } // } // Path: rx-renovate/src/main/java/renovate/rxjava/adapter/SingleResult.java import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Result; import rx.Single; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class SingleResult<T> implements CallAdapter<T, Single<Result<T>>> { @Override
public Single<Result<T>> adapt(Call<T> call, AdapterParam param) {
baby2431/renovate2
rx-renovate/src/main/java/renovate/rxjava/adapter/ObservableResponse.java
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // }
import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Response; import rx.Observable;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class ObservableResponse<T> implements CallAdapter<T, Observable<Response<T>>> { @Override
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // } // Path: rx-renovate/src/main/java/renovate/rxjava/adapter/ObservableResponse.java import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Response; import rx.Observable; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class ObservableResponse<T> implements CallAdapter<T, Observable<Response<T>>> { @Override
public Observable<Response<T>> adapt(Call<T> call, AdapterParam param) {
baby2431/renovate2
rx-renovate/src/main/java/renovate/rxjava/adapter/ObservableResponse.java
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // }
import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Response; import rx.Observable;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class ObservableResponse<T> implements CallAdapter<T, Observable<Response<T>>> { @Override
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // } // Path: rx-renovate/src/main/java/renovate/rxjava/adapter/ObservableResponse.java import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Response; import rx.Observable; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class ObservableResponse<T> implements CallAdapter<T, Observable<Response<T>>> { @Override
public Observable<Response<T>> adapt(Call<T> call, AdapterParam param) {
baby2431/renovate2
rx-renovate/src/main/java/renovate/rxjava/adapter/SingleBody.java
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // }
import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import rx.Single;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class SingleBody<T> implements CallAdapter<T, Single<T>> { @Override
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // Path: rx-renovate/src/main/java/renovate/rxjava/adapter/SingleBody.java import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import rx.Single; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class SingleBody<T> implements CallAdapter<T, Single<T>> { @Override
public Single<T> adapt(Call<T> call, AdapterParam param) {
baby2431/renovate2
rx-renovate/src/main/java/renovate/rxjava/adapter/SingleBody.java
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // }
import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import rx.Single;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class SingleBody<T> implements CallAdapter<T, Single<T>> { @Override
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // Path: rx-renovate/src/main/java/renovate/rxjava/adapter/SingleBody.java import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import rx.Single; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class SingleBody<T> implements CallAdapter<T, Single<T>> { @Override
public Single<T> adapt(Call<T> call, AdapterParam param) {
baby2431/renovate2
rx-renovate2/src/main/java/renovate/rxjava2/adapter/MaybeResponse.java
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // }
import io.reactivex.Maybe; import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Response;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class MaybeResponse<T> implements CallAdapter<T, Maybe<Response<T>>> { @Override
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // } // Path: rx-renovate2/src/main/java/renovate/rxjava2/adapter/MaybeResponse.java import io.reactivex.Maybe; import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Response; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class MaybeResponse<T> implements CallAdapter<T, Maybe<Response<T>>> { @Override
public Maybe<Response<T>> adapt(Call<T> call, AdapterParam param) {
baby2431/renovate2
rx-renovate2/src/main/java/renovate/rxjava2/adapter/MaybeResponse.java
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // }
import io.reactivex.Maybe; import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Response;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class MaybeResponse<T> implements CallAdapter<T, Maybe<Response<T>>> { @Override
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // } // Path: rx-renovate2/src/main/java/renovate/rxjava2/adapter/MaybeResponse.java import io.reactivex.Maybe; import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Response; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class MaybeResponse<T> implements CallAdapter<T, Maybe<Response<T>>> { @Override
public Maybe<Response<T>> adapt(Call<T> call, AdapterParam param) {
baby2431/renovate2
rx-renovate2/src/main/java/renovate/rxjava2/adapter/SingleResponse.java
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // }
import io.reactivex.Single; import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Response;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class SingleResponse<T> implements CallAdapter<T, Single<Response<T>>> { @Override
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // } // Path: rx-renovate2/src/main/java/renovate/rxjava2/adapter/SingleResponse.java import io.reactivex.Single; import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Response; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class SingleResponse<T> implements CallAdapter<T, Single<Response<T>>> { @Override
public Single<Response<T>> adapt(Call<T> call, AdapterParam param) {
baby2431/renovate2
rx-renovate2/src/main/java/renovate/rxjava2/adapter/SingleResponse.java
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // }
import io.reactivex.Single; import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Response;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class SingleResponse<T> implements CallAdapter<T, Single<Response<T>>> { @Override
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // } // Path: rx-renovate2/src/main/java/renovate/rxjava2/adapter/SingleResponse.java import io.reactivex.Single; import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Response; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class SingleResponse<T> implements CallAdapter<T, Single<Response<T>>> { @Override
public Single<Response<T>> adapt(Call<T> call, AdapterParam param) {
baby2431/renovate2
rx-renovate2/src/main/java/renovate/rxjava2/adapter/SingleBody.java
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // }
import io.reactivex.Single; import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class SingleBody<T> implements CallAdapter<T, Single<T>> { @Override
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // Path: rx-renovate2/src/main/java/renovate/rxjava2/adapter/SingleBody.java import io.reactivex.Single; import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class SingleBody<T> implements CallAdapter<T, Single<T>> { @Override
public Single<T> adapt(Call<T> call, AdapterParam param) {
baby2431/renovate2
rx-renovate2/src/main/java/renovate/rxjava2/adapter/SingleBody.java
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // }
import io.reactivex.Single; import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class SingleBody<T> implements CallAdapter<T, Single<T>> { @Override
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // Path: rx-renovate2/src/main/java/renovate/rxjava2/adapter/SingleBody.java import io.reactivex.Single; import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class SingleBody<T> implements CallAdapter<T, Single<T>> { @Override
public Single<T> adapt(Call<T> call, AdapterParam param) {
baby2431/renovate2
rx-renovate2/src/main/java/renovate/rxjava2/adapter/ObservableResult.java
// Path: rx-renovate2/src/main/java/renovate/rxjava2/observable/ResultObservable.java // public class ResultObservable<T> extends Observable<Result<T>> { // private final Observable<Response<T>> upstream; // // public ResultObservable(Observable<Response<T>> upstream) { // this.upstream = upstream; // } // // @Override // protected void subscribeActual(Observer<? super Result<T>> observer) { // upstream.subscribe(new ResultObserver<T>(observer)); // } // // private static class ResultObserver<R> implements Observer<Response<R>> { // private final Observer<? super Result<R>> observer; // // ResultObserver(Observer<? super Result<R>> observer) { // this.observer = observer; // } // // @Override // public void onSubscribe(Disposable disposable) { // observer.onSubscribe(disposable); // } // // @Override // public void onNext(Response<R> response) { // observer.onNext(Result.response(response)); // } // // @Override // public void onError(Throwable throwable) { // try { // observer.onNext(Result.<R>error(throwable)); // } catch (Throwable t) { // try { // observer.onError(t); // } catch (Throwable inner) { // Exceptions.throwIfFatal(inner); // RxJavaPlugins.onError(new CompositeException(t, inner)); // } // return; // } // observer.onComplete(); // } // // @Override // public void onComplete() { // observer.onComplete(); // } // } // }
import io.reactivex.Observable; import renovate.*; import renovate.rxjava2.observable.ResultObservable;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class ObservableResult<T> implements CallAdapter<T, Observable<Result<T>>> { @Override public Observable<Result<T>> adapt(Call<T> call, AdapterParam param) { Observable<Response<T>> observable = AnalysisParams.analysis(call, param);
// Path: rx-renovate2/src/main/java/renovate/rxjava2/observable/ResultObservable.java // public class ResultObservable<T> extends Observable<Result<T>> { // private final Observable<Response<T>> upstream; // // public ResultObservable(Observable<Response<T>> upstream) { // this.upstream = upstream; // } // // @Override // protected void subscribeActual(Observer<? super Result<T>> observer) { // upstream.subscribe(new ResultObserver<T>(observer)); // } // // private static class ResultObserver<R> implements Observer<Response<R>> { // private final Observer<? super Result<R>> observer; // // ResultObserver(Observer<? super Result<R>> observer) { // this.observer = observer; // } // // @Override // public void onSubscribe(Disposable disposable) { // observer.onSubscribe(disposable); // } // // @Override // public void onNext(Response<R> response) { // observer.onNext(Result.response(response)); // } // // @Override // public void onError(Throwable throwable) { // try { // observer.onNext(Result.<R>error(throwable)); // } catch (Throwable t) { // try { // observer.onError(t); // } catch (Throwable inner) { // Exceptions.throwIfFatal(inner); // RxJavaPlugins.onError(new CompositeException(t, inner)); // } // return; // } // observer.onComplete(); // } // // @Override // public void onComplete() { // observer.onComplete(); // } // } // } // Path: rx-renovate2/src/main/java/renovate/rxjava2/adapter/ObservableResult.java import io.reactivex.Observable; import renovate.*; import renovate.rxjava2.observable.ResultObservable; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class ObservableResult<T> implements CallAdapter<T, Observable<Result<T>>> { @Override public Observable<Result<T>> adapt(Call<T> call, AdapterParam param) { Observable<Response<T>> observable = AnalysisParams.analysis(call, param);
return new ResultObservable<>(observable);
baby2431/renovate2
rx-renovate2/src/main/java/renovate/rxjava2/adapter/ObservableResponse.java
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // }
import io.reactivex.Observable; import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Response;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class ObservableResponse<T> implements CallAdapter<T, Observable<Response<T>>> { @Override
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // } // Path: rx-renovate2/src/main/java/renovate/rxjava2/adapter/ObservableResponse.java import io.reactivex.Observable; import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Response; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class ObservableResponse<T> implements CallAdapter<T, Observable<Response<T>>> { @Override
public Observable<Response<T>> adapt(Call<T> call, AdapterParam param) {
baby2431/renovate2
rx-renovate2/src/main/java/renovate/rxjava2/adapter/ObservableResponse.java
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // }
import io.reactivex.Observable; import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Response;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class ObservableResponse<T> implements CallAdapter<T, Observable<Response<T>>> { @Override
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // // Path: renovate/src/main/java/renovate/Response.java // public final class Response<T> { // private final okhttp3.Response rawResponse; // private final T body; // private final ResponseBody errorBody; // // private Response(okhttp3.Response rawResponse, T body, ResponseBody errorBody) { // this.rawResponse = rawResponse; // this.body = body; // this.errorBody = errorBody; // } // // public static <T> Response<T> success(T body) { // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, Headers headers) { // if (headers == null) throw new NullPointerException("headers == null"); // return success(body, new okhttp3.Response.Builder() // // .code(200) // .message("OK") // .protocol(Protocol.HTTP_1_1) // .headers(headers) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> success(T body, okhttp3.Response rawResponse) { // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (!rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse must be successful response"); // } // return new Response<>(rawResponse, body, null); // } // // public static <T> Response<T> error(int code, ResponseBody body) { // if (code < 400) throw new IllegalArgumentException("code < 400: " + code); // return error(body, new okhttp3.Response.Builder() // // .code(code) // .protocol(Protocol.HTTP_1_1) // .request(new Request.Builder().url("http://localhost/").build()) // .build()); // } // // public static <T> Response<T> error(ResponseBody body, okhttp3.Response rawResponse) { // if (body == null) throw new NullPointerException("body == null"); // if (rawResponse == null) throw new NullPointerException("rawResponse == null"); // if (rawResponse.isSuccessful()) { // throw new IllegalArgumentException("rawResponse should not be successful response"); // } // return new Response<>(rawResponse, null, body); // } // // public okhttp3.Response raw() { // return rawResponse; // } // // public int code() { // return rawResponse.code(); // } // // public String message() { // return rawResponse.message(); // } // // public Headers headers() { // return rawResponse.headers(); // } // // public boolean isSuccessful() { // return rawResponse.isSuccessful(); // } // // public T body() { // return body; // } // // public ResponseBody errorBody() { // return errorBody; // } // // @Override public String toString() { // return rawResponse.toString(); // } // } // Path: rx-renovate2/src/main/java/renovate/rxjava2/adapter/ObservableResponse.java import io.reactivex.Observable; import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import renovate.Response; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava2.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/27 * 描 述: * 修订历史: * ================================================ */ public class ObservableResponse<T> implements CallAdapter<T, Observable<Response<T>>> { @Override
public Observable<Response<T>> adapt(Call<T> call, AdapterParam param) {
baby2431/renovate2
rx-renovate/src/main/java/renovate/rxjava/adapter/ObservableResult.java
// Path: rx-renovate/src/main/java/renovate/rxjava/subscribe/ResultOnSubscribe.java // public final class ResultOnSubscribe<T> implements OnSubscribe<Result<T>> { // private final OnSubscribe<Response<T>> upstream; // // public ResultOnSubscribe(OnSubscribe<Response<T>> upstream) { // this.upstream = upstream; // } // // @Override // public void call(Subscriber<? super Result<T>> subscriber) { // upstream.call(new ResultSubscriber<T>(subscriber)); // } // // private static class ResultSubscriber<R> extends Subscriber<Response<R>> { // // private final Subscriber<? super Result<R>> subscriber; // // ResultSubscriber(Subscriber<? super Result<R>> subscriber) { // super(subscriber); // this.subscriber = subscriber; // } // // @Override // public void onNext(Response<R> response) { // subscriber.onNext(Result.response(response)); // } // // @Override // public void onError(Throwable throwable) { // try { // subscriber.onNext(Result.<R>error(throwable)); // } catch (Throwable t) { // try { // subscriber.onError(t); // } catch (OnCompletedFailedException | OnErrorFailedException | OnErrorNotImplementedException e) { // RxJavaHooks.getOnError().call(e); // } catch (Throwable inner) { // Exceptions.throwIfFatal(inner); // RxJavaHooks.getOnError().call(new CompositeException(t, inner)); // } // return; // } // subscriber.onCompleted(); // } // // @Override // public void onCompleted() { // subscriber.onCompleted(); // } // } // }
import renovate.*; import renovate.rxjava.subscribe.ResultOnSubscribe; import rx.Observable;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class ObservableResult<T> implements CallAdapter<T, Observable<Result<T>>> { @Override public Observable<Result<T>> adapt(Call<T> call, AdapterParam param) { Observable.OnSubscribe<Response<T>> subscribe = AnalysisParams.analysis(call, param);
// Path: rx-renovate/src/main/java/renovate/rxjava/subscribe/ResultOnSubscribe.java // public final class ResultOnSubscribe<T> implements OnSubscribe<Result<T>> { // private final OnSubscribe<Response<T>> upstream; // // public ResultOnSubscribe(OnSubscribe<Response<T>> upstream) { // this.upstream = upstream; // } // // @Override // public void call(Subscriber<? super Result<T>> subscriber) { // upstream.call(new ResultSubscriber<T>(subscriber)); // } // // private static class ResultSubscriber<R> extends Subscriber<Response<R>> { // // private final Subscriber<? super Result<R>> subscriber; // // ResultSubscriber(Subscriber<? super Result<R>> subscriber) { // super(subscriber); // this.subscriber = subscriber; // } // // @Override // public void onNext(Response<R> response) { // subscriber.onNext(Result.response(response)); // } // // @Override // public void onError(Throwable throwable) { // try { // subscriber.onNext(Result.<R>error(throwable)); // } catch (Throwable t) { // try { // subscriber.onError(t); // } catch (OnCompletedFailedException | OnErrorFailedException | OnErrorNotImplementedException e) { // RxJavaHooks.getOnError().call(e); // } catch (Throwable inner) { // Exceptions.throwIfFatal(inner); // RxJavaHooks.getOnError().call(new CompositeException(t, inner)); // } // return; // } // subscriber.onCompleted(); // } // // @Override // public void onCompleted() { // subscriber.onCompleted(); // } // } // } // Path: rx-renovate/src/main/java/renovate/rxjava/adapter/ObservableResult.java import renovate.*; import renovate.rxjava.subscribe.ResultOnSubscribe; import rx.Observable; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class ObservableResult<T> implements CallAdapter<T, Observable<Result<T>>> { @Override public Observable<Result<T>> adapt(Call<T> call, AdapterParam param) { Observable.OnSubscribe<Response<T>> subscribe = AnalysisParams.analysis(call, param);
ResultOnSubscribe<T> resultSubscribe = new ResultOnSubscribe<>(subscribe);
baby2431/renovate2
rx-renovate/src/main/java/renovate/rxjava/adapter/CompletableResponse.java
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // }
import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import rx.Completable;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class CompletableResponse<T> implements CallAdapter<T, Completable> { @Override
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // Path: rx-renovate/src/main/java/renovate/rxjava/adapter/CompletableResponse.java import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import rx.Completable; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class CompletableResponse<T> implements CallAdapter<T, Completable> { @Override
public Completable adapt(Call<T> call, AdapterParam param) {
baby2431/renovate2
rx-renovate/src/main/java/renovate/rxjava/adapter/CompletableResponse.java
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // }
import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import rx.Completable;
/* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class CompletableResponse<T> implements CallAdapter<T, Completable> { @Override
// Path: renovate/src/main/java/renovate/AdapterParam.java // public class AdapterParam { // public boolean isAsync; // // public AdapterParam() { // isAsync = true; // } // } // // Path: renovate/src/main/java/renovate/Call.java // public interface Call<T> extends Cloneable { // Response<T> execute() throws IOException; // // void enqueue(Callback<T> callback); // // boolean isExecuted(); // // void cancel(); // // boolean isCanceled(); // // Call<T> clone(); // // Request request(); // } // // Path: renovate/src/main/java/renovate/CallAdapter.java // public interface CallAdapter<T, R> { // // /** call执行的代理方法 */ // R adapt(Call<T> call, AdapterParam param); // } // Path: rx-renovate/src/main/java/renovate/rxjava/adapter/CompletableResponse.java import renovate.AdapterParam; import renovate.Call; import renovate.CallAdapter; import rx.Completable; /* * Copyright 2016 jeasonlzy(廖子尧) * * 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 renovate.rxjava.adapter; /** * ================================================ * 作 者:jeasonlzy(廖子尧)Github地址:https://github.com/jeasonlzy * 版 本:1.0 * 创建日期:2017/5/26 * 描 述: * 修订历史: * ================================================ */ public class CompletableResponse<T> implements CallAdapter<T, Completable> { @Override
public Completable adapt(Call<T> call, AdapterParam param) {
Raphfrk/CraftProxyLiter
com/raphfrk/netutil/MaxLatencyBufferedOutputStream.java
// Path: com/raphfrk/protocol/KillableThread.java // public class KillableThread extends Thread { // // private ArrayList<KillableThread> children = new ArrayList<KillableThread>(); // // private boolean killed = false; // // public boolean killed() { // if(Thread.interrupted()) { // kill(); // } // // return killed; // } // // protected void kill() { // for(Thread t : children) { // t.interrupt(); // } // killed = true; // } // // protected void revive() { // Thread.interrupted(); // killed = false; // } // // boolean joinAll(int delay) throws InterruptedException { // kill(); // for(Thread t : children) { // t.join(delay); // if(t.isAlive()) { // return false; // } // } // // return true; // } // // }
import java.io.BufferedOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.ReentrantLock; import com.raphfrk.protocol.KillableThread;
clearFlush(); lock.lock(); try { //System.out.println("Flush happening " + System.currentTimeMillis()); super.flush(); } finally { lock.unlock(); } } public void close() throws IOException { while(timer.isAlive()) { timer.interrupt(); try { timer.join(50); } catch (InterruptedException ie) { try { Thread.currentThread().interrupt(); Thread.sleep(50); } catch (InterruptedException ie2) { Thread.currentThread().interrupt(); } } } }
// Path: com/raphfrk/protocol/KillableThread.java // public class KillableThread extends Thread { // // private ArrayList<KillableThread> children = new ArrayList<KillableThread>(); // // private boolean killed = false; // // public boolean killed() { // if(Thread.interrupted()) { // kill(); // } // // return killed; // } // // protected void kill() { // for(Thread t : children) { // t.interrupt(); // } // killed = true; // } // // protected void revive() { // Thread.interrupted(); // killed = false; // } // // boolean joinAll(int delay) throws InterruptedException { // kill(); // for(Thread t : children) { // t.join(delay); // if(t.isAlive()) { // return false; // } // } // // return true; // } // // } // Path: com/raphfrk/netutil/MaxLatencyBufferedOutputStream.java import java.io.BufferedOutputStream; import java.io.IOException; import java.io.OutputStream; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.locks.ReentrantLock; import com.raphfrk.protocol.KillableThread; clearFlush(); lock.lock(); try { //System.out.println("Flush happening " + System.currentTimeMillis()); super.flush(); } finally { lock.unlock(); } } public void close() throws IOException { while(timer.isAlive()) { timer.interrupt(); try { timer.join(50); } catch (InterruptedException ie) { try { Thread.currentThread().interrupt(); Thread.sleep(50); } catch (InterruptedException ie2) { Thread.currentThread().interrupt(); } } } }
private class LocalTimer extends KillableThread {
readlearncode/RESTful-Service-with-JAX-RS-2.0-Course
rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/rest/AuthorResource.java
// Path: rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/infrastructure/AuthorRepository.java // public interface AuthorRepository { // // Author saveAuthor(final Author author); // // Author deleteAuthor(final String id); // // List<Author> getAll(); // // Optional<Author> getById(String id); // // List<Author> saveAuthors(List<Author> authors); // }
import com.readlearncode.dukesbookshop.restserver.infrastructure.AuthorRepository; import javax.ejb.EJB; import javax.ejb.Stateless; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response;
package com.readlearncode.dukesbookshop.restserver.rest; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Stateless @Path("/authors") public class AuthorResource { @EJB
// Path: rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/infrastructure/AuthorRepository.java // public interface AuthorRepository { // // Author saveAuthor(final Author author); // // Author deleteAuthor(final String id); // // List<Author> getAll(); // // Optional<Author> getById(String id); // // List<Author> saveAuthors(List<Author> authors); // } // Path: rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/rest/AuthorResource.java import com.readlearncode.dukesbookshop.restserver.infrastructure.AuthorRepository; import javax.ejb.EJB; import javax.ejb.Stateless; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; package com.readlearncode.dukesbookshop.restserver.rest; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Stateless @Path("/authors") public class AuthorResource { @EJB
private AuthorRepository authorRepository;
readlearncode/RESTful-Service-with-JAX-RS-2.0-Course
rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/infrastructure/BookRepositoryBean.java
// Path: rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/domain/Book.java // @XmlRootElement // public class Book extends Hypermedia implements Serializable { // // private static final long serialVersionUID = 1L; // private static final String IMAGE_LOCATION = "/images/covers/"; // // @Size(min = 10, max = 10, message = "ISBN should be 10 characters") // private String id; // // @Size(min = 20) // private String title; // // @Size(min = 100) // private String description; // // @Size(min = 1) // private ArrayList<Author> authors = new ArrayList<>(); // Must use concrete List implementation as JAX-RS doesn't play nice with interfaces. // // @DecimalMin("0.00") // private Float price; // // @NotNull // private String imageFileName; // // @NotNull // @Pattern(regexp="^(https?:\\/\\/)?([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\\/\\w \\.-]*)*\\/?$") // private String link; // // @Past // Format 2018-08-25T00:00:00+01:00 // private Date published; // // public Book() { // // Required for serialisation/deserialisation // } // // public Book(String id, String title, String description, Float price, Date published, ArrayList<Author> authors, String imageFileName, String link) { // this.id = id; // this.title = title; // this.description = description; // this.price = price; // this.published = published; // this.authors = authors; // this.imageFileName = imageFileName.length() == 0 ? IMAGE_LOCATION.concat("no_image.png") : imageFileName; // this.link = link; // } // // public final String getId() { // return id; // } // // public final void setId(final String id) { // this.id = id; // } // // public final String getTitle() { // return title; // } // // public final void setTitle(final String title) { // this.title = title; // } // // public String getDescription() { // return description; // } // // public void setDescription(String description) { // this.description = description; // } // // public final Float getPrice() { // return price; // } // // public final void setPrice(final Float price) { // this.price = price; // } // // public final Date getPublished() { // return published; // } // // public final void setPublished(final Date published) { // this.published = published; // } // // public static long getSerialVersionUID() { // return serialVersionUID; // } // // public ArrayList<Author> getAuthors() { // return authors; // } // // public void setAuthors(ArrayList<Author> authors) { // this.authors = authors; // } // // public void addAuthor(Author author) { // this.authors.add(author); // } // // public String getImageFileName() { // return imageFileName; // } // // public void setImageFileName(String imageFileName) { // this.imageFileName = imageFileName; // } // // public String getLink() { // return link; // } // // public void setLink(String link) { // this.link = link; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Book book = (Book) o; // return Objects.equals(id, book.id) && // Objects.equals(title, book.title) && // Objects.equals(description, book.description) && // Objects.equals(authors, book.authors) && // Objects.equals(price, book.price) && // Objects.equals(imageFileName, book.imageFileName) && // Objects.equals(link, book.link) && // Objects.equals(published, book.published); // } // // @Override // public int hashCode() { // return Objects.hash(id, title, description, authors, price, imageFileName, link, published); // } // // @Override // public String toString() { // return "Book{" + // "id='" + id + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", authors=" + authors + // ", price=" + price + // ", imageFileName='" + imageFileName + '\'' + // ", link='" + link + '\'' + // ", published='" + published + '\'' + // '}'; // } // // // public void generateISBN() { // this.setId("1234567890"); // } // }
import com.readlearncode.dukesbookshop.restserver.domain.Book; import javax.ejb.EJB; import javax.ejb.Stateless; import java.util.*;
package com.readlearncode.dukesbookshop.restserver.infrastructure; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Stateless public class BookRepositoryBean implements BookRepository { @EJB private AuthorRepository authorRepository; private static final String IMAGE_LOCATION = "/images/covers/";
// Path: rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/domain/Book.java // @XmlRootElement // public class Book extends Hypermedia implements Serializable { // // private static final long serialVersionUID = 1L; // private static final String IMAGE_LOCATION = "/images/covers/"; // // @Size(min = 10, max = 10, message = "ISBN should be 10 characters") // private String id; // // @Size(min = 20) // private String title; // // @Size(min = 100) // private String description; // // @Size(min = 1) // private ArrayList<Author> authors = new ArrayList<>(); // Must use concrete List implementation as JAX-RS doesn't play nice with interfaces. // // @DecimalMin("0.00") // private Float price; // // @NotNull // private String imageFileName; // // @NotNull // @Pattern(regexp="^(https?:\\/\\/)?([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\\/\\w \\.-]*)*\\/?$") // private String link; // // @Past // Format 2018-08-25T00:00:00+01:00 // private Date published; // // public Book() { // // Required for serialisation/deserialisation // } // // public Book(String id, String title, String description, Float price, Date published, ArrayList<Author> authors, String imageFileName, String link) { // this.id = id; // this.title = title; // this.description = description; // this.price = price; // this.published = published; // this.authors = authors; // this.imageFileName = imageFileName.length() == 0 ? IMAGE_LOCATION.concat("no_image.png") : imageFileName; // this.link = link; // } // // public final String getId() { // return id; // } // // public final void setId(final String id) { // this.id = id; // } // // public final String getTitle() { // return title; // } // // public final void setTitle(final String title) { // this.title = title; // } // // public String getDescription() { // return description; // } // // public void setDescription(String description) { // this.description = description; // } // // public final Float getPrice() { // return price; // } // // public final void setPrice(final Float price) { // this.price = price; // } // // public final Date getPublished() { // return published; // } // // public final void setPublished(final Date published) { // this.published = published; // } // // public static long getSerialVersionUID() { // return serialVersionUID; // } // // public ArrayList<Author> getAuthors() { // return authors; // } // // public void setAuthors(ArrayList<Author> authors) { // this.authors = authors; // } // // public void addAuthor(Author author) { // this.authors.add(author); // } // // public String getImageFileName() { // return imageFileName; // } // // public void setImageFileName(String imageFileName) { // this.imageFileName = imageFileName; // } // // public String getLink() { // return link; // } // // public void setLink(String link) { // this.link = link; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Book book = (Book) o; // return Objects.equals(id, book.id) && // Objects.equals(title, book.title) && // Objects.equals(description, book.description) && // Objects.equals(authors, book.authors) && // Objects.equals(price, book.price) && // Objects.equals(imageFileName, book.imageFileName) && // Objects.equals(link, book.link) && // Objects.equals(published, book.published); // } // // @Override // public int hashCode() { // return Objects.hash(id, title, description, authors, price, imageFileName, link, published); // } // // @Override // public String toString() { // return "Book{" + // "id='" + id + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", authors=" + authors + // ", price=" + price + // ", imageFileName='" + imageFileName + '\'' + // ", link='" + link + '\'' + // ", published='" + published + '\'' + // '}'; // } // // // public void generateISBN() { // this.setId("1234567890"); // } // } // Path: rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/infrastructure/BookRepositoryBean.java import com.readlearncode.dukesbookshop.restserver.domain.Book; import javax.ejb.EJB; import javax.ejb.Stateless; import java.util.*; package com.readlearncode.dukesbookshop.restserver.infrastructure; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Stateless public class BookRepositoryBean implements BookRepository { @EJB private AuthorRepository authorRepository; private static final String IMAGE_LOCATION = "/images/covers/";
private final Map<String, Book> books = new HashMap<>();
readlearncode/RESTful-Service-with-JAX-RS-2.0-Course
rest-client/src/main/java/com/readlearncode/dukesbookshop/beans/AuthorList.java
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/AuthorService.java // public interface AuthorService { // // List<Author> getAuthors(); // // Author getAuthor(String id); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Author.java // public class Author implements Serializable { // // private String id; // private String firstName; // private String lastName; // private String blogURL; // // public Author(){} // // public Author(String firstName, String lastName){ // this.id = UUID.randomUUID().toString(); // this.firstName = firstName; // this.lastName = lastName; // } // // public Author(String firstName, String lastName, String blogURL){ // this(firstName, lastName); // this.blogURL = blogURL; // } // // public Author(String id, String firstName, String lastName, String blogURL){ // this(firstName, lastName, blogURL); // this.id = id; // } // // public String getId() { // return id; // } // // public void setId(String id) { // this.id = id; // } // // public String getFirstName() { // return firstName; // } // // public void setFirstName(String firstName) { // this.firstName = firstName; // } // // public String getLastName() { // return lastName; // } // // public void setLastName(String lastName) { // this.lastName = lastName; // } // // public String getBlogURL() { // return blogURL; // } // // public void setBlogURL(String blogURL) { // this.blogURL = blogURL; // } // // @Override // public String toString() { // return "Author{" + // "id='" + id + '\'' + // ", firstName='" + firstName + '\'' + // ", lastName='" + lastName + '\'' + // ", blogURL='" + blogURL + '\'' + // '}'; // } // }
import com.readlearncode.dukesbookshop.restclient.AuthorService; import com.readlearncode.dukesbookshop.domain.Author; import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.inject.Named; import java.util.List; import java.util.Map; import java.util.stream.Collectors;
package com.readlearncode.dukesbookshop.beans; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Named @RequestScoped public class AuthorList { @Inject
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/AuthorService.java // public interface AuthorService { // // List<Author> getAuthors(); // // Author getAuthor(String id); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Author.java // public class Author implements Serializable { // // private String id; // private String firstName; // private String lastName; // private String blogURL; // // public Author(){} // // public Author(String firstName, String lastName){ // this.id = UUID.randomUUID().toString(); // this.firstName = firstName; // this.lastName = lastName; // } // // public Author(String firstName, String lastName, String blogURL){ // this(firstName, lastName); // this.blogURL = blogURL; // } // // public Author(String id, String firstName, String lastName, String blogURL){ // this(firstName, lastName, blogURL); // this.id = id; // } // // public String getId() { // return id; // } // // public void setId(String id) { // this.id = id; // } // // public String getFirstName() { // return firstName; // } // // public void setFirstName(String firstName) { // this.firstName = firstName; // } // // public String getLastName() { // return lastName; // } // // public void setLastName(String lastName) { // this.lastName = lastName; // } // // public String getBlogURL() { // return blogURL; // } // // public void setBlogURL(String blogURL) { // this.blogURL = blogURL; // } // // @Override // public String toString() { // return "Author{" + // "id='" + id + '\'' + // ", firstName='" + firstName + '\'' + // ", lastName='" + lastName + '\'' + // ", blogURL='" + blogURL + '\'' + // '}'; // } // } // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/beans/AuthorList.java import com.readlearncode.dukesbookshop.restclient.AuthorService; import com.readlearncode.dukesbookshop.domain.Author; import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.inject.Named; import java.util.List; import java.util.Map; import java.util.stream.Collectors; package com.readlearncode.dukesbookshop.beans; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Named @RequestScoped public class AuthorList { @Inject
private AuthorService authorService;
readlearncode/RESTful-Service-with-JAX-RS-2.0-Course
rest-client/src/main/java/com/readlearncode/dukesbookshop/beans/AuthorList.java
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/AuthorService.java // public interface AuthorService { // // List<Author> getAuthors(); // // Author getAuthor(String id); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Author.java // public class Author implements Serializable { // // private String id; // private String firstName; // private String lastName; // private String blogURL; // // public Author(){} // // public Author(String firstName, String lastName){ // this.id = UUID.randomUUID().toString(); // this.firstName = firstName; // this.lastName = lastName; // } // // public Author(String firstName, String lastName, String blogURL){ // this(firstName, lastName); // this.blogURL = blogURL; // } // // public Author(String id, String firstName, String lastName, String blogURL){ // this(firstName, lastName, blogURL); // this.id = id; // } // // public String getId() { // return id; // } // // public void setId(String id) { // this.id = id; // } // // public String getFirstName() { // return firstName; // } // // public void setFirstName(String firstName) { // this.firstName = firstName; // } // // public String getLastName() { // return lastName; // } // // public void setLastName(String lastName) { // this.lastName = lastName; // } // // public String getBlogURL() { // return blogURL; // } // // public void setBlogURL(String blogURL) { // this.blogURL = blogURL; // } // // @Override // public String toString() { // return "Author{" + // "id='" + id + '\'' + // ", firstName='" + firstName + '\'' + // ", lastName='" + lastName + '\'' + // ", blogURL='" + blogURL + '\'' + // '}'; // } // }
import com.readlearncode.dukesbookshop.restclient.AuthorService; import com.readlearncode.dukesbookshop.domain.Author; import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.inject.Named; import java.util.List; import java.util.Map; import java.util.stream.Collectors;
package com.readlearncode.dukesbookshop.beans; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Named @RequestScoped public class AuthorList { @Inject private AuthorService authorService;
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/AuthorService.java // public interface AuthorService { // // List<Author> getAuthors(); // // Author getAuthor(String id); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Author.java // public class Author implements Serializable { // // private String id; // private String firstName; // private String lastName; // private String blogURL; // // public Author(){} // // public Author(String firstName, String lastName){ // this.id = UUID.randomUUID().toString(); // this.firstName = firstName; // this.lastName = lastName; // } // // public Author(String firstName, String lastName, String blogURL){ // this(firstName, lastName); // this.blogURL = blogURL; // } // // public Author(String id, String firstName, String lastName, String blogURL){ // this(firstName, lastName, blogURL); // this.id = id; // } // // public String getId() { // return id; // } // // public void setId(String id) { // this.id = id; // } // // public String getFirstName() { // return firstName; // } // // public void setFirstName(String firstName) { // this.firstName = firstName; // } // // public String getLastName() { // return lastName; // } // // public void setLastName(String lastName) { // this.lastName = lastName; // } // // public String getBlogURL() { // return blogURL; // } // // public void setBlogURL(String blogURL) { // this.blogURL = blogURL; // } // // @Override // public String toString() { // return "Author{" + // "id='" + id + '\'' + // ", firstName='" + firstName + '\'' + // ", lastName='" + lastName + '\'' + // ", blogURL='" + blogURL + '\'' + // '}'; // } // } // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/beans/AuthorList.java import com.readlearncode.dukesbookshop.restclient.AuthorService; import com.readlearncode.dukesbookshop.domain.Author; import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.inject.Named; import java.util.List; import java.util.Map; import java.util.stream.Collectors; package com.readlearncode.dukesbookshop.beans; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Named @RequestScoped public class AuthorList { @Inject private AuthorService authorService;
private List<Author> authors;
readlearncode/RESTful-Service-with-JAX-RS-2.0-Course
rest-client/src/main/java/com/readlearncode/dukesbookshop/beans/AuthorManager.java
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/AuthorService.java // public interface AuthorService { // // List<Author> getAuthors(); // // Author getAuthor(String id); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Author.java // public class Author implements Serializable { // // private String id; // private String firstName; // private String lastName; // private String blogURL; // // public Author(){} // // public Author(String firstName, String lastName){ // this.id = UUID.randomUUID().toString(); // this.firstName = firstName; // this.lastName = lastName; // } // // public Author(String firstName, String lastName, String blogURL){ // this(firstName, lastName); // this.blogURL = blogURL; // } // // public Author(String id, String firstName, String lastName, String blogURL){ // this(firstName, lastName, blogURL); // this.id = id; // } // // public String getId() { // return id; // } // // public void setId(String id) { // this.id = id; // } // // public String getFirstName() { // return firstName; // } // // public void setFirstName(String firstName) { // this.firstName = firstName; // } // // public String getLastName() { // return lastName; // } // // public void setLastName(String lastName) { // this.lastName = lastName; // } // // public String getBlogURL() { // return blogURL; // } // // public void setBlogURL(String blogURL) { // this.blogURL = blogURL; // } // // @Override // public String toString() { // return "Author{" + // "id='" + id + '\'' + // ", firstName='" + firstName + '\'' + // ", lastName='" + lastName + '\'' + // ", blogURL='" + blogURL + '\'' + // '}'; // } // }
import com.readlearncode.dukesbookshop.restclient.AuthorService; import com.readlearncode.dukesbookshop.domain.Author; import javax.faces.view.ViewScoped; import javax.inject.Inject; import javax.inject.Named; import java.io.Serializable;
package com.readlearncode.dukesbookshop.beans; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Named @ViewScoped public class AuthorManager implements Serializable { private static final long serialVersionUID = 1; @Inject
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/AuthorService.java // public interface AuthorService { // // List<Author> getAuthors(); // // Author getAuthor(String id); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Author.java // public class Author implements Serializable { // // private String id; // private String firstName; // private String lastName; // private String blogURL; // // public Author(){} // // public Author(String firstName, String lastName){ // this.id = UUID.randomUUID().toString(); // this.firstName = firstName; // this.lastName = lastName; // } // // public Author(String firstName, String lastName, String blogURL){ // this(firstName, lastName); // this.blogURL = blogURL; // } // // public Author(String id, String firstName, String lastName, String blogURL){ // this(firstName, lastName, blogURL); // this.id = id; // } // // public String getId() { // return id; // } // // public void setId(String id) { // this.id = id; // } // // public String getFirstName() { // return firstName; // } // // public void setFirstName(String firstName) { // this.firstName = firstName; // } // // public String getLastName() { // return lastName; // } // // public void setLastName(String lastName) { // this.lastName = lastName; // } // // public String getBlogURL() { // return blogURL; // } // // public void setBlogURL(String blogURL) { // this.blogURL = blogURL; // } // // @Override // public String toString() { // return "Author{" + // "id='" + id + '\'' + // ", firstName='" + firstName + '\'' + // ", lastName='" + lastName + '\'' + // ", blogURL='" + blogURL + '\'' + // '}'; // } // } // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/beans/AuthorManager.java import com.readlearncode.dukesbookshop.restclient.AuthorService; import com.readlearncode.dukesbookshop.domain.Author; import javax.faces.view.ViewScoped; import javax.inject.Inject; import javax.inject.Named; import java.io.Serializable; package com.readlearncode.dukesbookshop.beans; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Named @ViewScoped public class AuthorManager implements Serializable { private static final long serialVersionUID = 1; @Inject
private AuthorService authorService;
readlearncode/RESTful-Service-with-JAX-RS-2.0-Course
rest-client/src/main/java/com/readlearncode/dukesbookshop/beans/AuthorManager.java
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/AuthorService.java // public interface AuthorService { // // List<Author> getAuthors(); // // Author getAuthor(String id); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Author.java // public class Author implements Serializable { // // private String id; // private String firstName; // private String lastName; // private String blogURL; // // public Author(){} // // public Author(String firstName, String lastName){ // this.id = UUID.randomUUID().toString(); // this.firstName = firstName; // this.lastName = lastName; // } // // public Author(String firstName, String lastName, String blogURL){ // this(firstName, lastName); // this.blogURL = blogURL; // } // // public Author(String id, String firstName, String lastName, String blogURL){ // this(firstName, lastName, blogURL); // this.id = id; // } // // public String getId() { // return id; // } // // public void setId(String id) { // this.id = id; // } // // public String getFirstName() { // return firstName; // } // // public void setFirstName(String firstName) { // this.firstName = firstName; // } // // public String getLastName() { // return lastName; // } // // public void setLastName(String lastName) { // this.lastName = lastName; // } // // public String getBlogURL() { // return blogURL; // } // // public void setBlogURL(String blogURL) { // this.blogURL = blogURL; // } // // @Override // public String toString() { // return "Author{" + // "id='" + id + '\'' + // ", firstName='" + firstName + '\'' + // ", lastName='" + lastName + '\'' + // ", blogURL='" + blogURL + '\'' + // '}'; // } // }
import com.readlearncode.dukesbookshop.restclient.AuthorService; import com.readlearncode.dukesbookshop.domain.Author; import javax.faces.view.ViewScoped; import javax.inject.Inject; import javax.inject.Named; import java.io.Serializable;
package com.readlearncode.dukesbookshop.beans; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Named @ViewScoped public class AuthorManager implements Serializable { private static final long serialVersionUID = 1; @Inject private AuthorService authorService; private String id;
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/AuthorService.java // public interface AuthorService { // // List<Author> getAuthors(); // // Author getAuthor(String id); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Author.java // public class Author implements Serializable { // // private String id; // private String firstName; // private String lastName; // private String blogURL; // // public Author(){} // // public Author(String firstName, String lastName){ // this.id = UUID.randomUUID().toString(); // this.firstName = firstName; // this.lastName = lastName; // } // // public Author(String firstName, String lastName, String blogURL){ // this(firstName, lastName); // this.blogURL = blogURL; // } // // public Author(String id, String firstName, String lastName, String blogURL){ // this(firstName, lastName, blogURL); // this.id = id; // } // // public String getId() { // return id; // } // // public void setId(String id) { // this.id = id; // } // // public String getFirstName() { // return firstName; // } // // public void setFirstName(String firstName) { // this.firstName = firstName; // } // // public String getLastName() { // return lastName; // } // // public void setLastName(String lastName) { // this.lastName = lastName; // } // // public String getBlogURL() { // return blogURL; // } // // public void setBlogURL(String blogURL) { // this.blogURL = blogURL; // } // // @Override // public String toString() { // return "Author{" + // "id='" + id + '\'' + // ", firstName='" + firstName + '\'' + // ", lastName='" + lastName + '\'' + // ", blogURL='" + blogURL + '\'' + // '}'; // } // } // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/beans/AuthorManager.java import com.readlearncode.dukesbookshop.restclient.AuthorService; import com.readlearncode.dukesbookshop.domain.Author; import javax.faces.view.ViewScoped; import javax.inject.Inject; import javax.inject.Named; import java.io.Serializable; package com.readlearncode.dukesbookshop.beans; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Named @ViewScoped public class AuthorManager implements Serializable { private static final long serialVersionUID = 1; @Inject private AuthorService authorService; private String id;
private Author author;
readlearncode/RESTful-Service-with-JAX-RS-2.0-Course
rest-client/src/main/java/com/readlearncode/dukesbookshop/beans/BookCatalogue.java
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/BookService.java // public interface BookService { // // List<Book> getBooks(); // // Book getBook(String id); // // void deleteBook(String isbn); // // Book saveBook(Book book); // // List<Author> extractAuthors(JsonArray authorArray); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Book.java // public class Book extends Hypermedia implements Serializable { // private static final long serialVersionUID = 1L; // // private String id; // // private String title; // // private String description; // // private List<Author> authors = Collections.emptyList(); // // private Float price; // // private String imageFileName; // // private String link; // // private String published; // // public Book(){} // // public Book(String id, String title, String description, Float price, String published, List<Author> authors, String imageFileName, String link, List<LinkResource> links) { // this.id = id; // this.title = title; // this.description = description; // this.price = price; // this.published = published; // this.authors = authors; // this.imageFileName = imageFileName; // this.link = link; // this.setLinks(links); // } // // public final String getId() { // return id; // } // // public final void setId(final String id) { // this.id = id; // } // // public final String getTitle() { // return title; // } // // public final void setTitle(final String title) { // this.title = title; // } // // public String getDescription() { // return description; // } // // public void setDescription(String description) { // this.description = description; // } // // public final Float getPrice() { // return price; // } // // public final void setPrice(final Float price) { // this.price = price; // } // // public final String getPublished() { // return published; // } // // public final void setPublished(final String published) { // this.published = published; // } // // public static long getSerialVersionUID() { // return serialVersionUID; // } // // public List<Author> getAuthors() { // return authors; // } // // public void setAuthors(List<Author> authors) { // this.authors = authors; // } // // public void addAuthor(Author author){ // this.authors.add(author); // } // // public String getImageFileName() { // return imageFileName; // } // // public void setImageFileName(String imageFileName) { // this.imageFileName = imageFileName; // } // // public String getLink() { // return link; // } // // public void setLink(String link) { // this.link = link; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Book book = (Book) o; // return Objects.equals(id, book.id) && // Objects.equals(title, book.title) && // Objects.equals(description, book.description) && // Objects.equals(authors, book.authors) && // Objects.equals(price, book.price) && // Objects.equals(imageFileName, book.imageFileName) && // Objects.equals(link, book.link) && // Objects.equals(published, book.published); // } // // @Override // public int hashCode() { // return Objects.hash(id, title, description, authors, price, imageFileName, link, published); // } // // @Override // public String toString() { // return "Book{" + // "id='" + id + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", authors=" + authors + // ", price=" + price + // ", imageFileName='" + imageFileName + '\'' + // ", link='" + link + '\'' + // ", published='" + published + '\'' + // '}'; // } // }
import com.readlearncode.dukesbookshop.restclient.BookService; import com.readlearncode.dukesbookshop.domain.Book; import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.inject.Named; import java.util.List;
package com.readlearncode.dukesbookshop.beans; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Named @RequestScoped public class BookCatalogue { @Inject
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/BookService.java // public interface BookService { // // List<Book> getBooks(); // // Book getBook(String id); // // void deleteBook(String isbn); // // Book saveBook(Book book); // // List<Author> extractAuthors(JsonArray authorArray); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Book.java // public class Book extends Hypermedia implements Serializable { // private static final long serialVersionUID = 1L; // // private String id; // // private String title; // // private String description; // // private List<Author> authors = Collections.emptyList(); // // private Float price; // // private String imageFileName; // // private String link; // // private String published; // // public Book(){} // // public Book(String id, String title, String description, Float price, String published, List<Author> authors, String imageFileName, String link, List<LinkResource> links) { // this.id = id; // this.title = title; // this.description = description; // this.price = price; // this.published = published; // this.authors = authors; // this.imageFileName = imageFileName; // this.link = link; // this.setLinks(links); // } // // public final String getId() { // return id; // } // // public final void setId(final String id) { // this.id = id; // } // // public final String getTitle() { // return title; // } // // public final void setTitle(final String title) { // this.title = title; // } // // public String getDescription() { // return description; // } // // public void setDescription(String description) { // this.description = description; // } // // public final Float getPrice() { // return price; // } // // public final void setPrice(final Float price) { // this.price = price; // } // // public final String getPublished() { // return published; // } // // public final void setPublished(final String published) { // this.published = published; // } // // public static long getSerialVersionUID() { // return serialVersionUID; // } // // public List<Author> getAuthors() { // return authors; // } // // public void setAuthors(List<Author> authors) { // this.authors = authors; // } // // public void addAuthor(Author author){ // this.authors.add(author); // } // // public String getImageFileName() { // return imageFileName; // } // // public void setImageFileName(String imageFileName) { // this.imageFileName = imageFileName; // } // // public String getLink() { // return link; // } // // public void setLink(String link) { // this.link = link; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Book book = (Book) o; // return Objects.equals(id, book.id) && // Objects.equals(title, book.title) && // Objects.equals(description, book.description) && // Objects.equals(authors, book.authors) && // Objects.equals(price, book.price) && // Objects.equals(imageFileName, book.imageFileName) && // Objects.equals(link, book.link) && // Objects.equals(published, book.published); // } // // @Override // public int hashCode() { // return Objects.hash(id, title, description, authors, price, imageFileName, link, published); // } // // @Override // public String toString() { // return "Book{" + // "id='" + id + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", authors=" + authors + // ", price=" + price + // ", imageFileName='" + imageFileName + '\'' + // ", link='" + link + '\'' + // ", published='" + published + '\'' + // '}'; // } // } // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/beans/BookCatalogue.java import com.readlearncode.dukesbookshop.restclient.BookService; import com.readlearncode.dukesbookshop.domain.Book; import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.inject.Named; import java.util.List; package com.readlearncode.dukesbookshop.beans; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Named @RequestScoped public class BookCatalogue { @Inject
private BookService bookService;
readlearncode/RESTful-Service-with-JAX-RS-2.0-Course
rest-client/src/main/java/com/readlearncode/dukesbookshop/beans/BookCatalogue.java
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/BookService.java // public interface BookService { // // List<Book> getBooks(); // // Book getBook(String id); // // void deleteBook(String isbn); // // Book saveBook(Book book); // // List<Author> extractAuthors(JsonArray authorArray); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Book.java // public class Book extends Hypermedia implements Serializable { // private static final long serialVersionUID = 1L; // // private String id; // // private String title; // // private String description; // // private List<Author> authors = Collections.emptyList(); // // private Float price; // // private String imageFileName; // // private String link; // // private String published; // // public Book(){} // // public Book(String id, String title, String description, Float price, String published, List<Author> authors, String imageFileName, String link, List<LinkResource> links) { // this.id = id; // this.title = title; // this.description = description; // this.price = price; // this.published = published; // this.authors = authors; // this.imageFileName = imageFileName; // this.link = link; // this.setLinks(links); // } // // public final String getId() { // return id; // } // // public final void setId(final String id) { // this.id = id; // } // // public final String getTitle() { // return title; // } // // public final void setTitle(final String title) { // this.title = title; // } // // public String getDescription() { // return description; // } // // public void setDescription(String description) { // this.description = description; // } // // public final Float getPrice() { // return price; // } // // public final void setPrice(final Float price) { // this.price = price; // } // // public final String getPublished() { // return published; // } // // public final void setPublished(final String published) { // this.published = published; // } // // public static long getSerialVersionUID() { // return serialVersionUID; // } // // public List<Author> getAuthors() { // return authors; // } // // public void setAuthors(List<Author> authors) { // this.authors = authors; // } // // public void addAuthor(Author author){ // this.authors.add(author); // } // // public String getImageFileName() { // return imageFileName; // } // // public void setImageFileName(String imageFileName) { // this.imageFileName = imageFileName; // } // // public String getLink() { // return link; // } // // public void setLink(String link) { // this.link = link; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Book book = (Book) o; // return Objects.equals(id, book.id) && // Objects.equals(title, book.title) && // Objects.equals(description, book.description) && // Objects.equals(authors, book.authors) && // Objects.equals(price, book.price) && // Objects.equals(imageFileName, book.imageFileName) && // Objects.equals(link, book.link) && // Objects.equals(published, book.published); // } // // @Override // public int hashCode() { // return Objects.hash(id, title, description, authors, price, imageFileName, link, published); // } // // @Override // public String toString() { // return "Book{" + // "id='" + id + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", authors=" + authors + // ", price=" + price + // ", imageFileName='" + imageFileName + '\'' + // ", link='" + link + '\'' + // ", published='" + published + '\'' + // '}'; // } // }
import com.readlearncode.dukesbookshop.restclient.BookService; import com.readlearncode.dukesbookshop.domain.Book; import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.inject.Named; import java.util.List;
package com.readlearncode.dukesbookshop.beans; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Named @RequestScoped public class BookCatalogue { @Inject private BookService bookService;
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/BookService.java // public interface BookService { // // List<Book> getBooks(); // // Book getBook(String id); // // void deleteBook(String isbn); // // Book saveBook(Book book); // // List<Author> extractAuthors(JsonArray authorArray); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Book.java // public class Book extends Hypermedia implements Serializable { // private static final long serialVersionUID = 1L; // // private String id; // // private String title; // // private String description; // // private List<Author> authors = Collections.emptyList(); // // private Float price; // // private String imageFileName; // // private String link; // // private String published; // // public Book(){} // // public Book(String id, String title, String description, Float price, String published, List<Author> authors, String imageFileName, String link, List<LinkResource> links) { // this.id = id; // this.title = title; // this.description = description; // this.price = price; // this.published = published; // this.authors = authors; // this.imageFileName = imageFileName; // this.link = link; // this.setLinks(links); // } // // public final String getId() { // return id; // } // // public final void setId(final String id) { // this.id = id; // } // // public final String getTitle() { // return title; // } // // public final void setTitle(final String title) { // this.title = title; // } // // public String getDescription() { // return description; // } // // public void setDescription(String description) { // this.description = description; // } // // public final Float getPrice() { // return price; // } // // public final void setPrice(final Float price) { // this.price = price; // } // // public final String getPublished() { // return published; // } // // public final void setPublished(final String published) { // this.published = published; // } // // public static long getSerialVersionUID() { // return serialVersionUID; // } // // public List<Author> getAuthors() { // return authors; // } // // public void setAuthors(List<Author> authors) { // this.authors = authors; // } // // public void addAuthor(Author author){ // this.authors.add(author); // } // // public String getImageFileName() { // return imageFileName; // } // // public void setImageFileName(String imageFileName) { // this.imageFileName = imageFileName; // } // // public String getLink() { // return link; // } // // public void setLink(String link) { // this.link = link; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Book book = (Book) o; // return Objects.equals(id, book.id) && // Objects.equals(title, book.title) && // Objects.equals(description, book.description) && // Objects.equals(authors, book.authors) && // Objects.equals(price, book.price) && // Objects.equals(imageFileName, book.imageFileName) && // Objects.equals(link, book.link) && // Objects.equals(published, book.published); // } // // @Override // public int hashCode() { // return Objects.hash(id, title, description, authors, price, imageFileName, link, published); // } // // @Override // public String toString() { // return "Book{" + // "id='" + id + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", authors=" + authors + // ", price=" + price + // ", imageFileName='" + imageFileName + '\'' + // ", link='" + link + '\'' + // ", published='" + published + '\'' + // '}'; // } // } // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/beans/BookCatalogue.java import com.readlearncode.dukesbookshop.restclient.BookService; import com.readlearncode.dukesbookshop.domain.Book; import javax.annotation.PostConstruct; import javax.enterprise.context.RequestScoped; import javax.inject.Inject; import javax.inject.Named; import java.util.List; package com.readlearncode.dukesbookshop.beans; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Named @RequestScoped public class BookCatalogue { @Inject private BookService bookService;
private List<Book> books;
readlearncode/RESTful-Service-with-JAX-RS-2.0-Course
rest-client/src/main/java/com/readlearncode/dukesbookshop/beans/BookManager.java
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/AuthorService.java // public interface AuthorService { // // List<Author> getAuthors(); // // Author getAuthor(String id); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/BookService.java // public interface BookService { // // List<Book> getBooks(); // // Book getBook(String id); // // void deleteBook(String isbn); // // Book saveBook(Book book); // // List<Author> extractAuthors(JsonArray authorArray); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Book.java // public class Book extends Hypermedia implements Serializable { // private static final long serialVersionUID = 1L; // // private String id; // // private String title; // // private String description; // // private List<Author> authors = Collections.emptyList(); // // private Float price; // // private String imageFileName; // // private String link; // // private String published; // // public Book(){} // // public Book(String id, String title, String description, Float price, String published, List<Author> authors, String imageFileName, String link, List<LinkResource> links) { // this.id = id; // this.title = title; // this.description = description; // this.price = price; // this.published = published; // this.authors = authors; // this.imageFileName = imageFileName; // this.link = link; // this.setLinks(links); // } // // public final String getId() { // return id; // } // // public final void setId(final String id) { // this.id = id; // } // // public final String getTitle() { // return title; // } // // public final void setTitle(final String title) { // this.title = title; // } // // public String getDescription() { // return description; // } // // public void setDescription(String description) { // this.description = description; // } // // public final Float getPrice() { // return price; // } // // public final void setPrice(final Float price) { // this.price = price; // } // // public final String getPublished() { // return published; // } // // public final void setPublished(final String published) { // this.published = published; // } // // public static long getSerialVersionUID() { // return serialVersionUID; // } // // public List<Author> getAuthors() { // return authors; // } // // public void setAuthors(List<Author> authors) { // this.authors = authors; // } // // public void addAuthor(Author author){ // this.authors.add(author); // } // // public String getImageFileName() { // return imageFileName; // } // // public void setImageFileName(String imageFileName) { // this.imageFileName = imageFileName; // } // // public String getLink() { // return link; // } // // public void setLink(String link) { // this.link = link; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Book book = (Book) o; // return Objects.equals(id, book.id) && // Objects.equals(title, book.title) && // Objects.equals(description, book.description) && // Objects.equals(authors, book.authors) && // Objects.equals(price, book.price) && // Objects.equals(imageFileName, book.imageFileName) && // Objects.equals(link, book.link) && // Objects.equals(published, book.published); // } // // @Override // public int hashCode() { // return Objects.hash(id, title, description, authors, price, imageFileName, link, published); // } // // @Override // public String toString() { // return "Book{" + // "id='" + id + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", authors=" + authors + // ", price=" + price + // ", imageFileName='" + imageFileName + '\'' + // ", link='" + link + '\'' + // ", published='" + published + '\'' + // '}'; // } // }
import com.readlearncode.dukesbookshop.restclient.AuthorService; import com.readlearncode.dukesbookshop.restclient.BookService; import com.readlearncode.dukesbookshop.domain.Book; import javax.faces.view.ViewScoped; import javax.inject.Inject; import javax.inject.Named; import java.io.Serializable;
package com.readlearncode.dukesbookshop.beans; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Named @ViewScoped public class BookManager implements Serializable { private static final long serialVersionUID = 1; @Inject
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/AuthorService.java // public interface AuthorService { // // List<Author> getAuthors(); // // Author getAuthor(String id); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/BookService.java // public interface BookService { // // List<Book> getBooks(); // // Book getBook(String id); // // void deleteBook(String isbn); // // Book saveBook(Book book); // // List<Author> extractAuthors(JsonArray authorArray); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Book.java // public class Book extends Hypermedia implements Serializable { // private static final long serialVersionUID = 1L; // // private String id; // // private String title; // // private String description; // // private List<Author> authors = Collections.emptyList(); // // private Float price; // // private String imageFileName; // // private String link; // // private String published; // // public Book(){} // // public Book(String id, String title, String description, Float price, String published, List<Author> authors, String imageFileName, String link, List<LinkResource> links) { // this.id = id; // this.title = title; // this.description = description; // this.price = price; // this.published = published; // this.authors = authors; // this.imageFileName = imageFileName; // this.link = link; // this.setLinks(links); // } // // public final String getId() { // return id; // } // // public final void setId(final String id) { // this.id = id; // } // // public final String getTitle() { // return title; // } // // public final void setTitle(final String title) { // this.title = title; // } // // public String getDescription() { // return description; // } // // public void setDescription(String description) { // this.description = description; // } // // public final Float getPrice() { // return price; // } // // public final void setPrice(final Float price) { // this.price = price; // } // // public final String getPublished() { // return published; // } // // public final void setPublished(final String published) { // this.published = published; // } // // public static long getSerialVersionUID() { // return serialVersionUID; // } // // public List<Author> getAuthors() { // return authors; // } // // public void setAuthors(List<Author> authors) { // this.authors = authors; // } // // public void addAuthor(Author author){ // this.authors.add(author); // } // // public String getImageFileName() { // return imageFileName; // } // // public void setImageFileName(String imageFileName) { // this.imageFileName = imageFileName; // } // // public String getLink() { // return link; // } // // public void setLink(String link) { // this.link = link; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Book book = (Book) o; // return Objects.equals(id, book.id) && // Objects.equals(title, book.title) && // Objects.equals(description, book.description) && // Objects.equals(authors, book.authors) && // Objects.equals(price, book.price) && // Objects.equals(imageFileName, book.imageFileName) && // Objects.equals(link, book.link) && // Objects.equals(published, book.published); // } // // @Override // public int hashCode() { // return Objects.hash(id, title, description, authors, price, imageFileName, link, published); // } // // @Override // public String toString() { // return "Book{" + // "id='" + id + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", authors=" + authors + // ", price=" + price + // ", imageFileName='" + imageFileName + '\'' + // ", link='" + link + '\'' + // ", published='" + published + '\'' + // '}'; // } // } // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/beans/BookManager.java import com.readlearncode.dukesbookshop.restclient.AuthorService; import com.readlearncode.dukesbookshop.restclient.BookService; import com.readlearncode.dukesbookshop.domain.Book; import javax.faces.view.ViewScoped; import javax.inject.Inject; import javax.inject.Named; import java.io.Serializable; package com.readlearncode.dukesbookshop.beans; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Named @ViewScoped public class BookManager implements Serializable { private static final long serialVersionUID = 1; @Inject
private BookService bookService;
readlearncode/RESTful-Service-with-JAX-RS-2.0-Course
rest-client/src/main/java/com/readlearncode/dukesbookshop/beans/BookManager.java
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/AuthorService.java // public interface AuthorService { // // List<Author> getAuthors(); // // Author getAuthor(String id); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/BookService.java // public interface BookService { // // List<Book> getBooks(); // // Book getBook(String id); // // void deleteBook(String isbn); // // Book saveBook(Book book); // // List<Author> extractAuthors(JsonArray authorArray); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Book.java // public class Book extends Hypermedia implements Serializable { // private static final long serialVersionUID = 1L; // // private String id; // // private String title; // // private String description; // // private List<Author> authors = Collections.emptyList(); // // private Float price; // // private String imageFileName; // // private String link; // // private String published; // // public Book(){} // // public Book(String id, String title, String description, Float price, String published, List<Author> authors, String imageFileName, String link, List<LinkResource> links) { // this.id = id; // this.title = title; // this.description = description; // this.price = price; // this.published = published; // this.authors = authors; // this.imageFileName = imageFileName; // this.link = link; // this.setLinks(links); // } // // public final String getId() { // return id; // } // // public final void setId(final String id) { // this.id = id; // } // // public final String getTitle() { // return title; // } // // public final void setTitle(final String title) { // this.title = title; // } // // public String getDescription() { // return description; // } // // public void setDescription(String description) { // this.description = description; // } // // public final Float getPrice() { // return price; // } // // public final void setPrice(final Float price) { // this.price = price; // } // // public final String getPublished() { // return published; // } // // public final void setPublished(final String published) { // this.published = published; // } // // public static long getSerialVersionUID() { // return serialVersionUID; // } // // public List<Author> getAuthors() { // return authors; // } // // public void setAuthors(List<Author> authors) { // this.authors = authors; // } // // public void addAuthor(Author author){ // this.authors.add(author); // } // // public String getImageFileName() { // return imageFileName; // } // // public void setImageFileName(String imageFileName) { // this.imageFileName = imageFileName; // } // // public String getLink() { // return link; // } // // public void setLink(String link) { // this.link = link; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Book book = (Book) o; // return Objects.equals(id, book.id) && // Objects.equals(title, book.title) && // Objects.equals(description, book.description) && // Objects.equals(authors, book.authors) && // Objects.equals(price, book.price) && // Objects.equals(imageFileName, book.imageFileName) && // Objects.equals(link, book.link) && // Objects.equals(published, book.published); // } // // @Override // public int hashCode() { // return Objects.hash(id, title, description, authors, price, imageFileName, link, published); // } // // @Override // public String toString() { // return "Book{" + // "id='" + id + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", authors=" + authors + // ", price=" + price + // ", imageFileName='" + imageFileName + '\'' + // ", link='" + link + '\'' + // ", published='" + published + '\'' + // '}'; // } // }
import com.readlearncode.dukesbookshop.restclient.AuthorService; import com.readlearncode.dukesbookshop.restclient.BookService; import com.readlearncode.dukesbookshop.domain.Book; import javax.faces.view.ViewScoped; import javax.inject.Inject; import javax.inject.Named; import java.io.Serializable;
package com.readlearncode.dukesbookshop.beans; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Named @ViewScoped public class BookManager implements Serializable { private static final long serialVersionUID = 1; @Inject private BookService bookService; @Inject
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/AuthorService.java // public interface AuthorService { // // List<Author> getAuthors(); // // Author getAuthor(String id); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/BookService.java // public interface BookService { // // List<Book> getBooks(); // // Book getBook(String id); // // void deleteBook(String isbn); // // Book saveBook(Book book); // // List<Author> extractAuthors(JsonArray authorArray); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Book.java // public class Book extends Hypermedia implements Serializable { // private static final long serialVersionUID = 1L; // // private String id; // // private String title; // // private String description; // // private List<Author> authors = Collections.emptyList(); // // private Float price; // // private String imageFileName; // // private String link; // // private String published; // // public Book(){} // // public Book(String id, String title, String description, Float price, String published, List<Author> authors, String imageFileName, String link, List<LinkResource> links) { // this.id = id; // this.title = title; // this.description = description; // this.price = price; // this.published = published; // this.authors = authors; // this.imageFileName = imageFileName; // this.link = link; // this.setLinks(links); // } // // public final String getId() { // return id; // } // // public final void setId(final String id) { // this.id = id; // } // // public final String getTitle() { // return title; // } // // public final void setTitle(final String title) { // this.title = title; // } // // public String getDescription() { // return description; // } // // public void setDescription(String description) { // this.description = description; // } // // public final Float getPrice() { // return price; // } // // public final void setPrice(final Float price) { // this.price = price; // } // // public final String getPublished() { // return published; // } // // public final void setPublished(final String published) { // this.published = published; // } // // public static long getSerialVersionUID() { // return serialVersionUID; // } // // public List<Author> getAuthors() { // return authors; // } // // public void setAuthors(List<Author> authors) { // this.authors = authors; // } // // public void addAuthor(Author author){ // this.authors.add(author); // } // // public String getImageFileName() { // return imageFileName; // } // // public void setImageFileName(String imageFileName) { // this.imageFileName = imageFileName; // } // // public String getLink() { // return link; // } // // public void setLink(String link) { // this.link = link; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Book book = (Book) o; // return Objects.equals(id, book.id) && // Objects.equals(title, book.title) && // Objects.equals(description, book.description) && // Objects.equals(authors, book.authors) && // Objects.equals(price, book.price) && // Objects.equals(imageFileName, book.imageFileName) && // Objects.equals(link, book.link) && // Objects.equals(published, book.published); // } // // @Override // public int hashCode() { // return Objects.hash(id, title, description, authors, price, imageFileName, link, published); // } // // @Override // public String toString() { // return "Book{" + // "id='" + id + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", authors=" + authors + // ", price=" + price + // ", imageFileName='" + imageFileName + '\'' + // ", link='" + link + '\'' + // ", published='" + published + '\'' + // '}'; // } // } // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/beans/BookManager.java import com.readlearncode.dukesbookshop.restclient.AuthorService; import com.readlearncode.dukesbookshop.restclient.BookService; import com.readlearncode.dukesbookshop.domain.Book; import javax.faces.view.ViewScoped; import javax.inject.Inject; import javax.inject.Named; import java.io.Serializable; package com.readlearncode.dukesbookshop.beans; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Named @ViewScoped public class BookManager implements Serializable { private static final long serialVersionUID = 1; @Inject private BookService bookService; @Inject
private AuthorService authorService;
readlearncode/RESTful-Service-with-JAX-RS-2.0-Course
rest-client/src/main/java/com/readlearncode/dukesbookshop/beans/BookManager.java
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/AuthorService.java // public interface AuthorService { // // List<Author> getAuthors(); // // Author getAuthor(String id); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/BookService.java // public interface BookService { // // List<Book> getBooks(); // // Book getBook(String id); // // void deleteBook(String isbn); // // Book saveBook(Book book); // // List<Author> extractAuthors(JsonArray authorArray); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Book.java // public class Book extends Hypermedia implements Serializable { // private static final long serialVersionUID = 1L; // // private String id; // // private String title; // // private String description; // // private List<Author> authors = Collections.emptyList(); // // private Float price; // // private String imageFileName; // // private String link; // // private String published; // // public Book(){} // // public Book(String id, String title, String description, Float price, String published, List<Author> authors, String imageFileName, String link, List<LinkResource> links) { // this.id = id; // this.title = title; // this.description = description; // this.price = price; // this.published = published; // this.authors = authors; // this.imageFileName = imageFileName; // this.link = link; // this.setLinks(links); // } // // public final String getId() { // return id; // } // // public final void setId(final String id) { // this.id = id; // } // // public final String getTitle() { // return title; // } // // public final void setTitle(final String title) { // this.title = title; // } // // public String getDescription() { // return description; // } // // public void setDescription(String description) { // this.description = description; // } // // public final Float getPrice() { // return price; // } // // public final void setPrice(final Float price) { // this.price = price; // } // // public final String getPublished() { // return published; // } // // public final void setPublished(final String published) { // this.published = published; // } // // public static long getSerialVersionUID() { // return serialVersionUID; // } // // public List<Author> getAuthors() { // return authors; // } // // public void setAuthors(List<Author> authors) { // this.authors = authors; // } // // public void addAuthor(Author author){ // this.authors.add(author); // } // // public String getImageFileName() { // return imageFileName; // } // // public void setImageFileName(String imageFileName) { // this.imageFileName = imageFileName; // } // // public String getLink() { // return link; // } // // public void setLink(String link) { // this.link = link; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Book book = (Book) o; // return Objects.equals(id, book.id) && // Objects.equals(title, book.title) && // Objects.equals(description, book.description) && // Objects.equals(authors, book.authors) && // Objects.equals(price, book.price) && // Objects.equals(imageFileName, book.imageFileName) && // Objects.equals(link, book.link) && // Objects.equals(published, book.published); // } // // @Override // public int hashCode() { // return Objects.hash(id, title, description, authors, price, imageFileName, link, published); // } // // @Override // public String toString() { // return "Book{" + // "id='" + id + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", authors=" + authors + // ", price=" + price + // ", imageFileName='" + imageFileName + '\'' + // ", link='" + link + '\'' + // ", published='" + published + '\'' + // '}'; // } // }
import com.readlearncode.dukesbookshop.restclient.AuthorService; import com.readlearncode.dukesbookshop.restclient.BookService; import com.readlearncode.dukesbookshop.domain.Book; import javax.faces.view.ViewScoped; import javax.inject.Inject; import javax.inject.Named; import java.io.Serializable;
package com.readlearncode.dukesbookshop.beans; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Named @ViewScoped public class BookManager implements Serializable { private static final long serialVersionUID = 1; @Inject private BookService bookService; @Inject private AuthorService authorService; private String id;
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/AuthorService.java // public interface AuthorService { // // List<Author> getAuthors(); // // Author getAuthor(String id); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/BookService.java // public interface BookService { // // List<Book> getBooks(); // // Book getBook(String id); // // void deleteBook(String isbn); // // Book saveBook(Book book); // // List<Author> extractAuthors(JsonArray authorArray); // // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Book.java // public class Book extends Hypermedia implements Serializable { // private static final long serialVersionUID = 1L; // // private String id; // // private String title; // // private String description; // // private List<Author> authors = Collections.emptyList(); // // private Float price; // // private String imageFileName; // // private String link; // // private String published; // // public Book(){} // // public Book(String id, String title, String description, Float price, String published, List<Author> authors, String imageFileName, String link, List<LinkResource> links) { // this.id = id; // this.title = title; // this.description = description; // this.price = price; // this.published = published; // this.authors = authors; // this.imageFileName = imageFileName; // this.link = link; // this.setLinks(links); // } // // public final String getId() { // return id; // } // // public final void setId(final String id) { // this.id = id; // } // // public final String getTitle() { // return title; // } // // public final void setTitle(final String title) { // this.title = title; // } // // public String getDescription() { // return description; // } // // public void setDescription(String description) { // this.description = description; // } // // public final Float getPrice() { // return price; // } // // public final void setPrice(final Float price) { // this.price = price; // } // // public final String getPublished() { // return published; // } // // public final void setPublished(final String published) { // this.published = published; // } // // public static long getSerialVersionUID() { // return serialVersionUID; // } // // public List<Author> getAuthors() { // return authors; // } // // public void setAuthors(List<Author> authors) { // this.authors = authors; // } // // public void addAuthor(Author author){ // this.authors.add(author); // } // // public String getImageFileName() { // return imageFileName; // } // // public void setImageFileName(String imageFileName) { // this.imageFileName = imageFileName; // } // // public String getLink() { // return link; // } // // public void setLink(String link) { // this.link = link; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Book book = (Book) o; // return Objects.equals(id, book.id) && // Objects.equals(title, book.title) && // Objects.equals(description, book.description) && // Objects.equals(authors, book.authors) && // Objects.equals(price, book.price) && // Objects.equals(imageFileName, book.imageFileName) && // Objects.equals(link, book.link) && // Objects.equals(published, book.published); // } // // @Override // public int hashCode() { // return Objects.hash(id, title, description, authors, price, imageFileName, link, published); // } // // @Override // public String toString() { // return "Book{" + // "id='" + id + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", authors=" + authors + // ", price=" + price + // ", imageFileName='" + imageFileName + '\'' + // ", link='" + link + '\'' + // ", published='" + published + '\'' + // '}'; // } // } // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/beans/BookManager.java import com.readlearncode.dukesbookshop.restclient.AuthorService; import com.readlearncode.dukesbookshop.restclient.BookService; import com.readlearncode.dukesbookshop.domain.Book; import javax.faces.view.ViewScoped; import javax.inject.Inject; import javax.inject.Named; import java.io.Serializable; package com.readlearncode.dukesbookshop.beans; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Named @ViewScoped public class BookManager implements Serializable { private static final long serialVersionUID = 1; @Inject private BookService bookService; @Inject private AuthorService authorService; private String id;
private Book book;
readlearncode/RESTful-Service-with-JAX-RS-2.0-Course
rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/infrastructure/AuthorRepositoryBean.java
// Path: rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/domain/Author.java // @XmlRootElement // public class Author implements Serializable { // // private String id; // private String firstName; // private String lastName; // private String blogURL; // // public Author() { // } // // public Author(String id, String firstName, String lastName) { // this.id = id; // this.firstName = firstName; // this.lastName = lastName; // } // // public Author(String id, String firstName, String lastName, String blogURL) { // this(id, firstName, lastName); // this.blogURL = blogURL; // } // // // @Produces(MediaType.APPLICATION_JSON) // public String getId() { // return id; // } // // @GET // @Path("/firstName") // @Produces(MediaType.APPLICATION_JSON) // public String getFirstName() { // return firstName; // } // // @GET // @Path("/lastName") // @Produces(MediaType.APPLICATION_JSON) // public String getLastName() { // return lastName; // } // // @GET // @Path("/blog") // @Produces(MediaType.APPLICATION_JSON) // public String getBlogURL() { // return blogURL; // } // // public void setId(String id) { // this.id = id; // } // // public void setFirstName(String firstName) { // this.firstName = firstName; // } // // public void setLastName(String lastName) { // this.lastName = lastName; // } // // public void setBlogURL(String blogURL) { // this.blogURL = blogURL; // } // // // }
import com.readlearncode.dukesbookshop.restserver.domain.Author; import javax.ejb.Stateless; import java.util.*; import java.util.stream.Collectors;
package com.readlearncode.dukesbookshop.restserver.infrastructure; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Stateless public class AuthorRepositoryBean implements AuthorRepository {
// Path: rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/domain/Author.java // @XmlRootElement // public class Author implements Serializable { // // private String id; // private String firstName; // private String lastName; // private String blogURL; // // public Author() { // } // // public Author(String id, String firstName, String lastName) { // this.id = id; // this.firstName = firstName; // this.lastName = lastName; // } // // public Author(String id, String firstName, String lastName, String blogURL) { // this(id, firstName, lastName); // this.blogURL = blogURL; // } // // // @Produces(MediaType.APPLICATION_JSON) // public String getId() { // return id; // } // // @GET // @Path("/firstName") // @Produces(MediaType.APPLICATION_JSON) // public String getFirstName() { // return firstName; // } // // @GET // @Path("/lastName") // @Produces(MediaType.APPLICATION_JSON) // public String getLastName() { // return lastName; // } // // @GET // @Path("/blog") // @Produces(MediaType.APPLICATION_JSON) // public String getBlogURL() { // return blogURL; // } // // public void setId(String id) { // this.id = id; // } // // public void setFirstName(String firstName) { // this.firstName = firstName; // } // // public void setLastName(String lastName) { // this.lastName = lastName; // } // // public void setBlogURL(String blogURL) { // this.blogURL = blogURL; // } // // // } // Path: rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/infrastructure/AuthorRepositoryBean.java import com.readlearncode.dukesbookshop.restserver.domain.Author; import javax.ejb.Stateless; import java.util.*; import java.util.stream.Collectors; package com.readlearncode.dukesbookshop.restserver.infrastructure; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Stateless public class AuthorRepositoryBean implements AuthorRepository {
private final Map<String, Author> authors = new HashMap<>();
readlearncode/RESTful-Service-with-JAX-RS-2.0-Course
rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/infrastructure/BootstrapData.java
// Path: rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/domain/Author.java // @XmlRootElement // public class Author implements Serializable { // // private String id; // private String firstName; // private String lastName; // private String blogURL; // // public Author() { // } // // public Author(String id, String firstName, String lastName) { // this.id = id; // this.firstName = firstName; // this.lastName = lastName; // } // // public Author(String id, String firstName, String lastName, String blogURL) { // this(id, firstName, lastName); // this.blogURL = blogURL; // } // // // @Produces(MediaType.APPLICATION_JSON) // public String getId() { // return id; // } // // @GET // @Path("/firstName") // @Produces(MediaType.APPLICATION_JSON) // public String getFirstName() { // return firstName; // } // // @GET // @Path("/lastName") // @Produces(MediaType.APPLICATION_JSON) // public String getLastName() { // return lastName; // } // // @GET // @Path("/blog") // @Produces(MediaType.APPLICATION_JSON) // public String getBlogURL() { // return blogURL; // } // // public void setId(String id) { // this.id = id; // } // // public void setFirstName(String firstName) { // this.firstName = firstName; // } // // public void setLastName(String lastName) { // this.lastName = lastName; // } // // public void setBlogURL(String blogURL) { // this.blogURL = blogURL; // } // // // } // // Path: rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/domain/BookBuilder.java // public class BookBuilder { // private String id; // private String title; // private String description; // private Float price; // private Date published; // private ArrayList<Author> authors = new ArrayList<>(); // private String imageFileName; // private String link; // // public BookBuilder setId(String id) { // this.id = id; // return this; // } // // public BookBuilder setTitle(String title) { // this.title = title; // return this; // } // // public BookBuilder setDescription(String description) { // this.description = description; // return this; // } // // public BookBuilder setPrice(Float price) { // this.price = price; // return this; // } // // public BookBuilder setPublished(Date published) { // this.published = published; // return this; // } // // public BookBuilder setAuthors(ArrayList<Author> authors) { // this.authors.addAll(authors); // return this; // } // // public BookBuilder addAuthor(Author author) { // this.authors.add(author); // return this; // } // // public BookBuilder setImageFileName(String imageFileName) { // this.imageFileName = imageFileName; // return this; // } // // public BookBuilder setLink(String link) { // this.link = link; // return this; // } // // public Book createBook() { // return new Book(id, title, description, price, published, authors, imageFileName, link); // } // }
import com.readlearncode.dukesbookshop.restserver.domain.Author; import com.readlearncode.dukesbookshop.restserver.domain.BookBuilder; import javax.annotation.PostConstruct; import javax.ejb.EJB; import javax.ejb.Singleton; import javax.ejb.Startup; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat;
package com.readlearncode.dukesbookshop.restserver.infrastructure; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Singleton @Startup public class BootstrapData { private static final String API_URL = "http://localhost:8081/rest-server"; private static final String IMAGE_LOCATION = "/images/covers/"; @EJB private BookRepository bookRepository; @EJB private AuthorRepository authorRepository; @PostConstruct public void populateRepositories() { DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); // Create the authors
// Path: rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/domain/Author.java // @XmlRootElement // public class Author implements Serializable { // // private String id; // private String firstName; // private String lastName; // private String blogURL; // // public Author() { // } // // public Author(String id, String firstName, String lastName) { // this.id = id; // this.firstName = firstName; // this.lastName = lastName; // } // // public Author(String id, String firstName, String lastName, String blogURL) { // this(id, firstName, lastName); // this.blogURL = blogURL; // } // // // @Produces(MediaType.APPLICATION_JSON) // public String getId() { // return id; // } // // @GET // @Path("/firstName") // @Produces(MediaType.APPLICATION_JSON) // public String getFirstName() { // return firstName; // } // // @GET // @Path("/lastName") // @Produces(MediaType.APPLICATION_JSON) // public String getLastName() { // return lastName; // } // // @GET // @Path("/blog") // @Produces(MediaType.APPLICATION_JSON) // public String getBlogURL() { // return blogURL; // } // // public void setId(String id) { // this.id = id; // } // // public void setFirstName(String firstName) { // this.firstName = firstName; // } // // public void setLastName(String lastName) { // this.lastName = lastName; // } // // public void setBlogURL(String blogURL) { // this.blogURL = blogURL; // } // // // } // // Path: rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/domain/BookBuilder.java // public class BookBuilder { // private String id; // private String title; // private String description; // private Float price; // private Date published; // private ArrayList<Author> authors = new ArrayList<>(); // private String imageFileName; // private String link; // // public BookBuilder setId(String id) { // this.id = id; // return this; // } // // public BookBuilder setTitle(String title) { // this.title = title; // return this; // } // // public BookBuilder setDescription(String description) { // this.description = description; // return this; // } // // public BookBuilder setPrice(Float price) { // this.price = price; // return this; // } // // public BookBuilder setPublished(Date published) { // this.published = published; // return this; // } // // public BookBuilder setAuthors(ArrayList<Author> authors) { // this.authors.addAll(authors); // return this; // } // // public BookBuilder addAuthor(Author author) { // this.authors.add(author); // return this; // } // // public BookBuilder setImageFileName(String imageFileName) { // this.imageFileName = imageFileName; // return this; // } // // public BookBuilder setLink(String link) { // this.link = link; // return this; // } // // public Book createBook() { // return new Book(id, title, description, price, published, authors, imageFileName, link); // } // } // Path: rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/infrastructure/BootstrapData.java import com.readlearncode.dukesbookshop.restserver.domain.Author; import com.readlearncode.dukesbookshop.restserver.domain.BookBuilder; import javax.annotation.PostConstruct; import javax.ejb.EJB; import javax.ejb.Singleton; import javax.ejb.Startup; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; package com.readlearncode.dukesbookshop.restserver.infrastructure; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @Singleton @Startup public class BootstrapData { private static final String API_URL = "http://localhost:8081/rest-server"; private static final String IMAGE_LOCATION = "/images/covers/"; @EJB private BookRepository bookRepository; @EJB private AuthorRepository authorRepository; @PostConstruct public void populateRepositories() { DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); // Create the authors
Author meek = authorRepository.saveAuthor(new Author("1", "Captain S. P.", "Meek", "http://www.gutenberg.org"));
readlearncode/RESTful-Service-with-JAX-RS-2.0-Course
rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/infrastructure/BootstrapData.java
// Path: rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/domain/Author.java // @XmlRootElement // public class Author implements Serializable { // // private String id; // private String firstName; // private String lastName; // private String blogURL; // // public Author() { // } // // public Author(String id, String firstName, String lastName) { // this.id = id; // this.firstName = firstName; // this.lastName = lastName; // } // // public Author(String id, String firstName, String lastName, String blogURL) { // this(id, firstName, lastName); // this.blogURL = blogURL; // } // // // @Produces(MediaType.APPLICATION_JSON) // public String getId() { // return id; // } // // @GET // @Path("/firstName") // @Produces(MediaType.APPLICATION_JSON) // public String getFirstName() { // return firstName; // } // // @GET // @Path("/lastName") // @Produces(MediaType.APPLICATION_JSON) // public String getLastName() { // return lastName; // } // // @GET // @Path("/blog") // @Produces(MediaType.APPLICATION_JSON) // public String getBlogURL() { // return blogURL; // } // // public void setId(String id) { // this.id = id; // } // // public void setFirstName(String firstName) { // this.firstName = firstName; // } // // public void setLastName(String lastName) { // this.lastName = lastName; // } // // public void setBlogURL(String blogURL) { // this.blogURL = blogURL; // } // // // } // // Path: rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/domain/BookBuilder.java // public class BookBuilder { // private String id; // private String title; // private String description; // private Float price; // private Date published; // private ArrayList<Author> authors = new ArrayList<>(); // private String imageFileName; // private String link; // // public BookBuilder setId(String id) { // this.id = id; // return this; // } // // public BookBuilder setTitle(String title) { // this.title = title; // return this; // } // // public BookBuilder setDescription(String description) { // this.description = description; // return this; // } // // public BookBuilder setPrice(Float price) { // this.price = price; // return this; // } // // public BookBuilder setPublished(Date published) { // this.published = published; // return this; // } // // public BookBuilder setAuthors(ArrayList<Author> authors) { // this.authors.addAll(authors); // return this; // } // // public BookBuilder addAuthor(Author author) { // this.authors.add(author); // return this; // } // // public BookBuilder setImageFileName(String imageFileName) { // this.imageFileName = imageFileName; // return this; // } // // public BookBuilder setLink(String link) { // this.link = link; // return this; // } // // public Book createBook() { // return new Book(id, title, description, price, published, authors, imageFileName, link); // } // }
import com.readlearncode.dukesbookshop.restserver.domain.Author; import com.readlearncode.dukesbookshop.restserver.domain.BookBuilder; import javax.annotation.PostConstruct; import javax.ejb.EJB; import javax.ejb.Singleton; import javax.ejb.Startup; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat;
@PostConstruct public void populateRepositories() { DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); // Create the authors Author meek = authorRepository.saveAuthor(new Author("1", "Captain S. P.", "Meek", "http://www.gutenberg.org")); Author wright = authorRepository.saveAuthor(new Author("2", "Sewell", "Peaslee Wright", "http://www.gutenberg.org")); Author knight = authorRepository.saveAuthor(new Author("3", "Damon Francis", "Knight", "http://www.gutenberg.org")); Author dee = authorRepository.saveAuthor(new Author("4", "Roger", "Dee", "http://www.gutenberg.org")); Author sohl = authorRepository.saveAuthor(new Author("5", "Gerald Allan", "Sohl", "http://www.gutenberg.org")); Author harmon = authorRepository.saveAuthor(new Author("6", "Jim", "Harmon", "http://www.gutenberg.org")); Author fetlet = authorRepository.saveAuthor(new Author("7", "Andrew", "Fetler", "http://www.gutenberg.org")); Author leiber = authorRepository.saveAuthor(new Author("8", "Fritz", "Leiber", "http://www.gutenberg.org")); Author janis = authorRepository.saveAuthor(new Author("9", "Jean", "Janis", "http://www.gutenberg.org")); Author mayhem = authorRepository.saveAuthor(new Author("10", "Johnny", "Mayhem", "http://www.gutenberg.org")); Author savage = authorRepository.saveAuthor(new Author("11", "Arthur", "Savage", "http://www.gutenberg.org")); Author young = authorRepository.saveAuthor(new Author("12", "Robert", "Young", "http://www.gutenberg.org")); Author miller = authorRepository.saveAuthor(new Author("13", "R", "DeWitt Miller", "http://www.gutenberg.org")); Author stecher = authorRepository.saveAuthor(new Author("14", "L. J.", "Stecher JR.", "http://www.gutenberg.org")); Author stuart = authorRepository.saveAuthor(new Author("15", "William", "Stuart", "http://www.gutenberg.org")); Author leinster = authorRepository.saveAuthor(new Author("16", "Murray", "Leinster", "http://www.gutenberg.org")); Author ludwig = authorRepository.saveAuthor(new Author("17", "Edward", "Ludwig", "http://www.gutenberg.org")); try { // Create the books bookRepository.saveBook(
// Path: rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/domain/Author.java // @XmlRootElement // public class Author implements Serializable { // // private String id; // private String firstName; // private String lastName; // private String blogURL; // // public Author() { // } // // public Author(String id, String firstName, String lastName) { // this.id = id; // this.firstName = firstName; // this.lastName = lastName; // } // // public Author(String id, String firstName, String lastName, String blogURL) { // this(id, firstName, lastName); // this.blogURL = blogURL; // } // // // @Produces(MediaType.APPLICATION_JSON) // public String getId() { // return id; // } // // @GET // @Path("/firstName") // @Produces(MediaType.APPLICATION_JSON) // public String getFirstName() { // return firstName; // } // // @GET // @Path("/lastName") // @Produces(MediaType.APPLICATION_JSON) // public String getLastName() { // return lastName; // } // // @GET // @Path("/blog") // @Produces(MediaType.APPLICATION_JSON) // public String getBlogURL() { // return blogURL; // } // // public void setId(String id) { // this.id = id; // } // // public void setFirstName(String firstName) { // this.firstName = firstName; // } // // public void setLastName(String lastName) { // this.lastName = lastName; // } // // public void setBlogURL(String blogURL) { // this.blogURL = blogURL; // } // // // } // // Path: rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/domain/BookBuilder.java // public class BookBuilder { // private String id; // private String title; // private String description; // private Float price; // private Date published; // private ArrayList<Author> authors = new ArrayList<>(); // private String imageFileName; // private String link; // // public BookBuilder setId(String id) { // this.id = id; // return this; // } // // public BookBuilder setTitle(String title) { // this.title = title; // return this; // } // // public BookBuilder setDescription(String description) { // this.description = description; // return this; // } // // public BookBuilder setPrice(Float price) { // this.price = price; // return this; // } // // public BookBuilder setPublished(Date published) { // this.published = published; // return this; // } // // public BookBuilder setAuthors(ArrayList<Author> authors) { // this.authors.addAll(authors); // return this; // } // // public BookBuilder addAuthor(Author author) { // this.authors.add(author); // return this; // } // // public BookBuilder setImageFileName(String imageFileName) { // this.imageFileName = imageFileName; // return this; // } // // public BookBuilder setLink(String link) { // this.link = link; // return this; // } // // public Book createBook() { // return new Book(id, title, description, price, published, authors, imageFileName, link); // } // } // Path: rest-server/src/main/java/com/readlearncode/dukesbookshop/restserver/infrastructure/BootstrapData.java import com.readlearncode.dukesbookshop.restserver.domain.Author; import com.readlearncode.dukesbookshop.restserver.domain.BookBuilder; import javax.annotation.PostConstruct; import javax.ejb.EJB; import javax.ejb.Singleton; import javax.ejb.Startup; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; @PostConstruct public void populateRepositories() { DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); // Create the authors Author meek = authorRepository.saveAuthor(new Author("1", "Captain S. P.", "Meek", "http://www.gutenberg.org")); Author wright = authorRepository.saveAuthor(new Author("2", "Sewell", "Peaslee Wright", "http://www.gutenberg.org")); Author knight = authorRepository.saveAuthor(new Author("3", "Damon Francis", "Knight", "http://www.gutenberg.org")); Author dee = authorRepository.saveAuthor(new Author("4", "Roger", "Dee", "http://www.gutenberg.org")); Author sohl = authorRepository.saveAuthor(new Author("5", "Gerald Allan", "Sohl", "http://www.gutenberg.org")); Author harmon = authorRepository.saveAuthor(new Author("6", "Jim", "Harmon", "http://www.gutenberg.org")); Author fetlet = authorRepository.saveAuthor(new Author("7", "Andrew", "Fetler", "http://www.gutenberg.org")); Author leiber = authorRepository.saveAuthor(new Author("8", "Fritz", "Leiber", "http://www.gutenberg.org")); Author janis = authorRepository.saveAuthor(new Author("9", "Jean", "Janis", "http://www.gutenberg.org")); Author mayhem = authorRepository.saveAuthor(new Author("10", "Johnny", "Mayhem", "http://www.gutenberg.org")); Author savage = authorRepository.saveAuthor(new Author("11", "Arthur", "Savage", "http://www.gutenberg.org")); Author young = authorRepository.saveAuthor(new Author("12", "Robert", "Young", "http://www.gutenberg.org")); Author miller = authorRepository.saveAuthor(new Author("13", "R", "DeWitt Miller", "http://www.gutenberg.org")); Author stecher = authorRepository.saveAuthor(new Author("14", "L. J.", "Stecher JR.", "http://www.gutenberg.org")); Author stuart = authorRepository.saveAuthor(new Author("15", "William", "Stuart", "http://www.gutenberg.org")); Author leinster = authorRepository.saveAuthor(new Author("16", "Murray", "Leinster", "http://www.gutenberg.org")); Author ludwig = authorRepository.saveAuthor(new Author("17", "Edward", "Ludwig", "http://www.gutenberg.org")); try { // Create the books bookRepository.saveBook(
new BookBuilder()
readlearncode/RESTful-Service-with-JAX-RS-2.0-Course
rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/BookService.java
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Author.java // public class Author implements Serializable { // // private String id; // private String firstName; // private String lastName; // private String blogURL; // // public Author(){} // // public Author(String firstName, String lastName){ // this.id = UUID.randomUUID().toString(); // this.firstName = firstName; // this.lastName = lastName; // } // // public Author(String firstName, String lastName, String blogURL){ // this(firstName, lastName); // this.blogURL = blogURL; // } // // public Author(String id, String firstName, String lastName, String blogURL){ // this(firstName, lastName, blogURL); // this.id = id; // } // // public String getId() { // return id; // } // // public void setId(String id) { // this.id = id; // } // // public String getFirstName() { // return firstName; // } // // public void setFirstName(String firstName) { // this.firstName = firstName; // } // // public String getLastName() { // return lastName; // } // // public void setLastName(String lastName) { // this.lastName = lastName; // } // // public String getBlogURL() { // return blogURL; // } // // public void setBlogURL(String blogURL) { // this.blogURL = blogURL; // } // // @Override // public String toString() { // return "Author{" + // "id='" + id + '\'' + // ", firstName='" + firstName + '\'' + // ", lastName='" + lastName + '\'' + // ", blogURL='" + blogURL + '\'' + // '}'; // } // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Book.java // public class Book extends Hypermedia implements Serializable { // private static final long serialVersionUID = 1L; // // private String id; // // private String title; // // private String description; // // private List<Author> authors = Collections.emptyList(); // // private Float price; // // private String imageFileName; // // private String link; // // private String published; // // public Book(){} // // public Book(String id, String title, String description, Float price, String published, List<Author> authors, String imageFileName, String link, List<LinkResource> links) { // this.id = id; // this.title = title; // this.description = description; // this.price = price; // this.published = published; // this.authors = authors; // this.imageFileName = imageFileName; // this.link = link; // this.setLinks(links); // } // // public final String getId() { // return id; // } // // public final void setId(final String id) { // this.id = id; // } // // public final String getTitle() { // return title; // } // // public final void setTitle(final String title) { // this.title = title; // } // // public String getDescription() { // return description; // } // // public void setDescription(String description) { // this.description = description; // } // // public final Float getPrice() { // return price; // } // // public final void setPrice(final Float price) { // this.price = price; // } // // public final String getPublished() { // return published; // } // // public final void setPublished(final String published) { // this.published = published; // } // // public static long getSerialVersionUID() { // return serialVersionUID; // } // // public List<Author> getAuthors() { // return authors; // } // // public void setAuthors(List<Author> authors) { // this.authors = authors; // } // // public void addAuthor(Author author){ // this.authors.add(author); // } // // public String getImageFileName() { // return imageFileName; // } // // public void setImageFileName(String imageFileName) { // this.imageFileName = imageFileName; // } // // public String getLink() { // return link; // } // // public void setLink(String link) { // this.link = link; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Book book = (Book) o; // return Objects.equals(id, book.id) && // Objects.equals(title, book.title) && // Objects.equals(description, book.description) && // Objects.equals(authors, book.authors) && // Objects.equals(price, book.price) && // Objects.equals(imageFileName, book.imageFileName) && // Objects.equals(link, book.link) && // Objects.equals(published, book.published); // } // // @Override // public int hashCode() { // return Objects.hash(id, title, description, authors, price, imageFileName, link, published); // } // // @Override // public String toString() { // return "Book{" + // "id='" + id + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", authors=" + authors + // ", price=" + price + // ", imageFileName='" + imageFileName + '\'' + // ", link='" + link + '\'' + // ", published='" + published + '\'' + // '}'; // } // }
import com.readlearncode.dukesbookshop.domain.Author; import com.readlearncode.dukesbookshop.domain.Book; import javax.json.JsonArray; import java.util.List;
package com.readlearncode.dukesbookshop.restclient; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ public interface BookService { List<Book> getBooks(); Book getBook(String id); void deleteBook(String isbn); Book saveBook(Book book);
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Author.java // public class Author implements Serializable { // // private String id; // private String firstName; // private String lastName; // private String blogURL; // // public Author(){} // // public Author(String firstName, String lastName){ // this.id = UUID.randomUUID().toString(); // this.firstName = firstName; // this.lastName = lastName; // } // // public Author(String firstName, String lastName, String blogURL){ // this(firstName, lastName); // this.blogURL = blogURL; // } // // public Author(String id, String firstName, String lastName, String blogURL){ // this(firstName, lastName, blogURL); // this.id = id; // } // // public String getId() { // return id; // } // // public void setId(String id) { // this.id = id; // } // // public String getFirstName() { // return firstName; // } // // public void setFirstName(String firstName) { // this.firstName = firstName; // } // // public String getLastName() { // return lastName; // } // // public void setLastName(String lastName) { // this.lastName = lastName; // } // // public String getBlogURL() { // return blogURL; // } // // public void setBlogURL(String blogURL) { // this.blogURL = blogURL; // } // // @Override // public String toString() { // return "Author{" + // "id='" + id + '\'' + // ", firstName='" + firstName + '\'' + // ", lastName='" + lastName + '\'' + // ", blogURL='" + blogURL + '\'' + // '}'; // } // } // // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Book.java // public class Book extends Hypermedia implements Serializable { // private static final long serialVersionUID = 1L; // // private String id; // // private String title; // // private String description; // // private List<Author> authors = Collections.emptyList(); // // private Float price; // // private String imageFileName; // // private String link; // // private String published; // // public Book(){} // // public Book(String id, String title, String description, Float price, String published, List<Author> authors, String imageFileName, String link, List<LinkResource> links) { // this.id = id; // this.title = title; // this.description = description; // this.price = price; // this.published = published; // this.authors = authors; // this.imageFileName = imageFileName; // this.link = link; // this.setLinks(links); // } // // public final String getId() { // return id; // } // // public final void setId(final String id) { // this.id = id; // } // // public final String getTitle() { // return title; // } // // public final void setTitle(final String title) { // this.title = title; // } // // public String getDescription() { // return description; // } // // public void setDescription(String description) { // this.description = description; // } // // public final Float getPrice() { // return price; // } // // public final void setPrice(final Float price) { // this.price = price; // } // // public final String getPublished() { // return published; // } // // public final void setPublished(final String published) { // this.published = published; // } // // public static long getSerialVersionUID() { // return serialVersionUID; // } // // public List<Author> getAuthors() { // return authors; // } // // public void setAuthors(List<Author> authors) { // this.authors = authors; // } // // public void addAuthor(Author author){ // this.authors.add(author); // } // // public String getImageFileName() { // return imageFileName; // } // // public void setImageFileName(String imageFileName) { // this.imageFileName = imageFileName; // } // // public String getLink() { // return link; // } // // public void setLink(String link) { // this.link = link; // } // // @Override // public boolean equals(Object o) { // if (this == o) return true; // if (o == null || getClass() != o.getClass()) return false; // Book book = (Book) o; // return Objects.equals(id, book.id) && // Objects.equals(title, book.title) && // Objects.equals(description, book.description) && // Objects.equals(authors, book.authors) && // Objects.equals(price, book.price) && // Objects.equals(imageFileName, book.imageFileName) && // Objects.equals(link, book.link) && // Objects.equals(published, book.published); // } // // @Override // public int hashCode() { // return Objects.hash(id, title, description, authors, price, imageFileName, link, published); // } // // @Override // public String toString() { // return "Book{" + // "id='" + id + '\'' + // ", title='" + title + '\'' + // ", description='" + description + '\'' + // ", authors=" + authors + // ", price=" + price + // ", imageFileName='" + imageFileName + '\'' + // ", link='" + link + '\'' + // ", published='" + published + '\'' + // '}'; // } // } // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/BookService.java import com.readlearncode.dukesbookshop.domain.Author; import com.readlearncode.dukesbookshop.domain.Book; import javax.json.JsonArray; import java.util.List; package com.readlearncode.dukesbookshop.restclient; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ public interface BookService { List<Book> getBooks(); Book getBook(String id); void deleteBook(String isbn); Book saveBook(Book book);
List<Author> extractAuthors(JsonArray authorArray);
readlearncode/RESTful-Service-with-JAX-RS-2.0-Course
rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/AuthorServiceImpl.java
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Author.java // public class Author implements Serializable { // // private String id; // private String firstName; // private String lastName; // private String blogURL; // // public Author(){} // // public Author(String firstName, String lastName){ // this.id = UUID.randomUUID().toString(); // this.firstName = firstName; // this.lastName = lastName; // } // // public Author(String firstName, String lastName, String blogURL){ // this(firstName, lastName); // this.blogURL = blogURL; // } // // public Author(String id, String firstName, String lastName, String blogURL){ // this(firstName, lastName, blogURL); // this.id = id; // } // // public String getId() { // return id; // } // // public void setId(String id) { // this.id = id; // } // // public String getFirstName() { // return firstName; // } // // public void setFirstName(String firstName) { // this.firstName = firstName; // } // // public String getLastName() { // return lastName; // } // // public void setLastName(String lastName) { // this.lastName = lastName; // } // // public String getBlogURL() { // return blogURL; // } // // public void setBlogURL(String blogURL) { // this.blogURL = blogURL; // } // // @Override // public String toString() { // return "Author{" + // "id='" + id + '\'' + // ", firstName='" + firstName + '\'' + // ", lastName='" + lastName + '\'' + // ", blogURL='" + blogURL + '\'' + // '}'; // } // }
import com.readlearncode.dukesbookshop.domain.Author; import javax.annotation.PostConstruct; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; import javax.json.JsonArray; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.MediaType; import java.util.Collections; import java.util.List;
package com.readlearncode.dukesbookshop.restclient; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @ApplicationScoped public class AuthorServiceImpl implements AuthorService { private static final String API_URL = "http://localhost:8081/rest-server"; private static final String AUTHORS_ENDPOINT = API_URL + "/api/authors"; private Client client; @Inject private BookService bookService; @PostConstruct public void initialise() { client = ClientBuilder.newClient(); } @Override
// Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/domain/Author.java // public class Author implements Serializable { // // private String id; // private String firstName; // private String lastName; // private String blogURL; // // public Author(){} // // public Author(String firstName, String lastName){ // this.id = UUID.randomUUID().toString(); // this.firstName = firstName; // this.lastName = lastName; // } // // public Author(String firstName, String lastName, String blogURL){ // this(firstName, lastName); // this.blogURL = blogURL; // } // // public Author(String id, String firstName, String lastName, String blogURL){ // this(firstName, lastName, blogURL); // this.id = id; // } // // public String getId() { // return id; // } // // public void setId(String id) { // this.id = id; // } // // public String getFirstName() { // return firstName; // } // // public void setFirstName(String firstName) { // this.firstName = firstName; // } // // public String getLastName() { // return lastName; // } // // public void setLastName(String lastName) { // this.lastName = lastName; // } // // public String getBlogURL() { // return blogURL; // } // // public void setBlogURL(String blogURL) { // this.blogURL = blogURL; // } // // @Override // public String toString() { // return "Author{" + // "id='" + id + '\'' + // ", firstName='" + firstName + '\'' + // ", lastName='" + lastName + '\'' + // ", blogURL='" + blogURL + '\'' + // '}'; // } // } // Path: rest-client/src/main/java/com/readlearncode/dukesbookshop/restclient/AuthorServiceImpl.java import com.readlearncode.dukesbookshop.domain.Author; import javax.annotation.PostConstruct; import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; import javax.json.JsonArray; import javax.ws.rs.client.Client; import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.client.WebTarget; import javax.ws.rs.core.MediaType; import java.util.Collections; import java.util.List; package com.readlearncode.dukesbookshop.restclient; /** * Source code github.com/readlearncode * * @author Alex Theedom www.readlearncode.com * @version 1.0 */ @ApplicationScoped public class AuthorServiceImpl implements AuthorService { private static final String API_URL = "http://localhost:8081/rest-server"; private static final String AUTHORS_ENDPOINT = API_URL + "/api/authors"; private Client client; @Inject private BookService bookService; @PostConstruct public void initialise() { client = ClientBuilder.newClient(); } @Override
public List<Author> getAuthors() {
aelstad/keccakj
src/test/java/com/github/aelstad/keccakj/fips202/TestSHA3_256.java
// Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_256.java // public final class SHA3_256 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_256() { // super("SHA3-256", 2*256, 256/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // }
import java.io.InputStream; import java.util.List; import org.junit.Test; import com.github.aelstad.keccakj.fips202.SHA3_256;
/* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.fips202; public class TestSHA3_256 { @Test public void checkTestVectors() throws Exception { InputStream is = getClass().getResourceAsStream("/com/github/aelstad/keccakj/fips202/ShortMsgKAT_SHA3-256.txt"); KeccakDigestTestUtils kdtu = new KeccakDigestTestUtils(); List<KeccakDigestTestUtils.DigestTest> tests = kdtu.parseTests(is);
// Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_256.java // public final class SHA3_256 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_256() { // super("SHA3-256", 2*256, 256/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // Path: src/test/java/com/github/aelstad/keccakj/fips202/TestSHA3_256.java import java.io.InputStream; import java.util.List; import org.junit.Test; import com.github.aelstad.keccakj.fips202.SHA3_256; /* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.fips202; public class TestSHA3_256 { @Test public void checkTestVectors() throws Exception { InputStream is = getClass().getResourceAsStream("/com/github/aelstad/keccakj/fips202/ShortMsgKAT_SHA3-256.txt"); KeccakDigestTestUtils kdtu = new KeccakDigestTestUtils(); List<KeccakDigestTestUtils.DigestTest> tests = kdtu.parseTests(is);
SHA3_256 sha = new SHA3_256();
aelstad/keccakj
src/test/java/com/github/aelstad/keccakj/kangaroo/TestKangarooTwelve.java
// Path: src/main/java/com/github/aelstad/keccakj/kangaroo/KangarooTwelve.java // public class KangarooTwelve extends MessageDigest { // private final static int CHUNK_SIZE=8192; // // private final static byte[] PAD_FIRST_LONG = new byte[] // { (byte) 0x3, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0,(byte) 0, (byte) 0 }; // private final static byte[] PAD_LAST_LONG = new byte[] { (byte) 0xFF, (byte) 0xFF }; // // private final static byte[] DOMAIN_PAD_SHORT = new byte[] { 3 }; // private final static byte[] DOMAIN_PAD_LONG = new byte[] { 2 }; // // private KeccakSponge main = new KeccakSponge(12, 256, (byte) 0, 0); // private KeccakSponge inner = new KeccakSponge(12, 256, (byte) 0x3, 3); // // private KeccakSponge current; // // private byte[] salt; // // int off=0; // long chunk=0; // // private int outputLen; // // void flip() { // if(off == 0) { // return; // } // if(chunk > 0) { // BitOutputStream bos = main.getAbsorbStream(); // if(chunk == 1) { // bos.write(PAD_FIRST_LONG); // } // inner.getAbsorbStream().close(); // BitInputStream bis = inner.getSqueezeStream(); // byte[] cv = new byte[32]; // bis.read(cv); // bis.close(); // inner.reset(); // bos.write(cv); // } // ++chunk; // current = inner; // off = 0; // } // // public KangarooTwelve(int outputLen, byte[] diversifier) { // super(""); // this.outputLen = outputLen; // setSalt(diversifier); // reset(); // } // // private void setSalt(byte[] salt) { // byte[] buf = new byte[9]; // int saltlen = salt != null ? salt.length : 0; // int len = rightEncode(saltlen, buf); // this.salt = new byte[saltlen + len]; // if(saltlen > 0) { // System.arraycopy(salt, 0, this.salt, 0, saltlen); // } // System.arraycopy(buf, (buf.length-len), this.salt, saltlen, len); // } // // @Override // protected void engineUpdate(byte input) { // if(off == CHUNK_SIZE) { // flip(); // } // current.getAbsorbStream().write((byte) input); // // } // // @Override // protected void engineUpdate(byte[] input, int offset, int len) { // while(len > 0) { // int left = CHUNK_SIZE - off; // // if(left == 0) { // flip(); // } else { // int copyLen = Math.min(left, len); // current.getAbsorbStream().write(input, offset, copyLen); // len -= copyLen; // offset += copyLen; // off += copyLen; // } // } // // } // // int rightEncode(long l, byte[] buf) { // int i=buf.length-2; // int len=0; // while(l > 0) { // buf[i] = (byte) l; // l >>= 8; // --i; // ++len; // } // buf[buf.length-1] = (byte) len; // // return (len+1); // } // // @Override // protected byte[] engineDigest() { // engineUpdate(salt, 0, salt.length); // BitOutputStream bos = main.getAbsorbStream(); // if(chunk > 1) // { // flip(); // byte[] buf = new byte[9]; // int len = rightEncode(chunk-1, buf); // bos.write(buf, buf.length-len, len); // bos.write(PAD_LAST_LONG); // bos.writeBits(DOMAIN_PAD_LONG, 0, 2); // } else { // bos.writeBits(DOMAIN_PAD_SHORT, 0, 2); // } // bos.close(); // BitInputStream bis = main.getSqueezeStream(); // byte[] rv = new byte[outputLen]; // bis.read(rv); // bis.close(); // // reset(); // // return rv; // } // // @Override // protected void engineReset() { // main.reset(); // inner.reset(); // off = 0; // chunk = 0; // current = main; // } // }
import java.io.ByteArrayOutputStream; import org.apache.commons.codec.binary.Hex; import org.junit.Assert; import org.junit.Test; import com.github.aelstad.keccakj.kangaroo.KangarooTwelve;
package com.github.aelstad.keccakj.kangaroo; public class TestKangarooTwelve { byte[] getPattern(int length) { ByteArrayOutputStream bos = new ByteArrayOutputStream(length); int i=0; while(length > 0 ) { bos.write(i); ++i; if(i==0xFB) { i = 0; } --length; } return bos.toByteArray(); } byte[] getBytesFF(int length) { ByteArrayOutputStream bos = new ByteArrayOutputStream(length); while(length > 0 ) { bos.write(0xff); --length; } return bos.toByteArray(); } @Test public void testEmpty() {
// Path: src/main/java/com/github/aelstad/keccakj/kangaroo/KangarooTwelve.java // public class KangarooTwelve extends MessageDigest { // private final static int CHUNK_SIZE=8192; // // private final static byte[] PAD_FIRST_LONG = new byte[] // { (byte) 0x3, (byte) 0, (byte) 0, (byte) 0, (byte) 0, (byte) 0,(byte) 0, (byte) 0 }; // private final static byte[] PAD_LAST_LONG = new byte[] { (byte) 0xFF, (byte) 0xFF }; // // private final static byte[] DOMAIN_PAD_SHORT = new byte[] { 3 }; // private final static byte[] DOMAIN_PAD_LONG = new byte[] { 2 }; // // private KeccakSponge main = new KeccakSponge(12, 256, (byte) 0, 0); // private KeccakSponge inner = new KeccakSponge(12, 256, (byte) 0x3, 3); // // private KeccakSponge current; // // private byte[] salt; // // int off=0; // long chunk=0; // // private int outputLen; // // void flip() { // if(off == 0) { // return; // } // if(chunk > 0) { // BitOutputStream bos = main.getAbsorbStream(); // if(chunk == 1) { // bos.write(PAD_FIRST_LONG); // } // inner.getAbsorbStream().close(); // BitInputStream bis = inner.getSqueezeStream(); // byte[] cv = new byte[32]; // bis.read(cv); // bis.close(); // inner.reset(); // bos.write(cv); // } // ++chunk; // current = inner; // off = 0; // } // // public KangarooTwelve(int outputLen, byte[] diversifier) { // super(""); // this.outputLen = outputLen; // setSalt(diversifier); // reset(); // } // // private void setSalt(byte[] salt) { // byte[] buf = new byte[9]; // int saltlen = salt != null ? salt.length : 0; // int len = rightEncode(saltlen, buf); // this.salt = new byte[saltlen + len]; // if(saltlen > 0) { // System.arraycopy(salt, 0, this.salt, 0, saltlen); // } // System.arraycopy(buf, (buf.length-len), this.salt, saltlen, len); // } // // @Override // protected void engineUpdate(byte input) { // if(off == CHUNK_SIZE) { // flip(); // } // current.getAbsorbStream().write((byte) input); // // } // // @Override // protected void engineUpdate(byte[] input, int offset, int len) { // while(len > 0) { // int left = CHUNK_SIZE - off; // // if(left == 0) { // flip(); // } else { // int copyLen = Math.min(left, len); // current.getAbsorbStream().write(input, offset, copyLen); // len -= copyLen; // offset += copyLen; // off += copyLen; // } // } // // } // // int rightEncode(long l, byte[] buf) { // int i=buf.length-2; // int len=0; // while(l > 0) { // buf[i] = (byte) l; // l >>= 8; // --i; // ++len; // } // buf[buf.length-1] = (byte) len; // // return (len+1); // } // // @Override // protected byte[] engineDigest() { // engineUpdate(salt, 0, salt.length); // BitOutputStream bos = main.getAbsorbStream(); // if(chunk > 1) // { // flip(); // byte[] buf = new byte[9]; // int len = rightEncode(chunk-1, buf); // bos.write(buf, buf.length-len, len); // bos.write(PAD_LAST_LONG); // bos.writeBits(DOMAIN_PAD_LONG, 0, 2); // } else { // bos.writeBits(DOMAIN_PAD_SHORT, 0, 2); // } // bos.close(); // BitInputStream bis = main.getSqueezeStream(); // byte[] rv = new byte[outputLen]; // bis.read(rv); // bis.close(); // // reset(); // // return rv; // } // // @Override // protected void engineReset() { // main.reset(); // inner.reset(); // off = 0; // chunk = 0; // current = main; // } // } // Path: src/test/java/com/github/aelstad/keccakj/kangaroo/TestKangarooTwelve.java import java.io.ByteArrayOutputStream; import org.apache.commons.codec.binary.Hex; import org.junit.Assert; import org.junit.Test; import com.github.aelstad.keccakj.kangaroo.KangarooTwelve; package com.github.aelstad.keccakj.kangaroo; public class TestKangarooTwelve { byte[] getPattern(int length) { ByteArrayOutputStream bos = new ByteArrayOutputStream(length); int i=0; while(length > 0 ) { bos.write(i); ++i; if(i==0xFB) { i = 0; } --length; } return bos.toByteArray(); } byte[] getBytesFF(int length) { ByteArrayOutputStream bos = new ByteArrayOutputStream(length); while(length > 0 ) { bos.write(0xff); --length; } return bos.toByteArray(); } @Test public void testEmpty() {
KangarooTwelve kw = new KangarooTwelve(32, null);
aelstad/keccakj
src/main/java/com/github/aelstad/keccakj/core/Keccak1600.java
// Path: src/main/java/com/github/aelstad/keccakj/core/KeccakStateUtils.java // public enum StateOp { // ZERO, GET, VALIDATE, XOR_IN, XOR_TRANSFORM, WRAP, UNWRAP; // // public boolean isIn() { // return (this ==StateOp.XOR_IN || this == XOR_TRANSFORM || this ==StateOp.WRAP || this == StateOp.UNWRAP || this == VALIDATE); // } // // public boolean isOut() { // return (this == StateOp.GET || this == XOR_TRANSFORM || this==StateOp.WRAP || this == StateOp.UNWRAP); // } // // };
import java.util.Arrays; import com.github.aelstad.keccakj.core.KeccakStateUtils.StateOp;
/* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.core; /** * Java port of the reference implementation of Keccack-1600 permuation * from https://github.com/gvanas/KeccakCodePackage * */ public final class Keccak1600 { public Keccak1600() { this(256, 24); } public Keccak1600(int capacitityInBits) { this(capacitityInBits, NR_ROUNDS); } public Keccak1600(int capacityInBits, int rounds) { this.capacitityBits = capacityInBits; this.rateBits = 1600-capacityInBits; this.rateBytes = rateBits >> 3; this.firstRound = NR_ROUNDS - rounds; clear(); }
// Path: src/main/java/com/github/aelstad/keccakj/core/KeccakStateUtils.java // public enum StateOp { // ZERO, GET, VALIDATE, XOR_IN, XOR_TRANSFORM, WRAP, UNWRAP; // // public boolean isIn() { // return (this ==StateOp.XOR_IN || this == XOR_TRANSFORM || this ==StateOp.WRAP || this == StateOp.UNWRAP || this == VALIDATE); // } // // public boolean isOut() { // return (this == StateOp.GET || this == XOR_TRANSFORM || this==StateOp.WRAP || this == StateOp.UNWRAP); // } // // }; // Path: src/main/java/com/github/aelstad/keccakj/core/Keccak1600.java import java.util.Arrays; import com.github.aelstad.keccakj.core.KeccakStateUtils.StateOp; /* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.core; /** * Java port of the reference implementation of Keccack-1600 permuation * from https://github.com/gvanas/KeccakCodePackage * */ public final class Keccak1600 { public Keccak1600() { this(256, 24); } public Keccak1600(int capacitityInBits) { this(capacitityInBits, NR_ROUNDS); } public Keccak1600(int capacityInBits, int rounds) { this.capacitityBits = capacityInBits; this.rateBits = 1600-capacityInBits; this.rateBytes = rateBits >> 3; this.firstRound = NR_ROUNDS - rounds; clear(); }
byte byteOp(StateOp stateOp, int stateByteOff, byte in)
aelstad/keccakj
src/main/java/com/github/aelstad/keccakj/spi/Shake128Key.java
// Path: src/main/java/com/github/aelstad/keccakj/provider/Constants.java // public class Constants { // public static final String PROVIDER = "com.github.aelstad.keccakj"; // // public static final String SHA3_224 = "SHA3-224"; // public static final String SHA3_256 = "SHA3-256"; // public static final String SHA3_384 = "SHA3-384"; // public static final String SHA3_512 = "SHA3-512"; // // public static final String KECCAK_RND128 = "KECCAK-RND-128"; // public static final String KECCAK_RND256 = "KECCAK-RND-256"; // // public static final String SHAKE128_STREAM_CIPHER = "SHAKE128"; // public static final String SHAKE256_STREAM_CIPHER = "SHAKE256"; // // public static final String LAKEKEYAK_AUTHENTICATING_STREAM_CIPHER = "LAKE-KEYAK"; // }
import com.github.aelstad.keccakj.provider.Constants;
/* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.spi; public class Shake128Key extends RawKey { @Override public String getAlgorithm() {
// Path: src/main/java/com/github/aelstad/keccakj/provider/Constants.java // public class Constants { // public static final String PROVIDER = "com.github.aelstad.keccakj"; // // public static final String SHA3_224 = "SHA3-224"; // public static final String SHA3_256 = "SHA3-256"; // public static final String SHA3_384 = "SHA3-384"; // public static final String SHA3_512 = "SHA3-512"; // // public static final String KECCAK_RND128 = "KECCAK-RND-128"; // public static final String KECCAK_RND256 = "KECCAK-RND-256"; // // public static final String SHAKE128_STREAM_CIPHER = "SHAKE128"; // public static final String SHAKE256_STREAM_CIPHER = "SHAKE256"; // // public static final String LAKEKEYAK_AUTHENTICATING_STREAM_CIPHER = "LAKE-KEYAK"; // } // Path: src/main/java/com/github/aelstad/keccakj/spi/Shake128Key.java import com.github.aelstad.keccakj.provider.Constants; /* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.spi; public class Shake128Key extends RawKey { @Override public String getAlgorithm() {
return Constants.SHAKE128_STREAM_CIPHER;
aelstad/keccakj
src/test/java/com/github/aelstad/keccakj/keyak/v2/TestLakeKeyak.java
// Path: src/main/java/com/github/aelstad/keccakj/keyak/v2/LakeKeyak.java // public class LakeKeyak { // private final static int KEYPACK_LENGTH = 40; // private final static int SQUEEZE_BYTES = 1344/8; // private final static int ABSORB_BYTES = 1536/8; // // Piston piston; // // public LakeKeyak() { // piston = new Piston(SQUEEZE_BYTES, ABSORB_BYTES); // } // // public void init(byte[] key, byte[] nonce, int nonceOff, int nonceLen, byte[] tag, int tagoff, boolean forget, boolean unwrap) throws IOException, InvalidKeyException // { // if(key == null || key.length > KEYPACK_LENGTH-2) // throw new InvalidKeyException(); // // piston.reset(); // // PistonInitStreamBuilder pisb = new PistonInitStreamBuilder(key, KEYPACK_LENGTH, nonce, nonceOff, nonceLen); // // InputStream is = pisb.stream((byte) 1, (byte) 0); // piston.setStreams(null, is); // // int len = 0; // do { // if(len > 0) { // piston.spark(); // } else { // len = piston.fillBuffer(); // } // piston.transformBuffer(null, false); // len = piston.fillBuffer(); // } while(len > 0); // if(forget) { // forget(); // } // piston.handleTag(tag, tagoff, tag != null ? 16 : 0, unwrap); // } // // void forget() throws IOException { // byte[] tmp = new byte[32]; // piston.handleTag(tmp, 0, tmp.length, false); // piston.setStreams(null, new ByteArrayInputStream(tmp)); // piston.fillBuffer(); // piston.transformBuffer(null, false); // } // // void wrapOrUnwrap(InputStream in, InputStream ad, OutputStream out, byte[] tag, int tagoff, boolean forget, boolean unwrap) throws IOException // { // piston.setStreams(in, ad); // int len = 0; // do { // if(len > 0) { // piston.spark(); // } else { // len = piston.fillBuffer(); // } // piston.transformBuffer(out, unwrap); // len = piston.fillBuffer(); // } while(len > 0); // if(forget) { // forget(); // } // piston.handleTag(tag, tagoff, 16, unwrap); // } // // public void unwrap(InputStream ciphertext, InputStream ad, OutputStream plaintext, byte[] tag, int tagoff, boolean forget) throws IOException // { // wrapOrUnwrap(ciphertext, ad, plaintext, tag, tagoff, forget, true); // } // // public void wrap(InputStream ciphertext, InputStream ad, OutputStream plaintext, byte[] tag, int tagoff, boolean forget) throws IOException // { // wrapOrUnwrap(ciphertext, ad, plaintext, tag, tagoff, forget, false); // } // }
import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.security.InvalidKeyException; import java.util.ArrayList; import java.util.List; import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.binary.Hex; import org.junit.Assert; import org.junit.Test; import com.github.aelstad.keccakj.keyak.v2.LakeKeyak;
package com.github.aelstad.keccakj.keyak.v2; public class TestLakeKeyak { byte[] tagBuf = new byte[16]; byte[] generateSimpleRawMaterial(int len, int seed1, int seed2) { seed1 &= 0xff; byte[] rv = new byte[len]; for(int i=0; i < len; ++i) { int iRolled= ((i&0xff) << (seed2&7)) | ((i&0xff) >>> 8-(seed2&7)); int val = seed1 + (161*len) - iRolled + i; val &= 0xff; rv[i] = (byte) val; } return rv; } String getHexString(byte[] rv) { String tmp = Hex.encodeHexString(rv); String formatted=""; for(int i=0; i < tmp.length(); i+=2) { if(formatted.length()>0) formatted += " "; formatted += tmp.substring(i, i+2); } return formatted; }
// Path: src/main/java/com/github/aelstad/keccakj/keyak/v2/LakeKeyak.java // public class LakeKeyak { // private final static int KEYPACK_LENGTH = 40; // private final static int SQUEEZE_BYTES = 1344/8; // private final static int ABSORB_BYTES = 1536/8; // // Piston piston; // // public LakeKeyak() { // piston = new Piston(SQUEEZE_BYTES, ABSORB_BYTES); // } // // public void init(byte[] key, byte[] nonce, int nonceOff, int nonceLen, byte[] tag, int tagoff, boolean forget, boolean unwrap) throws IOException, InvalidKeyException // { // if(key == null || key.length > KEYPACK_LENGTH-2) // throw new InvalidKeyException(); // // piston.reset(); // // PistonInitStreamBuilder pisb = new PistonInitStreamBuilder(key, KEYPACK_LENGTH, nonce, nonceOff, nonceLen); // // InputStream is = pisb.stream((byte) 1, (byte) 0); // piston.setStreams(null, is); // // int len = 0; // do { // if(len > 0) { // piston.spark(); // } else { // len = piston.fillBuffer(); // } // piston.transformBuffer(null, false); // len = piston.fillBuffer(); // } while(len > 0); // if(forget) { // forget(); // } // piston.handleTag(tag, tagoff, tag != null ? 16 : 0, unwrap); // } // // void forget() throws IOException { // byte[] tmp = new byte[32]; // piston.handleTag(tmp, 0, tmp.length, false); // piston.setStreams(null, new ByteArrayInputStream(tmp)); // piston.fillBuffer(); // piston.transformBuffer(null, false); // } // // void wrapOrUnwrap(InputStream in, InputStream ad, OutputStream out, byte[] tag, int tagoff, boolean forget, boolean unwrap) throws IOException // { // piston.setStreams(in, ad); // int len = 0; // do { // if(len > 0) { // piston.spark(); // } else { // len = piston.fillBuffer(); // } // piston.transformBuffer(out, unwrap); // len = piston.fillBuffer(); // } while(len > 0); // if(forget) { // forget(); // } // piston.handleTag(tag, tagoff, 16, unwrap); // } // // public void unwrap(InputStream ciphertext, InputStream ad, OutputStream plaintext, byte[] tag, int tagoff, boolean forget) throws IOException // { // wrapOrUnwrap(ciphertext, ad, plaintext, tag, tagoff, forget, true); // } // // public void wrap(InputStream ciphertext, InputStream ad, OutputStream plaintext, byte[] tag, int tagoff, boolean forget) throws IOException // { // wrapOrUnwrap(ciphertext, ad, plaintext, tag, tagoff, forget, false); // } // } // Path: src/test/java/com/github/aelstad/keccakj/keyak/v2/TestLakeKeyak.java import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.security.InvalidKeyException; import java.util.ArrayList; import java.util.List; import org.apache.commons.codec.DecoderException; import org.apache.commons.codec.binary.Hex; import org.junit.Assert; import org.junit.Test; import com.github.aelstad.keccakj.keyak.v2.LakeKeyak; package com.github.aelstad.keccakj.keyak.v2; public class TestLakeKeyak { byte[] tagBuf = new byte[16]; byte[] generateSimpleRawMaterial(int len, int seed1, int seed2) { seed1 &= 0xff; byte[] rv = new byte[len]; for(int i=0; i < len; ++i) { int iRolled= ((i&0xff) << (seed2&7)) | ((i&0xff) >>> 8-(seed2&7)); int val = seed1 + (161*len) - iRolled + i; val &= 0xff; rv[i] = (byte) val; } return rv; } String getHexString(byte[] rv) { String tmp = Hex.encodeHexString(rv); String formatted=""; for(int i=0; i < tmp.length(); i+=2) { if(formatted.length()>0) formatted += " "; formatted += tmp.substring(i, i+2); } return formatted; }
void startEngine(LakeKeyak global, LakeKeyak wrap, LakeKeyak unwrap, byte[] key, byte[] nonce, boolean tag, boolean forget) throws IOException, InvalidKeyException {
aelstad/keccakj
src/test/java/com/github/aelstad/keccakj/provider/TestKeccakjProvider.java
// Path: src/main/java/com/github/aelstad/keccakj/cipher/CipherProviderFactory.java // public interface CipherProviderFactory { // public CipherInterface getInstance(String transformation) throws NoSuchAlgorithmException, NoSuchPaddingException; // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_224.java // public final class SHA3_224 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_224() { // super("SHA3-224", 224*2, 224/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_256.java // public final class SHA3_256 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_256() { // super("SHA3-256", 2*256, 256/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_384.java // public final class SHA3_384 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_384() { // super("SHA3-384", 2*384, 384/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_512.java // public final class SHA3_512 extends AbstractKeccakMessageDigest { // // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_512() { // super("SHA3-512", 2*512, 512/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // }
import java.security.MessageDigest; import java.security.SecureRandom; import java.security.Security; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import com.github.aelstad.keccakj.cipher.CipherProviderFactory; import com.github.aelstad.keccakj.fips202.SHA3_224; import com.github.aelstad.keccakj.fips202.SHA3_256; import com.github.aelstad.keccakj.fips202.SHA3_384; import com.github.aelstad.keccakj.fips202.SHA3_512;
/* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.provider; public class TestKeccakjProvider { @BeforeClass public static void beforeClass() { Security.addProvider(new KeccakjProvider()); } @Test public void testSha3_224() throws Exception {
// Path: src/main/java/com/github/aelstad/keccakj/cipher/CipherProviderFactory.java // public interface CipherProviderFactory { // public CipherInterface getInstance(String transformation) throws NoSuchAlgorithmException, NoSuchPaddingException; // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_224.java // public final class SHA3_224 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_224() { // super("SHA3-224", 224*2, 224/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_256.java // public final class SHA3_256 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_256() { // super("SHA3-256", 2*256, 256/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_384.java // public final class SHA3_384 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_384() { // super("SHA3-384", 2*384, 384/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_512.java // public final class SHA3_512 extends AbstractKeccakMessageDigest { // // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_512() { // super("SHA3-512", 2*512, 512/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // Path: src/test/java/com/github/aelstad/keccakj/provider/TestKeccakjProvider.java import java.security.MessageDigest; import java.security.SecureRandom; import java.security.Security; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import com.github.aelstad.keccakj.cipher.CipherProviderFactory; import com.github.aelstad.keccakj.fips202.SHA3_224; import com.github.aelstad.keccakj.fips202.SHA3_256; import com.github.aelstad.keccakj.fips202.SHA3_384; import com.github.aelstad.keccakj.fips202.SHA3_512; /* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.provider; public class TestKeccakjProvider { @BeforeClass public static void beforeClass() { Security.addProvider(new KeccakjProvider()); } @Test public void testSha3_224() throws Exception {
Assert.assertTrue(Constants.SHA3_224.equals("SHA3-224"));
aelstad/keccakj
src/test/java/com/github/aelstad/keccakj/provider/TestKeccakjProvider.java
// Path: src/main/java/com/github/aelstad/keccakj/cipher/CipherProviderFactory.java // public interface CipherProviderFactory { // public CipherInterface getInstance(String transformation) throws NoSuchAlgorithmException, NoSuchPaddingException; // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_224.java // public final class SHA3_224 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_224() { // super("SHA3-224", 224*2, 224/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_256.java // public final class SHA3_256 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_256() { // super("SHA3-256", 2*256, 256/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_384.java // public final class SHA3_384 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_384() { // super("SHA3-384", 2*384, 384/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_512.java // public final class SHA3_512 extends AbstractKeccakMessageDigest { // // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_512() { // super("SHA3-512", 2*512, 512/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // }
import java.security.MessageDigest; import java.security.SecureRandom; import java.security.Security; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import com.github.aelstad.keccakj.cipher.CipherProviderFactory; import com.github.aelstad.keccakj.fips202.SHA3_224; import com.github.aelstad.keccakj.fips202.SHA3_256; import com.github.aelstad.keccakj.fips202.SHA3_384; import com.github.aelstad.keccakj.fips202.SHA3_512;
/* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.provider; public class TestKeccakjProvider { @BeforeClass public static void beforeClass() { Security.addProvider(new KeccakjProvider()); } @Test public void testSha3_224() throws Exception { Assert.assertTrue(Constants.SHA3_224.equals("SHA3-224")); Assert.assertTrue(MessageDigest.getInstance(Constants.SHA3_224, Constants.PROVIDER) instanceof SHA3_224); } @Test public void testSha3_256() throws Exception {
// Path: src/main/java/com/github/aelstad/keccakj/cipher/CipherProviderFactory.java // public interface CipherProviderFactory { // public CipherInterface getInstance(String transformation) throws NoSuchAlgorithmException, NoSuchPaddingException; // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_224.java // public final class SHA3_224 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_224() { // super("SHA3-224", 224*2, 224/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_256.java // public final class SHA3_256 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_256() { // super("SHA3-256", 2*256, 256/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_384.java // public final class SHA3_384 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_384() { // super("SHA3-384", 2*384, 384/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_512.java // public final class SHA3_512 extends AbstractKeccakMessageDigest { // // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_512() { // super("SHA3-512", 2*512, 512/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // Path: src/test/java/com/github/aelstad/keccakj/provider/TestKeccakjProvider.java import java.security.MessageDigest; import java.security.SecureRandom; import java.security.Security; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import com.github.aelstad.keccakj.cipher.CipherProviderFactory; import com.github.aelstad.keccakj.fips202.SHA3_224; import com.github.aelstad.keccakj.fips202.SHA3_256; import com.github.aelstad.keccakj.fips202.SHA3_384; import com.github.aelstad.keccakj.fips202.SHA3_512; /* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.provider; public class TestKeccakjProvider { @BeforeClass public static void beforeClass() { Security.addProvider(new KeccakjProvider()); } @Test public void testSha3_224() throws Exception { Assert.assertTrue(Constants.SHA3_224.equals("SHA3-224")); Assert.assertTrue(MessageDigest.getInstance(Constants.SHA3_224, Constants.PROVIDER) instanceof SHA3_224); } @Test public void testSha3_256() throws Exception {
Assert.assertTrue(Constants.SHA3_256.equals("SHA3-256"));
aelstad/keccakj
src/test/java/com/github/aelstad/keccakj/provider/TestKeccakjProvider.java
// Path: src/main/java/com/github/aelstad/keccakj/cipher/CipherProviderFactory.java // public interface CipherProviderFactory { // public CipherInterface getInstance(String transformation) throws NoSuchAlgorithmException, NoSuchPaddingException; // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_224.java // public final class SHA3_224 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_224() { // super("SHA3-224", 224*2, 224/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_256.java // public final class SHA3_256 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_256() { // super("SHA3-256", 2*256, 256/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_384.java // public final class SHA3_384 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_384() { // super("SHA3-384", 2*384, 384/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_512.java // public final class SHA3_512 extends AbstractKeccakMessageDigest { // // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_512() { // super("SHA3-512", 2*512, 512/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // }
import java.security.MessageDigest; import java.security.SecureRandom; import java.security.Security; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import com.github.aelstad.keccakj.cipher.CipherProviderFactory; import com.github.aelstad.keccakj.fips202.SHA3_224; import com.github.aelstad.keccakj.fips202.SHA3_256; import com.github.aelstad.keccakj.fips202.SHA3_384; import com.github.aelstad.keccakj.fips202.SHA3_512;
/* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.provider; public class TestKeccakjProvider { @BeforeClass public static void beforeClass() { Security.addProvider(new KeccakjProvider()); } @Test public void testSha3_224() throws Exception { Assert.assertTrue(Constants.SHA3_224.equals("SHA3-224")); Assert.assertTrue(MessageDigest.getInstance(Constants.SHA3_224, Constants.PROVIDER) instanceof SHA3_224); } @Test public void testSha3_256() throws Exception { Assert.assertTrue(Constants.SHA3_256.equals("SHA3-256")); Assert.assertTrue(MessageDigest.getInstance(Constants.SHA3_256, Constants.PROVIDER) instanceof SHA3_256); } @Test public void testSha3_384() throws Exception {
// Path: src/main/java/com/github/aelstad/keccakj/cipher/CipherProviderFactory.java // public interface CipherProviderFactory { // public CipherInterface getInstance(String transformation) throws NoSuchAlgorithmException, NoSuchPaddingException; // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_224.java // public final class SHA3_224 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_224() { // super("SHA3-224", 224*2, 224/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_256.java // public final class SHA3_256 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_256() { // super("SHA3-256", 2*256, 256/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_384.java // public final class SHA3_384 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_384() { // super("SHA3-384", 2*384, 384/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_512.java // public final class SHA3_512 extends AbstractKeccakMessageDigest { // // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_512() { // super("SHA3-512", 2*512, 512/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // Path: src/test/java/com/github/aelstad/keccakj/provider/TestKeccakjProvider.java import java.security.MessageDigest; import java.security.SecureRandom; import java.security.Security; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import com.github.aelstad.keccakj.cipher.CipherProviderFactory; import com.github.aelstad.keccakj.fips202.SHA3_224; import com.github.aelstad.keccakj.fips202.SHA3_256; import com.github.aelstad.keccakj.fips202.SHA3_384; import com.github.aelstad.keccakj.fips202.SHA3_512; /* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.provider; public class TestKeccakjProvider { @BeforeClass public static void beforeClass() { Security.addProvider(new KeccakjProvider()); } @Test public void testSha3_224() throws Exception { Assert.assertTrue(Constants.SHA3_224.equals("SHA3-224")); Assert.assertTrue(MessageDigest.getInstance(Constants.SHA3_224, Constants.PROVIDER) instanceof SHA3_224); } @Test public void testSha3_256() throws Exception { Assert.assertTrue(Constants.SHA3_256.equals("SHA3-256")); Assert.assertTrue(MessageDigest.getInstance(Constants.SHA3_256, Constants.PROVIDER) instanceof SHA3_256); } @Test public void testSha3_384() throws Exception {
Assert.assertTrue(Constants.SHA3_384.equals("SHA3-384"));
aelstad/keccakj
src/test/java/com/github/aelstad/keccakj/provider/TestKeccakjProvider.java
// Path: src/main/java/com/github/aelstad/keccakj/cipher/CipherProviderFactory.java // public interface CipherProviderFactory { // public CipherInterface getInstance(String transformation) throws NoSuchAlgorithmException, NoSuchPaddingException; // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_224.java // public final class SHA3_224 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_224() { // super("SHA3-224", 224*2, 224/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_256.java // public final class SHA3_256 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_256() { // super("SHA3-256", 2*256, 256/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_384.java // public final class SHA3_384 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_384() { // super("SHA3-384", 2*384, 384/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_512.java // public final class SHA3_512 extends AbstractKeccakMessageDigest { // // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_512() { // super("SHA3-512", 2*512, 512/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // }
import java.security.MessageDigest; import java.security.SecureRandom; import java.security.Security; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import com.github.aelstad.keccakj.cipher.CipherProviderFactory; import com.github.aelstad.keccakj.fips202.SHA3_224; import com.github.aelstad.keccakj.fips202.SHA3_256; import com.github.aelstad.keccakj.fips202.SHA3_384; import com.github.aelstad.keccakj.fips202.SHA3_512;
/* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.provider; public class TestKeccakjProvider { @BeforeClass public static void beforeClass() { Security.addProvider(new KeccakjProvider()); } @Test public void testSha3_224() throws Exception { Assert.assertTrue(Constants.SHA3_224.equals("SHA3-224")); Assert.assertTrue(MessageDigest.getInstance(Constants.SHA3_224, Constants.PROVIDER) instanceof SHA3_224); } @Test public void testSha3_256() throws Exception { Assert.assertTrue(Constants.SHA3_256.equals("SHA3-256")); Assert.assertTrue(MessageDigest.getInstance(Constants.SHA3_256, Constants.PROVIDER) instanceof SHA3_256); } @Test public void testSha3_384() throws Exception { Assert.assertTrue(Constants.SHA3_384.equals("SHA3-384")); Assert.assertTrue(MessageDigest.getInstance(Constants.SHA3_384, Constants.PROVIDER) instanceof SHA3_384); } @Test public void testSha3_512() throws Exception {
// Path: src/main/java/com/github/aelstad/keccakj/cipher/CipherProviderFactory.java // public interface CipherProviderFactory { // public CipherInterface getInstance(String transformation) throws NoSuchAlgorithmException, NoSuchPaddingException; // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_224.java // public final class SHA3_224 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_224() { // super("SHA3-224", 224*2, 224/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_256.java // public final class SHA3_256 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_256() { // super("SHA3-256", 2*256, 256/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_384.java // public final class SHA3_384 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_384() { // super("SHA3-384", 2*384, 384/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_512.java // public final class SHA3_512 extends AbstractKeccakMessageDigest { // // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_512() { // super("SHA3-512", 2*512, 512/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // Path: src/test/java/com/github/aelstad/keccakj/provider/TestKeccakjProvider.java import java.security.MessageDigest; import java.security.SecureRandom; import java.security.Security; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import com.github.aelstad.keccakj.cipher.CipherProviderFactory; import com.github.aelstad.keccakj.fips202.SHA3_224; import com.github.aelstad.keccakj.fips202.SHA3_256; import com.github.aelstad.keccakj.fips202.SHA3_384; import com.github.aelstad.keccakj.fips202.SHA3_512; /* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.provider; public class TestKeccakjProvider { @BeforeClass public static void beforeClass() { Security.addProvider(new KeccakjProvider()); } @Test public void testSha3_224() throws Exception { Assert.assertTrue(Constants.SHA3_224.equals("SHA3-224")); Assert.assertTrue(MessageDigest.getInstance(Constants.SHA3_224, Constants.PROVIDER) instanceof SHA3_224); } @Test public void testSha3_256() throws Exception { Assert.assertTrue(Constants.SHA3_256.equals("SHA3-256")); Assert.assertTrue(MessageDigest.getInstance(Constants.SHA3_256, Constants.PROVIDER) instanceof SHA3_256); } @Test public void testSha3_384() throws Exception { Assert.assertTrue(Constants.SHA3_384.equals("SHA3-384")); Assert.assertTrue(MessageDigest.getInstance(Constants.SHA3_384, Constants.PROVIDER) instanceof SHA3_384); } @Test public void testSha3_512() throws Exception {
Assert.assertTrue(Constants.SHA3_512.equals("SHA3-512"));
aelstad/keccakj
src/test/java/com/github/aelstad/keccakj/provider/TestKeccakjProvider.java
// Path: src/main/java/com/github/aelstad/keccakj/cipher/CipherProviderFactory.java // public interface CipherProviderFactory { // public CipherInterface getInstance(String transformation) throws NoSuchAlgorithmException, NoSuchPaddingException; // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_224.java // public final class SHA3_224 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_224() { // super("SHA3-224", 224*2, 224/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_256.java // public final class SHA3_256 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_256() { // super("SHA3-256", 2*256, 256/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_384.java // public final class SHA3_384 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_384() { // super("SHA3-384", 2*384, 384/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_512.java // public final class SHA3_512 extends AbstractKeccakMessageDigest { // // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_512() { // super("SHA3-512", 2*512, 512/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // }
import java.security.MessageDigest; import java.security.SecureRandom; import java.security.Security; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import com.github.aelstad.keccakj.cipher.CipherProviderFactory; import com.github.aelstad.keccakj.fips202.SHA3_224; import com.github.aelstad.keccakj.fips202.SHA3_256; import com.github.aelstad.keccakj.fips202.SHA3_384; import com.github.aelstad.keccakj.fips202.SHA3_512;
Assert.assertTrue(MessageDigest.getInstance(Constants.SHA3_256, Constants.PROVIDER) instanceof SHA3_256); } @Test public void testSha3_384() throws Exception { Assert.assertTrue(Constants.SHA3_384.equals("SHA3-384")); Assert.assertTrue(MessageDigest.getInstance(Constants.SHA3_384, Constants.PROVIDER) instanceof SHA3_384); } @Test public void testSha3_512() throws Exception { Assert.assertTrue(Constants.SHA3_512.equals("SHA3-512")); Assert.assertTrue(MessageDigest.getInstance(Constants.SHA3_512, Constants.PROVIDER) instanceof SHA3_512); } @Test public void testKeccackRnd128() throws Exception { Assert.assertNotNull(SecureRandom.getInstance(Constants.KECCAK_RND128, Constants.PROVIDER)); } @Test public void testKeccackRnd256() throws Exception { Assert.assertNotNull(SecureRandom.getInstance(Constants.KECCAK_RND256, Constants.PROVIDER)); byte[] buf = new byte[1024]; SecureRandom.getInstance(Constants.KECCAK_RND256, Constants.PROVIDER).nextBytes(buf); } @Test public void testShake128StreamCipher() throws Exception {
// Path: src/main/java/com/github/aelstad/keccakj/cipher/CipherProviderFactory.java // public interface CipherProviderFactory { // public CipherInterface getInstance(String transformation) throws NoSuchAlgorithmException, NoSuchPaddingException; // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_224.java // public final class SHA3_224 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_224() { // super("SHA3-224", 224*2, 224/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_256.java // public final class SHA3_256 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_256() { // super("SHA3-256", 2*256, 256/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_384.java // public final class SHA3_384 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_384() { // super("SHA3-384", 2*384, 384/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // } // // Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_512.java // public final class SHA3_512 extends AbstractKeccakMessageDigest { // // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_512() { // super("SHA3-512", 2*512, 512/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // Path: src/test/java/com/github/aelstad/keccakj/provider/TestKeccakjProvider.java import java.security.MessageDigest; import java.security.SecureRandom; import java.security.Security; import org.junit.Assert; import org.junit.BeforeClass; import org.junit.Test; import com.github.aelstad.keccakj.cipher.CipherProviderFactory; import com.github.aelstad.keccakj.fips202.SHA3_224; import com.github.aelstad.keccakj.fips202.SHA3_256; import com.github.aelstad.keccakj.fips202.SHA3_384; import com.github.aelstad.keccakj.fips202.SHA3_512; Assert.assertTrue(MessageDigest.getInstance(Constants.SHA3_256, Constants.PROVIDER) instanceof SHA3_256); } @Test public void testSha3_384() throws Exception { Assert.assertTrue(Constants.SHA3_384.equals("SHA3-384")); Assert.assertTrue(MessageDigest.getInstance(Constants.SHA3_384, Constants.PROVIDER) instanceof SHA3_384); } @Test public void testSha3_512() throws Exception { Assert.assertTrue(Constants.SHA3_512.equals("SHA3-512")); Assert.assertTrue(MessageDigest.getInstance(Constants.SHA3_512, Constants.PROVIDER) instanceof SHA3_512); } @Test public void testKeccackRnd128() throws Exception { Assert.assertNotNull(SecureRandom.getInstance(Constants.KECCAK_RND128, Constants.PROVIDER)); } @Test public void testKeccackRnd256() throws Exception { Assert.assertNotNull(SecureRandom.getInstance(Constants.KECCAK_RND256, Constants.PROVIDER)); byte[] buf = new byte[1024]; SecureRandom.getInstance(Constants.KECCAK_RND256, Constants.PROVIDER).nextBytes(buf); } @Test public void testShake128StreamCipher() throws Exception {
CipherProviderFactory cpf = (CipherProviderFactory) Security.getProvider(Constants.PROVIDER);
aelstad/keccakj
src/test/java/com/github/aelstad/keccakj/fips202/TestShake256.java
// Path: src/main/java/com/github/aelstad/keccakj/fips202/Shake256.java // public class Shake256 extends KeccakSponge{ // private final static byte DOMAIN_PADDING = 0xf; // private final static int DOMMAIN_PADDING_LENGTH = 4; // // public Shake256() { // super(512, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // }
import java.io.InputStream; import java.util.List; import org.junit.Test; import com.github.aelstad.keccakj.fips202.Shake256;
/* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.fips202; public class TestShake256 { @Test public void checkTestVectors() throws Exception { InputStream is = KeccakDigestTestUtils.getResourceStreamInPackage(getClass(), "ShortMsgKAT_SHAKE256.txt"); KeccakDigestTestUtils kdtu = new KeccakDigestTestUtils(); List<KeccakDigestTestUtils.DigestTest> tests = kdtu.parseTests(is);
// Path: src/main/java/com/github/aelstad/keccakj/fips202/Shake256.java // public class Shake256 extends KeccakSponge{ // private final static byte DOMAIN_PADDING = 0xf; // private final static int DOMMAIN_PADDING_LENGTH = 4; // // public Shake256() { // super(512, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // Path: src/test/java/com/github/aelstad/keccakj/fips202/TestShake256.java import java.io.InputStream; import java.util.List; import org.junit.Test; import com.github.aelstad.keccakj.fips202.Shake256; /* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.fips202; public class TestShake256 { @Test public void checkTestVectors() throws Exception { InputStream is = KeccakDigestTestUtils.getResourceStreamInPackage(getClass(), "ShortMsgKAT_SHAKE256.txt"); KeccakDigestTestUtils kdtu = new KeccakDigestTestUtils(); List<KeccakDigestTestUtils.DigestTest> tests = kdtu.parseTests(is);
Shake256 shake = new Shake256();
aelstad/keccakj
src/test/java/com/github/aelstad/keccakj/fips202/TestSHA3_384.java
// Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_384.java // public final class SHA3_384 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_384() { // super("SHA3-384", 2*384, 384/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // }
import java.io.InputStream; import java.util.List; import org.junit.Test; import com.github.aelstad.keccakj.fips202.SHA3_384;
/* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.fips202; public class TestSHA3_384 { @Test public void checkTestVectors() throws Exception { InputStream is = KeccakDigestTestUtils.getResourceStreamInPackage(getClass(), "ShortMsgKAT_SHA3-384.txt"); KeccakDigestTestUtils kdtu = new KeccakDigestTestUtils(); List<KeccakDigestTestUtils.DigestTest> tests = kdtu.parseTests(is);
// Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_384.java // public final class SHA3_384 extends AbstractKeccakMessageDigest { // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_384() { // super("SHA3-384", 2*384, 384/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // } // Path: src/test/java/com/github/aelstad/keccakj/fips202/TestSHA3_384.java import java.io.InputStream; import java.util.List; import org.junit.Test; import com.github.aelstad.keccakj.fips202.SHA3_384; /* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.fips202; public class TestSHA3_384 { @Test public void checkTestVectors() throws Exception { InputStream is = KeccakDigestTestUtils.getResourceStreamInPackage(getClass(), "ShortMsgKAT_SHA3-384.txt"); KeccakDigestTestUtils kdtu = new KeccakDigestTestUtils(); List<KeccakDigestTestUtils.DigestTest> tests = kdtu.parseTests(is);
SHA3_384 sha = new SHA3_384();
aelstad/keccakj
src/main/java/com/github/aelstad/keccakj/spi/Shake256Key.java
// Path: src/main/java/com/github/aelstad/keccakj/provider/Constants.java // public class Constants { // public static final String PROVIDER = "com.github.aelstad.keccakj"; // // public static final String SHA3_224 = "SHA3-224"; // public static final String SHA3_256 = "SHA3-256"; // public static final String SHA3_384 = "SHA3-384"; // public static final String SHA3_512 = "SHA3-512"; // // public static final String KECCAK_RND128 = "KECCAK-RND-128"; // public static final String KECCAK_RND256 = "KECCAK-RND-256"; // // public static final String SHAKE128_STREAM_CIPHER = "SHAKE128"; // public static final String SHAKE256_STREAM_CIPHER = "SHAKE256"; // // public static final String LAKEKEYAK_AUTHENTICATING_STREAM_CIPHER = "LAKE-KEYAK"; // }
import com.github.aelstad.keccakj.provider.Constants;
/* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.spi; public class Shake256Key extends RawKey { @Override public String getAlgorithm() {
// Path: src/main/java/com/github/aelstad/keccakj/provider/Constants.java // public class Constants { // public static final String PROVIDER = "com.github.aelstad.keccakj"; // // public static final String SHA3_224 = "SHA3-224"; // public static final String SHA3_256 = "SHA3-256"; // public static final String SHA3_384 = "SHA3-384"; // public static final String SHA3_512 = "SHA3-512"; // // public static final String KECCAK_RND128 = "KECCAK-RND-128"; // public static final String KECCAK_RND256 = "KECCAK-RND-256"; // // public static final String SHAKE128_STREAM_CIPHER = "SHAKE128"; // public static final String SHAKE256_STREAM_CIPHER = "SHAKE256"; // // public static final String LAKEKEYAK_AUTHENTICATING_STREAM_CIPHER = "LAKE-KEYAK"; // } // Path: src/main/java/com/github/aelstad/keccakj/spi/Shake256Key.java import com.github.aelstad.keccakj.provider.Constants; /* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.spi; public class Shake256Key extends RawKey { @Override public String getAlgorithm() {
return Constants.SHAKE256_STREAM_CIPHER;
aelstad/keccakj
src/main/java/com/github/aelstad/keccakj/core/KeccakSponge.java
// Path: src/main/java/com/github/aelstad/keccakj/core/KeccakStateUtils.java // public enum StateOp { // ZERO, GET, VALIDATE, XOR_IN, XOR_TRANSFORM, WRAP, UNWRAP; // // public boolean isIn() { // return (this ==StateOp.XOR_IN || this == XOR_TRANSFORM || this ==StateOp.WRAP || this == StateOp.UNWRAP || this == VALIDATE); // } // // public boolean isOut() { // return (this == StateOp.GET || this == XOR_TRANSFORM || this==StateOp.WRAP || this == StateOp.UNWRAP); // } // // }; // // Path: src/main/java/com/github/aelstad/keccakj/io/BitInputStream.java // public abstract class BitInputStream extends InputStream { // @Override // public abstract void close(); // // // @Override // public int read(byte[] b, int off, int len) { // return (int) (readBits(b, ((long)off)<<3, ((long)len)<<3)>>3); // } // // /** // * Transform input to output with the input stream as a keystream // * // * @param input Input byte-array // * @param inputOff Input offset // * @param output Output byte-array // * @param outputOff Output offset // * @param len length in bytes // * @return Number of bytes transformed // */ // public int transform(byte[] input, int inputOff, byte[] output, int outputOff, int len) { // return (int) (transformBits(input, ((long)inputOff)<<3, output, ((long)outputOff)<<3, ((long)len)<<3)>>3); // } // // // @Override // public int read(byte[] b) { // return this.read(b, 0, b.length)>>3; // } // // /** // * Transform input to output using the input stream as a keystream // * // * @param input Input byte array // * @param output Output byte array // * // * @return Number of bytes transformed // */ // public int transform(byte[] input, byte[] output) { // return (int) (transformBits(input, 0l, output, 0l, ((long)input.length)<<3)>>3); // } // // // @Override // public int read() { // byte[] buf = new byte[1]; // readBits(buf, 0, 8); // // return ((int) buf[0]) & 0xff; // } // // // public abstract long readBits(byte[] arg, long bitOff, long bitLen); // // /** // * Transform input to output using the input stream as a keystream // * // * @param input Input byte array // * @param inputOff Input offset in bits // * @param output Output byte array // * @param outputOff Output offset in bits // * @param bitLen Number of bits // * @return Number of bits transformed // */ // public abstract long transformBits(byte[] input, long inputOff, byte[] output, long outputOff, long bitLen); // } // // Path: src/main/java/com/github/aelstad/keccakj/io/BitOutputStream.java // public abstract class BitOutputStream extends OutputStream { // // @Override // public abstract void close(); // // @Override // public void write(byte[] b, int off, int len) { // writeBits(b, ((long) (off))<<3, ((long)len)<<3); // } // // @Override // public void write(byte[] b) { // write(b, 0, b.length); // } // // @Override // public void write(int b) { // writeBits(new byte[] { (byte) b }, 0, 8); // } // // public abstract void writeBits(byte[] arg, long bitOff, long bitLen); // // }
import java.io.FilterOutputStream; import java.io.IOException; import java.util.Arrays; import com.github.aelstad.keccakj.core.KeccakStateUtils.StateOp; import com.github.aelstad.keccakj.io.BitInputStream; import com.github.aelstad.keccakj.io.BitOutputStream;
/* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.core; public class KeccakSponge { Keccak1600 keccak1600; int domainPaddingBitLength; byte domainPadding; private int ratePos; SqueezeStream squeezeStream; AbsorbStream absorbStream;
// Path: src/main/java/com/github/aelstad/keccakj/core/KeccakStateUtils.java // public enum StateOp { // ZERO, GET, VALIDATE, XOR_IN, XOR_TRANSFORM, WRAP, UNWRAP; // // public boolean isIn() { // return (this ==StateOp.XOR_IN || this == XOR_TRANSFORM || this ==StateOp.WRAP || this == StateOp.UNWRAP || this == VALIDATE); // } // // public boolean isOut() { // return (this == StateOp.GET || this == XOR_TRANSFORM || this==StateOp.WRAP || this == StateOp.UNWRAP); // } // // }; // // Path: src/main/java/com/github/aelstad/keccakj/io/BitInputStream.java // public abstract class BitInputStream extends InputStream { // @Override // public abstract void close(); // // // @Override // public int read(byte[] b, int off, int len) { // return (int) (readBits(b, ((long)off)<<3, ((long)len)<<3)>>3); // } // // /** // * Transform input to output with the input stream as a keystream // * // * @param input Input byte-array // * @param inputOff Input offset // * @param output Output byte-array // * @param outputOff Output offset // * @param len length in bytes // * @return Number of bytes transformed // */ // public int transform(byte[] input, int inputOff, byte[] output, int outputOff, int len) { // return (int) (transformBits(input, ((long)inputOff)<<3, output, ((long)outputOff)<<3, ((long)len)<<3)>>3); // } // // // @Override // public int read(byte[] b) { // return this.read(b, 0, b.length)>>3; // } // // /** // * Transform input to output using the input stream as a keystream // * // * @param input Input byte array // * @param output Output byte array // * // * @return Number of bytes transformed // */ // public int transform(byte[] input, byte[] output) { // return (int) (transformBits(input, 0l, output, 0l, ((long)input.length)<<3)>>3); // } // // // @Override // public int read() { // byte[] buf = new byte[1]; // readBits(buf, 0, 8); // // return ((int) buf[0]) & 0xff; // } // // // public abstract long readBits(byte[] arg, long bitOff, long bitLen); // // /** // * Transform input to output using the input stream as a keystream // * // * @param input Input byte array // * @param inputOff Input offset in bits // * @param output Output byte array // * @param outputOff Output offset in bits // * @param bitLen Number of bits // * @return Number of bits transformed // */ // public abstract long transformBits(byte[] input, long inputOff, byte[] output, long outputOff, long bitLen); // } // // Path: src/main/java/com/github/aelstad/keccakj/io/BitOutputStream.java // public abstract class BitOutputStream extends OutputStream { // // @Override // public abstract void close(); // // @Override // public void write(byte[] b, int off, int len) { // writeBits(b, ((long) (off))<<3, ((long)len)<<3); // } // // @Override // public void write(byte[] b) { // write(b, 0, b.length); // } // // @Override // public void write(int b) { // writeBits(new byte[] { (byte) b }, 0, 8); // } // // public abstract void writeBits(byte[] arg, long bitOff, long bitLen); // // } // Path: src/main/java/com/github/aelstad/keccakj/core/KeccakSponge.java import java.io.FilterOutputStream; import java.io.IOException; import java.util.Arrays; import com.github.aelstad.keccakj.core.KeccakStateUtils.StateOp; import com.github.aelstad.keccakj.io.BitInputStream; import com.github.aelstad.keccakj.io.BitOutputStream; /* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.core; public class KeccakSponge { Keccak1600 keccak1600; int domainPaddingBitLength; byte domainPadding; private int ratePos; SqueezeStream squeezeStream; AbsorbStream absorbStream;
private final class SqueezeStream extends BitInputStream {
aelstad/keccakj
src/main/java/com/github/aelstad/keccakj/core/KeccakSponge.java
// Path: src/main/java/com/github/aelstad/keccakj/core/KeccakStateUtils.java // public enum StateOp { // ZERO, GET, VALIDATE, XOR_IN, XOR_TRANSFORM, WRAP, UNWRAP; // // public boolean isIn() { // return (this ==StateOp.XOR_IN || this == XOR_TRANSFORM || this ==StateOp.WRAP || this == StateOp.UNWRAP || this == VALIDATE); // } // // public boolean isOut() { // return (this == StateOp.GET || this == XOR_TRANSFORM || this==StateOp.WRAP || this == StateOp.UNWRAP); // } // // }; // // Path: src/main/java/com/github/aelstad/keccakj/io/BitInputStream.java // public abstract class BitInputStream extends InputStream { // @Override // public abstract void close(); // // // @Override // public int read(byte[] b, int off, int len) { // return (int) (readBits(b, ((long)off)<<3, ((long)len)<<3)>>3); // } // // /** // * Transform input to output with the input stream as a keystream // * // * @param input Input byte-array // * @param inputOff Input offset // * @param output Output byte-array // * @param outputOff Output offset // * @param len length in bytes // * @return Number of bytes transformed // */ // public int transform(byte[] input, int inputOff, byte[] output, int outputOff, int len) { // return (int) (transformBits(input, ((long)inputOff)<<3, output, ((long)outputOff)<<3, ((long)len)<<3)>>3); // } // // // @Override // public int read(byte[] b) { // return this.read(b, 0, b.length)>>3; // } // // /** // * Transform input to output using the input stream as a keystream // * // * @param input Input byte array // * @param output Output byte array // * // * @return Number of bytes transformed // */ // public int transform(byte[] input, byte[] output) { // return (int) (transformBits(input, 0l, output, 0l, ((long)input.length)<<3)>>3); // } // // // @Override // public int read() { // byte[] buf = new byte[1]; // readBits(buf, 0, 8); // // return ((int) buf[0]) & 0xff; // } // // // public abstract long readBits(byte[] arg, long bitOff, long bitLen); // // /** // * Transform input to output using the input stream as a keystream // * // * @param input Input byte array // * @param inputOff Input offset in bits // * @param output Output byte array // * @param outputOff Output offset in bits // * @param bitLen Number of bits // * @return Number of bits transformed // */ // public abstract long transformBits(byte[] input, long inputOff, byte[] output, long outputOff, long bitLen); // } // // Path: src/main/java/com/github/aelstad/keccakj/io/BitOutputStream.java // public abstract class BitOutputStream extends OutputStream { // // @Override // public abstract void close(); // // @Override // public void write(byte[] b, int off, int len) { // writeBits(b, ((long) (off))<<3, ((long)len)<<3); // } // // @Override // public void write(byte[] b) { // write(b, 0, b.length); // } // // @Override // public void write(int b) { // writeBits(new byte[] { (byte) b }, 0, 8); // } // // public abstract void writeBits(byte[] arg, long bitOff, long bitLen); // // }
import java.io.FilterOutputStream; import java.io.IOException; import java.util.Arrays; import com.github.aelstad.keccakj.core.KeccakStateUtils.StateOp; import com.github.aelstad.keccakj.io.BitInputStream; import com.github.aelstad.keccakj.io.BitOutputStream;
int chunk = (int) Math.min(bitLen, remainingBits); if((ratePos & 7)==0 && (bitOff&7)==0 && (chunk&7)==0) { keccak1600.getBytes(ratePos>>3, bits, (int) (bitOff>>3), chunk>>3); } else { keccak1600.getBits(ratePos, bits, bitOff, chunk); } ratePos += chunk; bitLen -= chunk; bitOff += chunk; rv += chunk; } return rv; } @Override public long transformBits(byte[] input, long inputOff, byte[] output, long outputOff, long bitLen) { long rv = 0; while(bitLen > 0) { int remainingBits = keccak1600.remainingBits(ratePos); if(remainingBits <= 0) { keccak1600.permute(); ratePos = 0; remainingBits = keccak1600.remainingBits(ratePos); } int chunk = (int) Math.min(bitLen, remainingBits); if((ratePos & 7)==0 && (inputOff&7)==0 && (outputOff&7)==0 && (chunk&7)==0) {
// Path: src/main/java/com/github/aelstad/keccakj/core/KeccakStateUtils.java // public enum StateOp { // ZERO, GET, VALIDATE, XOR_IN, XOR_TRANSFORM, WRAP, UNWRAP; // // public boolean isIn() { // return (this ==StateOp.XOR_IN || this == XOR_TRANSFORM || this ==StateOp.WRAP || this == StateOp.UNWRAP || this == VALIDATE); // } // // public boolean isOut() { // return (this == StateOp.GET || this == XOR_TRANSFORM || this==StateOp.WRAP || this == StateOp.UNWRAP); // } // // }; // // Path: src/main/java/com/github/aelstad/keccakj/io/BitInputStream.java // public abstract class BitInputStream extends InputStream { // @Override // public abstract void close(); // // // @Override // public int read(byte[] b, int off, int len) { // return (int) (readBits(b, ((long)off)<<3, ((long)len)<<3)>>3); // } // // /** // * Transform input to output with the input stream as a keystream // * // * @param input Input byte-array // * @param inputOff Input offset // * @param output Output byte-array // * @param outputOff Output offset // * @param len length in bytes // * @return Number of bytes transformed // */ // public int transform(byte[] input, int inputOff, byte[] output, int outputOff, int len) { // return (int) (transformBits(input, ((long)inputOff)<<3, output, ((long)outputOff)<<3, ((long)len)<<3)>>3); // } // // // @Override // public int read(byte[] b) { // return this.read(b, 0, b.length)>>3; // } // // /** // * Transform input to output using the input stream as a keystream // * // * @param input Input byte array // * @param output Output byte array // * // * @return Number of bytes transformed // */ // public int transform(byte[] input, byte[] output) { // return (int) (transformBits(input, 0l, output, 0l, ((long)input.length)<<3)>>3); // } // // // @Override // public int read() { // byte[] buf = new byte[1]; // readBits(buf, 0, 8); // // return ((int) buf[0]) & 0xff; // } // // // public abstract long readBits(byte[] arg, long bitOff, long bitLen); // // /** // * Transform input to output using the input stream as a keystream // * // * @param input Input byte array // * @param inputOff Input offset in bits // * @param output Output byte array // * @param outputOff Output offset in bits // * @param bitLen Number of bits // * @return Number of bits transformed // */ // public abstract long transformBits(byte[] input, long inputOff, byte[] output, long outputOff, long bitLen); // } // // Path: src/main/java/com/github/aelstad/keccakj/io/BitOutputStream.java // public abstract class BitOutputStream extends OutputStream { // // @Override // public abstract void close(); // // @Override // public void write(byte[] b, int off, int len) { // writeBits(b, ((long) (off))<<3, ((long)len)<<3); // } // // @Override // public void write(byte[] b) { // write(b, 0, b.length); // } // // @Override // public void write(int b) { // writeBits(new byte[] { (byte) b }, 0, 8); // } // // public abstract void writeBits(byte[] arg, long bitOff, long bitLen); // // } // Path: src/main/java/com/github/aelstad/keccakj/core/KeccakSponge.java import java.io.FilterOutputStream; import java.io.IOException; import java.util.Arrays; import com.github.aelstad.keccakj.core.KeccakStateUtils.StateOp; import com.github.aelstad.keccakj.io.BitInputStream; import com.github.aelstad.keccakj.io.BitOutputStream; int chunk = (int) Math.min(bitLen, remainingBits); if((ratePos & 7)==0 && (bitOff&7)==0 && (chunk&7)==0) { keccak1600.getBytes(ratePos>>3, bits, (int) (bitOff>>3), chunk>>3); } else { keccak1600.getBits(ratePos, bits, bitOff, chunk); } ratePos += chunk; bitLen -= chunk; bitOff += chunk; rv += chunk; } return rv; } @Override public long transformBits(byte[] input, long inputOff, byte[] output, long outputOff, long bitLen) { long rv = 0; while(bitLen > 0) { int remainingBits = keccak1600.remainingBits(ratePos); if(remainingBits <= 0) { keccak1600.permute(); ratePos = 0; remainingBits = keccak1600.remainingBits(ratePos); } int chunk = (int) Math.min(bitLen, remainingBits); if((ratePos & 7)==0 && (inputOff&7)==0 && (outputOff&7)==0 && (chunk&7)==0) {
keccak1600.bytesOp(StateOp.XOR_TRANSFORM, ratePos>>3, output, (int) (outputOff>>3), input, (int) (inputOff>>3), chunk>>3);
aelstad/keccakj
src/main/java/com/github/aelstad/keccakj/core/KeccakSponge.java
// Path: src/main/java/com/github/aelstad/keccakj/core/KeccakStateUtils.java // public enum StateOp { // ZERO, GET, VALIDATE, XOR_IN, XOR_TRANSFORM, WRAP, UNWRAP; // // public boolean isIn() { // return (this ==StateOp.XOR_IN || this == XOR_TRANSFORM || this ==StateOp.WRAP || this == StateOp.UNWRAP || this == VALIDATE); // } // // public boolean isOut() { // return (this == StateOp.GET || this == XOR_TRANSFORM || this==StateOp.WRAP || this == StateOp.UNWRAP); // } // // }; // // Path: src/main/java/com/github/aelstad/keccakj/io/BitInputStream.java // public abstract class BitInputStream extends InputStream { // @Override // public abstract void close(); // // // @Override // public int read(byte[] b, int off, int len) { // return (int) (readBits(b, ((long)off)<<3, ((long)len)<<3)>>3); // } // // /** // * Transform input to output with the input stream as a keystream // * // * @param input Input byte-array // * @param inputOff Input offset // * @param output Output byte-array // * @param outputOff Output offset // * @param len length in bytes // * @return Number of bytes transformed // */ // public int transform(byte[] input, int inputOff, byte[] output, int outputOff, int len) { // return (int) (transformBits(input, ((long)inputOff)<<3, output, ((long)outputOff)<<3, ((long)len)<<3)>>3); // } // // // @Override // public int read(byte[] b) { // return this.read(b, 0, b.length)>>3; // } // // /** // * Transform input to output using the input stream as a keystream // * // * @param input Input byte array // * @param output Output byte array // * // * @return Number of bytes transformed // */ // public int transform(byte[] input, byte[] output) { // return (int) (transformBits(input, 0l, output, 0l, ((long)input.length)<<3)>>3); // } // // // @Override // public int read() { // byte[] buf = new byte[1]; // readBits(buf, 0, 8); // // return ((int) buf[0]) & 0xff; // } // // // public abstract long readBits(byte[] arg, long bitOff, long bitLen); // // /** // * Transform input to output using the input stream as a keystream // * // * @param input Input byte array // * @param inputOff Input offset in bits // * @param output Output byte array // * @param outputOff Output offset in bits // * @param bitLen Number of bits // * @return Number of bits transformed // */ // public abstract long transformBits(byte[] input, long inputOff, byte[] output, long outputOff, long bitLen); // } // // Path: src/main/java/com/github/aelstad/keccakj/io/BitOutputStream.java // public abstract class BitOutputStream extends OutputStream { // // @Override // public abstract void close(); // // @Override // public void write(byte[] b, int off, int len) { // writeBits(b, ((long) (off))<<3, ((long)len)<<3); // } // // @Override // public void write(byte[] b) { // write(b, 0, b.length); // } // // @Override // public void write(int b) { // writeBits(new byte[] { (byte) b }, 0, 8); // } // // public abstract void writeBits(byte[] arg, long bitOff, long bitLen); // // }
import java.io.FilterOutputStream; import java.io.IOException; import java.util.Arrays; import com.github.aelstad.keccakj.core.KeccakStateUtils.StateOp; import com.github.aelstad.keccakj.io.BitInputStream; import com.github.aelstad.keccakj.io.BitOutputStream;
} @Override public long transformBits(byte[] input, long inputOff, byte[] output, long outputOff, long bitLen) { long rv = 0; while(bitLen > 0) { int remainingBits = keccak1600.remainingBits(ratePos); if(remainingBits <= 0) { keccak1600.permute(); ratePos = 0; remainingBits = keccak1600.remainingBits(ratePos); } int chunk = (int) Math.min(bitLen, remainingBits); if((ratePos & 7)==0 && (inputOff&7)==0 && (outputOff&7)==0 && (chunk&7)==0) { keccak1600.bytesOp(StateOp.XOR_TRANSFORM, ratePos>>3, output, (int) (outputOff>>3), input, (int) (inputOff>>3), chunk>>3); } else { keccak1600.bitsOp(StateOp.XOR_TRANSFORM, ratePos, output, outputOff, input, inputOff, chunk); } ratePos += chunk; bitLen -= chunk; inputOff += chunk; outputOff += chunk; rv += chunk; } return rv; } }
// Path: src/main/java/com/github/aelstad/keccakj/core/KeccakStateUtils.java // public enum StateOp { // ZERO, GET, VALIDATE, XOR_IN, XOR_TRANSFORM, WRAP, UNWRAP; // // public boolean isIn() { // return (this ==StateOp.XOR_IN || this == XOR_TRANSFORM || this ==StateOp.WRAP || this == StateOp.UNWRAP || this == VALIDATE); // } // // public boolean isOut() { // return (this == StateOp.GET || this == XOR_TRANSFORM || this==StateOp.WRAP || this == StateOp.UNWRAP); // } // // }; // // Path: src/main/java/com/github/aelstad/keccakj/io/BitInputStream.java // public abstract class BitInputStream extends InputStream { // @Override // public abstract void close(); // // // @Override // public int read(byte[] b, int off, int len) { // return (int) (readBits(b, ((long)off)<<3, ((long)len)<<3)>>3); // } // // /** // * Transform input to output with the input stream as a keystream // * // * @param input Input byte-array // * @param inputOff Input offset // * @param output Output byte-array // * @param outputOff Output offset // * @param len length in bytes // * @return Number of bytes transformed // */ // public int transform(byte[] input, int inputOff, byte[] output, int outputOff, int len) { // return (int) (transformBits(input, ((long)inputOff)<<3, output, ((long)outputOff)<<3, ((long)len)<<3)>>3); // } // // // @Override // public int read(byte[] b) { // return this.read(b, 0, b.length)>>3; // } // // /** // * Transform input to output using the input stream as a keystream // * // * @param input Input byte array // * @param output Output byte array // * // * @return Number of bytes transformed // */ // public int transform(byte[] input, byte[] output) { // return (int) (transformBits(input, 0l, output, 0l, ((long)input.length)<<3)>>3); // } // // // @Override // public int read() { // byte[] buf = new byte[1]; // readBits(buf, 0, 8); // // return ((int) buf[0]) & 0xff; // } // // // public abstract long readBits(byte[] arg, long bitOff, long bitLen); // // /** // * Transform input to output using the input stream as a keystream // * // * @param input Input byte array // * @param inputOff Input offset in bits // * @param output Output byte array // * @param outputOff Output offset in bits // * @param bitLen Number of bits // * @return Number of bits transformed // */ // public abstract long transformBits(byte[] input, long inputOff, byte[] output, long outputOff, long bitLen); // } // // Path: src/main/java/com/github/aelstad/keccakj/io/BitOutputStream.java // public abstract class BitOutputStream extends OutputStream { // // @Override // public abstract void close(); // // @Override // public void write(byte[] b, int off, int len) { // writeBits(b, ((long) (off))<<3, ((long)len)<<3); // } // // @Override // public void write(byte[] b) { // write(b, 0, b.length); // } // // @Override // public void write(int b) { // writeBits(new byte[] { (byte) b }, 0, 8); // } // // public abstract void writeBits(byte[] arg, long bitOff, long bitLen); // // } // Path: src/main/java/com/github/aelstad/keccakj/core/KeccakSponge.java import java.io.FilterOutputStream; import java.io.IOException; import java.util.Arrays; import com.github.aelstad.keccakj.core.KeccakStateUtils.StateOp; import com.github.aelstad.keccakj.io.BitInputStream; import com.github.aelstad.keccakj.io.BitOutputStream; } @Override public long transformBits(byte[] input, long inputOff, byte[] output, long outputOff, long bitLen) { long rv = 0; while(bitLen > 0) { int remainingBits = keccak1600.remainingBits(ratePos); if(remainingBits <= 0) { keccak1600.permute(); ratePos = 0; remainingBits = keccak1600.remainingBits(ratePos); } int chunk = (int) Math.min(bitLen, remainingBits); if((ratePos & 7)==0 && (inputOff&7)==0 && (outputOff&7)==0 && (chunk&7)==0) { keccak1600.bytesOp(StateOp.XOR_TRANSFORM, ratePos>>3, output, (int) (outputOff>>3), input, (int) (inputOff>>3), chunk>>3); } else { keccak1600.bitsOp(StateOp.XOR_TRANSFORM, ratePos, output, outputOff, input, inputOff, chunk); } ratePos += chunk; bitLen -= chunk; inputOff += chunk; outputOff += chunk; rv += chunk; } return rv; } }
private final class AbsorbStream extends BitOutputStream {
aelstad/keccakj
src/test/java/com/github/aelstad/keccakj/fips202/TestStreamEncryption.java
// Path: src/main/java/com/github/aelstad/keccakj/fips202/Shake128.java // public final class Shake128 extends KeccakSponge { // private final static byte DOMAIN_PADDING = 0xf; // private final static int DOMMAIN_PADDING_LENGTH = 4; // // public Shake128() { // super(256, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // // // } // // Path: src/main/java/com/github/aelstad/keccakj/spi/Shake128Key.java // public class Shake128Key extends RawKey { // // @Override // public String getAlgorithm() { // return Constants.SHAKE128_STREAM_CIPHER; // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/spi/Shake128StreamCipher.java // public final class Shake128StreamCipher extends AbstractSpongeStreamCipher { // private Shake128 sponge; // // @Override // KeccakSponge getSponge() { // if(sponge == null) { // sponge = new Shake128(); // } // return sponge; // } // // }
import java.io.ByteArrayOutputStream; import java.io.FilterOutputStream; import java.io.IOException; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.SecureRandom; import java.util.Arrays; import java.util.Random; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.IvParameterSpec; import org.junit.Assert; import org.junit.Test; import com.github.aelstad.keccakj.fips202.Shake128; import com.github.aelstad.keccakj.spi.Shake128Key; import com.github.aelstad.keccakj.spi.Shake128StreamCipher;
/* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.fips202; /** * Demonstrates stream encryption/decryption */ public class TestStreamEncryption { @Test public void testIt() throws IOException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
// Path: src/main/java/com/github/aelstad/keccakj/fips202/Shake128.java // public final class Shake128 extends KeccakSponge { // private final static byte DOMAIN_PADDING = 0xf; // private final static int DOMMAIN_PADDING_LENGTH = 4; // // public Shake128() { // super(256, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // // // } // // Path: src/main/java/com/github/aelstad/keccakj/spi/Shake128Key.java // public class Shake128Key extends RawKey { // // @Override // public String getAlgorithm() { // return Constants.SHAKE128_STREAM_CIPHER; // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/spi/Shake128StreamCipher.java // public final class Shake128StreamCipher extends AbstractSpongeStreamCipher { // private Shake128 sponge; // // @Override // KeccakSponge getSponge() { // if(sponge == null) { // sponge = new Shake128(); // } // return sponge; // } // // } // Path: src/test/java/com/github/aelstad/keccakj/fips202/TestStreamEncryption.java import java.io.ByteArrayOutputStream; import java.io.FilterOutputStream; import java.io.IOException; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.SecureRandom; import java.util.Arrays; import java.util.Random; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.IvParameterSpec; import org.junit.Assert; import org.junit.Test; import com.github.aelstad.keccakj.fips202.Shake128; import com.github.aelstad.keccakj.spi.Shake128Key; import com.github.aelstad.keccakj.spi.Shake128StreamCipher; /* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.fips202; /** * Demonstrates stream encryption/decryption */ public class TestStreamEncryption { @Test public void testIt() throws IOException, NoSuchAlgorithmException, NoSuchProviderException, NoSuchPaddingException, InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, BadPaddingException {
Shake128 shake128 = new Shake128();
aelstad/keccakj
src/test/java/com/github/aelstad/keccakj/fips202/TestStreamEncryption.java
// Path: src/main/java/com/github/aelstad/keccakj/fips202/Shake128.java // public final class Shake128 extends KeccakSponge { // private final static byte DOMAIN_PADDING = 0xf; // private final static int DOMMAIN_PADDING_LENGTH = 4; // // public Shake128() { // super(256, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // // // } // // Path: src/main/java/com/github/aelstad/keccakj/spi/Shake128Key.java // public class Shake128Key extends RawKey { // // @Override // public String getAlgorithm() { // return Constants.SHAKE128_STREAM_CIPHER; // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/spi/Shake128StreamCipher.java // public final class Shake128StreamCipher extends AbstractSpongeStreamCipher { // private Shake128 sponge; // // @Override // KeccakSponge getSponge() { // if(sponge == null) { // sponge = new Shake128(); // } // return sponge; // } // // }
import java.io.ByteArrayOutputStream; import java.io.FilterOutputStream; import java.io.IOException; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.SecureRandom; import java.util.Arrays; import java.util.Random; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.IvParameterSpec; import org.junit.Assert; import org.junit.Test; import com.github.aelstad.keccakj.fips202.Shake128; import com.github.aelstad.keccakj.spi.Shake128Key; import com.github.aelstad.keccakj.spi.Shake128StreamCipher;
for(int i=8; i < 16384; ++i) { byte[] data = new byte[i]; byte[] nonce = new byte[128]; keyRandom.nextBytes(nonce); dataRandom.nextBytes(data); shake128.getAbsorbStream().write(key); shake128.getAbsorbStream().write(nonce); ByteArrayOutputStream bos = new ByteArrayOutputStream(); FilterOutputStream fos = shake128.getTransformingSqueezeStream(bos); fos.write(data); fos.close(); Assert.assertTrue(bos.size()==data.length); Assert.assertTrue(!Arrays.equals(data, bos.toByteArray())); byte[] encrypted = bos.toByteArray(); shake128.reset(); shake128.getAbsorbStream().write(key); shake128.getAbsorbStream().write(nonce); bos.reset(); fos = shake128.getTransformingSqueezeStream(bos); fos.write(encrypted); fos.close(); byte[] decrypted = bos.toByteArray(); Assert.assertTrue(data != decrypted); Assert.assertTrue(Arrays.equals(decrypted, data)); // Using the SPI impl. getCipher not available unless Jar is signed IvParameterSpec ivParameterSpec = new IvParameterSpec(nonce);
// Path: src/main/java/com/github/aelstad/keccakj/fips202/Shake128.java // public final class Shake128 extends KeccakSponge { // private final static byte DOMAIN_PADDING = 0xf; // private final static int DOMMAIN_PADDING_LENGTH = 4; // // public Shake128() { // super(256, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // // // } // // Path: src/main/java/com/github/aelstad/keccakj/spi/Shake128Key.java // public class Shake128Key extends RawKey { // // @Override // public String getAlgorithm() { // return Constants.SHAKE128_STREAM_CIPHER; // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/spi/Shake128StreamCipher.java // public final class Shake128StreamCipher extends AbstractSpongeStreamCipher { // private Shake128 sponge; // // @Override // KeccakSponge getSponge() { // if(sponge == null) { // sponge = new Shake128(); // } // return sponge; // } // // } // Path: src/test/java/com/github/aelstad/keccakj/fips202/TestStreamEncryption.java import java.io.ByteArrayOutputStream; import java.io.FilterOutputStream; import java.io.IOException; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.SecureRandom; import java.util.Arrays; import java.util.Random; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.IvParameterSpec; import org.junit.Assert; import org.junit.Test; import com.github.aelstad.keccakj.fips202.Shake128; import com.github.aelstad.keccakj.spi.Shake128Key; import com.github.aelstad.keccakj.spi.Shake128StreamCipher; for(int i=8; i < 16384; ++i) { byte[] data = new byte[i]; byte[] nonce = new byte[128]; keyRandom.nextBytes(nonce); dataRandom.nextBytes(data); shake128.getAbsorbStream().write(key); shake128.getAbsorbStream().write(nonce); ByteArrayOutputStream bos = new ByteArrayOutputStream(); FilterOutputStream fos = shake128.getTransformingSqueezeStream(bos); fos.write(data); fos.close(); Assert.assertTrue(bos.size()==data.length); Assert.assertTrue(!Arrays.equals(data, bos.toByteArray())); byte[] encrypted = bos.toByteArray(); shake128.reset(); shake128.getAbsorbStream().write(key); shake128.getAbsorbStream().write(nonce); bos.reset(); fos = shake128.getTransformingSqueezeStream(bos); fos.write(encrypted); fos.close(); byte[] decrypted = bos.toByteArray(); Assert.assertTrue(data != decrypted); Assert.assertTrue(Arrays.equals(decrypted, data)); // Using the SPI impl. getCipher not available unless Jar is signed IvParameterSpec ivParameterSpec = new IvParameterSpec(nonce);
Shake128Key shakeKey = new Shake128Key();
aelstad/keccakj
src/test/java/com/github/aelstad/keccakj/fips202/TestStreamEncryption.java
// Path: src/main/java/com/github/aelstad/keccakj/fips202/Shake128.java // public final class Shake128 extends KeccakSponge { // private final static byte DOMAIN_PADDING = 0xf; // private final static int DOMMAIN_PADDING_LENGTH = 4; // // public Shake128() { // super(256, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // // // } // // Path: src/main/java/com/github/aelstad/keccakj/spi/Shake128Key.java // public class Shake128Key extends RawKey { // // @Override // public String getAlgorithm() { // return Constants.SHAKE128_STREAM_CIPHER; // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/spi/Shake128StreamCipher.java // public final class Shake128StreamCipher extends AbstractSpongeStreamCipher { // private Shake128 sponge; // // @Override // KeccakSponge getSponge() { // if(sponge == null) { // sponge = new Shake128(); // } // return sponge; // } // // }
import java.io.ByteArrayOutputStream; import java.io.FilterOutputStream; import java.io.IOException; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.SecureRandom; import java.util.Arrays; import java.util.Random; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.IvParameterSpec; import org.junit.Assert; import org.junit.Test; import com.github.aelstad.keccakj.fips202.Shake128; import com.github.aelstad.keccakj.spi.Shake128Key; import com.github.aelstad.keccakj.spi.Shake128StreamCipher;
byte[] nonce = new byte[128]; keyRandom.nextBytes(nonce); dataRandom.nextBytes(data); shake128.getAbsorbStream().write(key); shake128.getAbsorbStream().write(nonce); ByteArrayOutputStream bos = new ByteArrayOutputStream(); FilterOutputStream fos = shake128.getTransformingSqueezeStream(bos); fos.write(data); fos.close(); Assert.assertTrue(bos.size()==data.length); Assert.assertTrue(!Arrays.equals(data, bos.toByteArray())); byte[] encrypted = bos.toByteArray(); shake128.reset(); shake128.getAbsorbStream().write(key); shake128.getAbsorbStream().write(nonce); bos.reset(); fos = shake128.getTransformingSqueezeStream(bos); fos.write(encrypted); fos.close(); byte[] decrypted = bos.toByteArray(); Assert.assertTrue(data != decrypted); Assert.assertTrue(Arrays.equals(decrypted, data)); // Using the SPI impl. getCipher not available unless Jar is signed IvParameterSpec ivParameterSpec = new IvParameterSpec(nonce); Shake128Key shakeKey = new Shake128Key(); shakeKey.setRaw(key);
// Path: src/main/java/com/github/aelstad/keccakj/fips202/Shake128.java // public final class Shake128 extends KeccakSponge { // private final static byte DOMAIN_PADDING = 0xf; // private final static int DOMMAIN_PADDING_LENGTH = 4; // // public Shake128() { // super(256, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // // // } // // Path: src/main/java/com/github/aelstad/keccakj/spi/Shake128Key.java // public class Shake128Key extends RawKey { // // @Override // public String getAlgorithm() { // return Constants.SHAKE128_STREAM_CIPHER; // } // // } // // Path: src/main/java/com/github/aelstad/keccakj/spi/Shake128StreamCipher.java // public final class Shake128StreamCipher extends AbstractSpongeStreamCipher { // private Shake128 sponge; // // @Override // KeccakSponge getSponge() { // if(sponge == null) { // sponge = new Shake128(); // } // return sponge; // } // // } // Path: src/test/java/com/github/aelstad/keccakj/fips202/TestStreamEncryption.java import java.io.ByteArrayOutputStream; import java.io.FilterOutputStream; import java.io.IOException; import java.security.InvalidAlgorithmParameterException; import java.security.InvalidKeyException; import java.security.NoSuchAlgorithmException; import java.security.NoSuchProviderException; import java.security.SecureRandom; import java.util.Arrays; import java.util.Random; import javax.crypto.BadPaddingException; import javax.crypto.Cipher; import javax.crypto.IllegalBlockSizeException; import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.IvParameterSpec; import org.junit.Assert; import org.junit.Test; import com.github.aelstad.keccakj.fips202.Shake128; import com.github.aelstad.keccakj.spi.Shake128Key; import com.github.aelstad.keccakj.spi.Shake128StreamCipher; byte[] nonce = new byte[128]; keyRandom.nextBytes(nonce); dataRandom.nextBytes(data); shake128.getAbsorbStream().write(key); shake128.getAbsorbStream().write(nonce); ByteArrayOutputStream bos = new ByteArrayOutputStream(); FilterOutputStream fos = shake128.getTransformingSqueezeStream(bos); fos.write(data); fos.close(); Assert.assertTrue(bos.size()==data.length); Assert.assertTrue(!Arrays.equals(data, bos.toByteArray())); byte[] encrypted = bos.toByteArray(); shake128.reset(); shake128.getAbsorbStream().write(key); shake128.getAbsorbStream().write(nonce); bos.reset(); fos = shake128.getTransformingSqueezeStream(bos); fos.write(encrypted); fos.close(); byte[] decrypted = bos.toByteArray(); Assert.assertTrue(data != decrypted); Assert.assertTrue(Arrays.equals(decrypted, data)); // Using the SPI impl. getCipher not available unless Jar is signed IvParameterSpec ivParameterSpec = new IvParameterSpec(nonce); Shake128Key shakeKey = new Shake128Key(); shakeKey.setRaw(key);
Shake128StreamCipher c = new Shake128StreamCipher();
aelstad/keccakj
src/main/java/com/github/aelstad/keccakj/core/AbstractKeccakMessageDigest.java
// Path: src/main/java/com/github/aelstad/keccakj/io/BitInputStream.java // public abstract class BitInputStream extends InputStream { // @Override // public abstract void close(); // // // @Override // public int read(byte[] b, int off, int len) { // return (int) (readBits(b, ((long)off)<<3, ((long)len)<<3)>>3); // } // // /** // * Transform input to output with the input stream as a keystream // * // * @param input Input byte-array // * @param inputOff Input offset // * @param output Output byte-array // * @param outputOff Output offset // * @param len length in bytes // * @return Number of bytes transformed // */ // public int transform(byte[] input, int inputOff, byte[] output, int outputOff, int len) { // return (int) (transformBits(input, ((long)inputOff)<<3, output, ((long)outputOff)<<3, ((long)len)<<3)>>3); // } // // // @Override // public int read(byte[] b) { // return this.read(b, 0, b.length)>>3; // } // // /** // * Transform input to output using the input stream as a keystream // * // * @param input Input byte array // * @param output Output byte array // * // * @return Number of bytes transformed // */ // public int transform(byte[] input, byte[] output) { // return (int) (transformBits(input, 0l, output, 0l, ((long)input.length)<<3)>>3); // } // // // @Override // public int read() { // byte[] buf = new byte[1]; // readBits(buf, 0, 8); // // return ((int) buf[0]) & 0xff; // } // // // public abstract long readBits(byte[] arg, long bitOff, long bitLen); // // /** // * Transform input to output using the input stream as a keystream // * // * @param input Input byte array // * @param inputOff Input offset in bits // * @param output Output byte array // * @param outputOff Output offset in bits // * @param bitLen Number of bits // * @return Number of bits transformed // */ // public abstract long transformBits(byte[] input, long inputOff, byte[] output, long outputOff, long bitLen); // } // // Path: src/main/java/com/github/aelstad/keccakj/io/BitOutputStream.java // public abstract class BitOutputStream extends OutputStream { // // @Override // public abstract void close(); // // @Override // public void write(byte[] b, int off, int len) { // writeBits(b, ((long) (off))<<3, ((long)len)<<3); // } // // @Override // public void write(byte[] b) { // write(b, 0, b.length); // } // // @Override // public void write(int b) { // writeBits(new byte[] { (byte) b }, 0, 8); // } // // public abstract void writeBits(byte[] arg, long bitOff, long bitLen); // // }
import java.security.MessageDigest; import com.github.aelstad.keccakj.io.BitInputStream; import com.github.aelstad.keccakj.io.BitOutputStream;
package com.github.aelstad.keccakj.core; public abstract class AbstractKeccakMessageDigest extends MessageDigest { KeccakSponge keccakSponge;
// Path: src/main/java/com/github/aelstad/keccakj/io/BitInputStream.java // public abstract class BitInputStream extends InputStream { // @Override // public abstract void close(); // // // @Override // public int read(byte[] b, int off, int len) { // return (int) (readBits(b, ((long)off)<<3, ((long)len)<<3)>>3); // } // // /** // * Transform input to output with the input stream as a keystream // * // * @param input Input byte-array // * @param inputOff Input offset // * @param output Output byte-array // * @param outputOff Output offset // * @param len length in bytes // * @return Number of bytes transformed // */ // public int transform(byte[] input, int inputOff, byte[] output, int outputOff, int len) { // return (int) (transformBits(input, ((long)inputOff)<<3, output, ((long)outputOff)<<3, ((long)len)<<3)>>3); // } // // // @Override // public int read(byte[] b) { // return this.read(b, 0, b.length)>>3; // } // // /** // * Transform input to output using the input stream as a keystream // * // * @param input Input byte array // * @param output Output byte array // * // * @return Number of bytes transformed // */ // public int transform(byte[] input, byte[] output) { // return (int) (transformBits(input, 0l, output, 0l, ((long)input.length)<<3)>>3); // } // // // @Override // public int read() { // byte[] buf = new byte[1]; // readBits(buf, 0, 8); // // return ((int) buf[0]) & 0xff; // } // // // public abstract long readBits(byte[] arg, long bitOff, long bitLen); // // /** // * Transform input to output using the input stream as a keystream // * // * @param input Input byte array // * @param inputOff Input offset in bits // * @param output Output byte array // * @param outputOff Output offset in bits // * @param bitLen Number of bits // * @return Number of bits transformed // */ // public abstract long transformBits(byte[] input, long inputOff, byte[] output, long outputOff, long bitLen); // } // // Path: src/main/java/com/github/aelstad/keccakj/io/BitOutputStream.java // public abstract class BitOutputStream extends OutputStream { // // @Override // public abstract void close(); // // @Override // public void write(byte[] b, int off, int len) { // writeBits(b, ((long) (off))<<3, ((long)len)<<3); // } // // @Override // public void write(byte[] b) { // write(b, 0, b.length); // } // // @Override // public void write(int b) { // writeBits(new byte[] { (byte) b }, 0, 8); // } // // public abstract void writeBits(byte[] arg, long bitOff, long bitLen); // // } // Path: src/main/java/com/github/aelstad/keccakj/core/AbstractKeccakMessageDigest.java import java.security.MessageDigest; import com.github.aelstad.keccakj.io.BitInputStream; import com.github.aelstad.keccakj.io.BitOutputStream; package com.github.aelstad.keccakj.core; public abstract class AbstractKeccakMessageDigest extends MessageDigest { KeccakSponge keccakSponge;
BitOutputStream absorbStream;
aelstad/keccakj
src/main/java/com/github/aelstad/keccakj/core/AbstractKeccakMessageDigest.java
// Path: src/main/java/com/github/aelstad/keccakj/io/BitInputStream.java // public abstract class BitInputStream extends InputStream { // @Override // public abstract void close(); // // // @Override // public int read(byte[] b, int off, int len) { // return (int) (readBits(b, ((long)off)<<3, ((long)len)<<3)>>3); // } // // /** // * Transform input to output with the input stream as a keystream // * // * @param input Input byte-array // * @param inputOff Input offset // * @param output Output byte-array // * @param outputOff Output offset // * @param len length in bytes // * @return Number of bytes transformed // */ // public int transform(byte[] input, int inputOff, byte[] output, int outputOff, int len) { // return (int) (transformBits(input, ((long)inputOff)<<3, output, ((long)outputOff)<<3, ((long)len)<<3)>>3); // } // // // @Override // public int read(byte[] b) { // return this.read(b, 0, b.length)>>3; // } // // /** // * Transform input to output using the input stream as a keystream // * // * @param input Input byte array // * @param output Output byte array // * // * @return Number of bytes transformed // */ // public int transform(byte[] input, byte[] output) { // return (int) (transformBits(input, 0l, output, 0l, ((long)input.length)<<3)>>3); // } // // // @Override // public int read() { // byte[] buf = new byte[1]; // readBits(buf, 0, 8); // // return ((int) buf[0]) & 0xff; // } // // // public abstract long readBits(byte[] arg, long bitOff, long bitLen); // // /** // * Transform input to output using the input stream as a keystream // * // * @param input Input byte array // * @param inputOff Input offset in bits // * @param output Output byte array // * @param outputOff Output offset in bits // * @param bitLen Number of bits // * @return Number of bits transformed // */ // public abstract long transformBits(byte[] input, long inputOff, byte[] output, long outputOff, long bitLen); // } // // Path: src/main/java/com/github/aelstad/keccakj/io/BitOutputStream.java // public abstract class BitOutputStream extends OutputStream { // // @Override // public abstract void close(); // // @Override // public void write(byte[] b, int off, int len) { // writeBits(b, ((long) (off))<<3, ((long)len)<<3); // } // // @Override // public void write(byte[] b) { // write(b, 0, b.length); // } // // @Override // public void write(int b) { // writeBits(new byte[] { (byte) b }, 0, 8); // } // // public abstract void writeBits(byte[] arg, long bitOff, long bitLen); // // }
import java.security.MessageDigest; import com.github.aelstad.keccakj.io.BitInputStream; import com.github.aelstad.keccakj.io.BitOutputStream;
package com.github.aelstad.keccakj.core; public abstract class AbstractKeccakMessageDigest extends MessageDigest { KeccakSponge keccakSponge; BitOutputStream absorbStream; int digestLength; /** * Security level in bits is min(capacity/2,digestLength*8). * * @param algorithm Algorithm name * @param capacityInBits Keccack capacity in bits. Must be a multiple of 8. * @param digestLength Length of digest in bytes * @param domainPadding Domain padding value * @param domainPaddingBitLength Domain padding bits */ public AbstractKeccakMessageDigest(String algorithm, int capacityInBits, int digestLength, byte domainPadding, int domainPaddingBitLength) { super(algorithm); this.keccakSponge = new KeccakSponge(capacityInBits, domainPadding, domainPaddingBitLength); this.absorbStream = keccakSponge.getAbsorbStream(); this.digestLength = digestLength; } @Override protected byte[] engineDigest() { absorbStream.close(); byte[] rv = new byte[digestLength];
// Path: src/main/java/com/github/aelstad/keccakj/io/BitInputStream.java // public abstract class BitInputStream extends InputStream { // @Override // public abstract void close(); // // // @Override // public int read(byte[] b, int off, int len) { // return (int) (readBits(b, ((long)off)<<3, ((long)len)<<3)>>3); // } // // /** // * Transform input to output with the input stream as a keystream // * // * @param input Input byte-array // * @param inputOff Input offset // * @param output Output byte-array // * @param outputOff Output offset // * @param len length in bytes // * @return Number of bytes transformed // */ // public int transform(byte[] input, int inputOff, byte[] output, int outputOff, int len) { // return (int) (transformBits(input, ((long)inputOff)<<3, output, ((long)outputOff)<<3, ((long)len)<<3)>>3); // } // // // @Override // public int read(byte[] b) { // return this.read(b, 0, b.length)>>3; // } // // /** // * Transform input to output using the input stream as a keystream // * // * @param input Input byte array // * @param output Output byte array // * // * @return Number of bytes transformed // */ // public int transform(byte[] input, byte[] output) { // return (int) (transformBits(input, 0l, output, 0l, ((long)input.length)<<3)>>3); // } // // // @Override // public int read() { // byte[] buf = new byte[1]; // readBits(buf, 0, 8); // // return ((int) buf[0]) & 0xff; // } // // // public abstract long readBits(byte[] arg, long bitOff, long bitLen); // // /** // * Transform input to output using the input stream as a keystream // * // * @param input Input byte array // * @param inputOff Input offset in bits // * @param output Output byte array // * @param outputOff Output offset in bits // * @param bitLen Number of bits // * @return Number of bits transformed // */ // public abstract long transformBits(byte[] input, long inputOff, byte[] output, long outputOff, long bitLen); // } // // Path: src/main/java/com/github/aelstad/keccakj/io/BitOutputStream.java // public abstract class BitOutputStream extends OutputStream { // // @Override // public abstract void close(); // // @Override // public void write(byte[] b, int off, int len) { // writeBits(b, ((long) (off))<<3, ((long)len)<<3); // } // // @Override // public void write(byte[] b) { // write(b, 0, b.length); // } // // @Override // public void write(int b) { // writeBits(new byte[] { (byte) b }, 0, 8); // } // // public abstract void writeBits(byte[] arg, long bitOff, long bitLen); // // } // Path: src/main/java/com/github/aelstad/keccakj/core/AbstractKeccakMessageDigest.java import java.security.MessageDigest; import com.github.aelstad.keccakj.io.BitInputStream; import com.github.aelstad.keccakj.io.BitOutputStream; package com.github.aelstad.keccakj.core; public abstract class AbstractKeccakMessageDigest extends MessageDigest { KeccakSponge keccakSponge; BitOutputStream absorbStream; int digestLength; /** * Security level in bits is min(capacity/2,digestLength*8). * * @param algorithm Algorithm name * @param capacityInBits Keccack capacity in bits. Must be a multiple of 8. * @param digestLength Length of digest in bytes * @param domainPadding Domain padding value * @param domainPaddingBitLength Domain padding bits */ public AbstractKeccakMessageDigest(String algorithm, int capacityInBits, int digestLength, byte domainPadding, int domainPaddingBitLength) { super(algorithm); this.keccakSponge = new KeccakSponge(capacityInBits, domainPadding, domainPaddingBitLength); this.absorbStream = keccakSponge.getAbsorbStream(); this.digestLength = digestLength; } @Override protected byte[] engineDigest() { absorbStream.close(); byte[] rv = new byte[digestLength];
BitInputStream bis = keccakSponge.getSqueezeStream();
aelstad/keccakj
src/test/java/com/github/aelstad/keccakj/fips202/TestShake128.java
// Path: src/main/java/com/github/aelstad/keccakj/fips202/Shake128.java // public final class Shake128 extends KeccakSponge { // private final static byte DOMAIN_PADDING = 0xf; // private final static int DOMMAIN_PADDING_LENGTH = 4; // // public Shake128() { // super(256, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // // // }
import java.io.InputStream; import java.util.List; import org.junit.Test; import com.github.aelstad.keccakj.fips202.Shake128;
/* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.fips202; public class TestShake128 { @Test public void checkTestVectors() throws Exception { InputStream is = KeccakDigestTestUtils.getResourceStreamInPackage(getClass(), "ShortMsgKAT_SHAKE128.txt"); KeccakDigestTestUtils kdtu = new KeccakDigestTestUtils(); List<KeccakDigestTestUtils.DigestTest> tests = kdtu.parseTests(is);
// Path: src/main/java/com/github/aelstad/keccakj/fips202/Shake128.java // public final class Shake128 extends KeccakSponge { // private final static byte DOMAIN_PADDING = 0xf; // private final static int DOMMAIN_PADDING_LENGTH = 4; // // public Shake128() { // super(256, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // // // } // Path: src/test/java/com/github/aelstad/keccakj/fips202/TestShake128.java import java.io.InputStream; import java.util.List; import org.junit.Test; import com.github.aelstad.keccakj.fips202.Shake128; /* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.fips202; public class TestShake128 { @Test public void checkTestVectors() throws Exception { InputStream is = KeccakDigestTestUtils.getResourceStreamInPackage(getClass(), "ShortMsgKAT_SHAKE128.txt"); KeccakDigestTestUtils kdtu = new KeccakDigestTestUtils(); List<KeccakDigestTestUtils.DigestTest> tests = kdtu.parseTests(is);
Shake128 shake = new Shake128();
aelstad/keccakj
src/test/java/com/github/aelstad/keccakj/fips202/TestSHA3_512.java
// Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_512.java // public final class SHA3_512 extends AbstractKeccakMessageDigest { // // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_512() { // super("SHA3-512", 2*512, 512/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // }
import java.io.InputStream; import java.util.List; import org.junit.Test; import com.github.aelstad.keccakj.fips202.SHA3_512;
/* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.fips202; public class TestSHA3_512 { @Test public void checkTestVectors() throws Exception { InputStream is = KeccakDigestTestUtils.getResourceStreamInPackage(getClass(), "ShortMsgKAT_SHA3-512.txt"); KeccakDigestTestUtils kdtu = new KeccakDigestTestUtils(); List<KeccakDigestTestUtils.DigestTest> tests = kdtu.parseTests(is);
// Path: src/main/java/com/github/aelstad/keccakj/fips202/SHA3_512.java // public final class SHA3_512 extends AbstractKeccakMessageDigest { // // private final static byte DOMAIN_PADDING = 2; // private final static int DOMMAIN_PADDING_LENGTH = 2; // // public SHA3_512() { // super("SHA3-512", 2*512, 512/8, DOMAIN_PADDING, DOMMAIN_PADDING_LENGTH); // } // // } // Path: src/test/java/com/github/aelstad/keccakj/fips202/TestSHA3_512.java import java.io.InputStream; import java.util.List; import org.junit.Test; import com.github.aelstad.keccakj.fips202.SHA3_512; /* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.fips202; public class TestSHA3_512 { @Test public void checkTestVectors() throws Exception { InputStream is = KeccakDigestTestUtils.getResourceStreamInPackage(getClass(), "ShortMsgKAT_SHA3-512.txt"); KeccakDigestTestUtils kdtu = new KeccakDigestTestUtils(); List<KeccakDigestTestUtils.DigestTest> tests = kdtu.parseTests(is);
SHA3_512 sha = new SHA3_512();
aelstad/keccakj
src/main/java/com/github/aelstad/keccakj/spi/LakeKeyakKey.java
// Path: src/main/java/com/github/aelstad/keccakj/provider/Constants.java // public class Constants { // public static final String PROVIDER = "com.github.aelstad.keccakj"; // // public static final String SHA3_224 = "SHA3-224"; // public static final String SHA3_256 = "SHA3-256"; // public static final String SHA3_384 = "SHA3-384"; // public static final String SHA3_512 = "SHA3-512"; // // public static final String KECCAK_RND128 = "KECCAK-RND-128"; // public static final String KECCAK_RND256 = "KECCAK-RND-256"; // // public static final String SHAKE128_STREAM_CIPHER = "SHAKE128"; // public static final String SHAKE256_STREAM_CIPHER = "SHAKE256"; // // public static final String LAKEKEYAK_AUTHENTICATING_STREAM_CIPHER = "LAKE-KEYAK"; // }
import java.security.InvalidKeyException; import com.github.aelstad.keccakj.provider.Constants;
/* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.spi; public final class LakeKeyakKey extends RawKey { public LakeKeyakKey() { super(); } public LakeKeyakKey(byte[] rawKey) throws InvalidKeyException { super(rawKey); } @Override public String getAlgorithm() {
// Path: src/main/java/com/github/aelstad/keccakj/provider/Constants.java // public class Constants { // public static final String PROVIDER = "com.github.aelstad.keccakj"; // // public static final String SHA3_224 = "SHA3-224"; // public static final String SHA3_256 = "SHA3-256"; // public static final String SHA3_384 = "SHA3-384"; // public static final String SHA3_512 = "SHA3-512"; // // public static final String KECCAK_RND128 = "KECCAK-RND-128"; // public static final String KECCAK_RND256 = "KECCAK-RND-256"; // // public static final String SHAKE128_STREAM_CIPHER = "SHAKE128"; // public static final String SHAKE256_STREAM_CIPHER = "SHAKE256"; // // public static final String LAKEKEYAK_AUTHENTICATING_STREAM_CIPHER = "LAKE-KEYAK"; // } // Path: src/main/java/com/github/aelstad/keccakj/spi/LakeKeyakKey.java import java.security.InvalidKeyException; import com.github.aelstad.keccakj.provider.Constants; /* * Copyright 2014 Amund Elstad. * * 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.aelstad.keccakj.spi; public final class LakeKeyakKey extends RawKey { public LakeKeyakKey() { super(); } public LakeKeyakKey(byte[] rawKey) throws InvalidKeyException { super(rawKey); } @Override public String getAlgorithm() {
return Constants.LAKEKEYAK_AUTHENTICATING_STREAM_CIPHER;
achellies/AtlasForAndroid
src/android/taobao/atlas/util/AtlasFileLock.java
// Path: src/android/taobao/atlas/runtime/RuntimeVariables.java // public class RuntimeVariables { // public static Application androidApplication; // public static DelegateClassLoader delegateClassLoader; // public static Resources delegateResources; // }
import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; import java.util.HashMap; import java.util.Map; import android.app.ActivityManager; import android.app.ActivityManager.RunningAppProcessInfo; import android.os.Process; import android.taobao.atlas.runtime.RuntimeVariables; import android.util.Log;
package android.taobao.atlas.util; public class AtlasFileLock { private static final String TAG = "AtlasFileLock"; private static String processName; private static AtlasFileLock singleton; private Map<String, FileLockCount> mRefCountMap; private class FileLockCount { FileLock mFileLock; int mRefCount; FileLockCount(FileLock fileLock, int i) { this.mFileLock = fileLock; this.mRefCount = i; } } public AtlasFileLock() { this.mRefCountMap = new HashMap(); } static { int myPid = Process.myPid();
// Path: src/android/taobao/atlas/runtime/RuntimeVariables.java // public class RuntimeVariables { // public static Application androidApplication; // public static DelegateClassLoader delegateClassLoader; // public static Resources delegateResources; // } // Path: src/android/taobao/atlas/util/AtlasFileLock.java import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; import java.nio.channels.FileChannel; import java.nio.channels.FileLock; import java.util.HashMap; import java.util.Map; import android.app.ActivityManager; import android.app.ActivityManager.RunningAppProcessInfo; import android.os.Process; import android.taobao.atlas.runtime.RuntimeVariables; import android.util.Log; package android.taobao.atlas.util; public class AtlasFileLock { private static final String TAG = "AtlasFileLock"; private static String processName; private static AtlasFileLock singleton; private Map<String, FileLockCount> mRefCountMap; private class FileLockCount { FileLock mFileLock; int mRefCount; FileLockCount(FileLock fileLock, int i) { this.mFileLock = fileLock; this.mRefCount = i; } } public AtlasFileLock() { this.mRefCountMap = new HashMap(); } static { int myPid = Process.myPid();
if (RuntimeVariables.androidApplication.getApplicationContext() != null) {
achellies/AtlasForAndroid
src/android/taobao/atlas/framework/BundleContextImpl.java
// Path: src/android/taobao/atlas/log/Logger.java // public interface Logger { // void debug(String str); // // void error(String str); // // void error(String str, Throwable th); // // void error(StringBuffer stringBuffer, Throwable th); // // void fatal(String str); // // void fatal(String str, Throwable th); // // void info(String str); // // boolean isDebugEnabled(); // // boolean isErrorEnabled(); // // boolean isFatalEnabled(); // // boolean isInfoEnabled(); // // boolean isVerboseEnabled(); // // boolean isWarnEnabled(); // // void verbose(String str); // // void warn(String str); // // void warn(String str, Throwable th); // // void warn(StringBuffer stringBuffer, Throwable th); // } // // Path: src/android/taobao/atlas/log/LoggerFactory.java // public class LoggerFactory { // public static int logLevel; // // static { // logLevel = 3; // } // // public static Logger getInstance(String str) { // return getInstance(str, null); // } // // public static Logger getInstance(Class<?> cls) { // return getInstance(null, cls); // } // // private static Logger getInstance(String str, Class<?> cls) { // if (cls != null) { // return new AndroidLogger((Class) cls); // } // return new AndroidLogger(str); // } // }
import android.taobao.atlas.log.Logger; import android.taobao.atlas.log.LoggerFactory; import com.tencent.mm.sdk.platformtools.MAlarmHandler; import java.io.File; import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; import java.util.Dictionary; import java.util.List; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; import org.osgi.framework.BundleListener; import org.osgi.framework.Constants; import org.osgi.framework.Filter; import org.osgi.framework.FrameworkListener; import org.osgi.framework.InvalidSyntaxException; import org.osgi.framework.ServiceListener; import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceRegistration; import org.osgi.framework.SynchronousBundleListener;
package android.taobao.atlas.framework; public class BundleContextImpl implements BundleContext { static final Logger log; BundleImpl bundle; boolean isValid; public BundleContextImpl() { this.isValid = true; } static {
// Path: src/android/taobao/atlas/log/Logger.java // public interface Logger { // void debug(String str); // // void error(String str); // // void error(String str, Throwable th); // // void error(StringBuffer stringBuffer, Throwable th); // // void fatal(String str); // // void fatal(String str, Throwable th); // // void info(String str); // // boolean isDebugEnabled(); // // boolean isErrorEnabled(); // // boolean isFatalEnabled(); // // boolean isInfoEnabled(); // // boolean isVerboseEnabled(); // // boolean isWarnEnabled(); // // void verbose(String str); // // void warn(String str); // // void warn(String str, Throwable th); // // void warn(StringBuffer stringBuffer, Throwable th); // } // // Path: src/android/taobao/atlas/log/LoggerFactory.java // public class LoggerFactory { // public static int logLevel; // // static { // logLevel = 3; // } // // public static Logger getInstance(String str) { // return getInstance(str, null); // } // // public static Logger getInstance(Class<?> cls) { // return getInstance(null, cls); // } // // private static Logger getInstance(String str, Class<?> cls) { // if (cls != null) { // return new AndroidLogger((Class) cls); // } // return new AndroidLogger(str); // } // } // Path: src/android/taobao/atlas/framework/BundleContextImpl.java import android.taobao.atlas.log.Logger; import android.taobao.atlas.log.LoggerFactory; import com.tencent.mm.sdk.platformtools.MAlarmHandler; import java.io.File; import java.io.InputStream; import java.util.ArrayList; import java.util.Collection; import java.util.Dictionary; import java.util.List; import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; import org.osgi.framework.BundleException; import org.osgi.framework.BundleListener; import org.osgi.framework.Constants; import org.osgi.framework.Filter; import org.osgi.framework.FrameworkListener; import org.osgi.framework.InvalidSyntaxException; import org.osgi.framework.ServiceListener; import org.osgi.framework.ServiceReference; import org.osgi.framework.ServiceRegistration; import org.osgi.framework.SynchronousBundleListener; package android.taobao.atlas.framework; public class BundleContextImpl implements BundleContext { static final Logger log; BundleImpl bundle; boolean isValid; public BundleContextImpl() { this.isValid = true; } static {
log = LoggerFactory.getInstance("BundleContextImpl");
achellies/AtlasForAndroid
src/android/taobao/atlas/runtime/DelegateComponent.java
// Path: src/android/taobao/atlas/log/Logger.java // public interface Logger { // void debug(String str); // // void error(String str); // // void error(String str, Throwable th); // // void error(StringBuffer stringBuffer, Throwable th); // // void fatal(String str); // // void fatal(String str, Throwable th); // // void info(String str); // // boolean isDebugEnabled(); // // boolean isErrorEnabled(); // // boolean isFatalEnabled(); // // boolean isInfoEnabled(); // // boolean isVerboseEnabled(); // // boolean isWarnEnabled(); // // void verbose(String str); // // void warn(String str); // // void warn(String str, Throwable th); // // void warn(StringBuffer stringBuffer, Throwable th); // } // // Path: src/android/taobao/atlas/log/LoggerFactory.java // public class LoggerFactory { // public static int logLevel; // // static { // logLevel = 3; // } // // public static Logger getInstance(String str) { // return getInstance(str, null); // } // // public static Logger getInstance(Class<?> cls) { // return getInstance(null, cls); // } // // private static Logger getInstance(String str, Class<?> cls) { // if (cls != null) { // return new AndroidLogger((Class) cls); // } // return new AndroidLogger(str); // } // }
import android.app.Application; import android.taobao.atlas.log.Logger; import android.taobao.atlas.log.LoggerFactory; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap;
package android.taobao.atlas.runtime; public class DelegateComponent { static Map<String, Application> apkApplications; private static Map<String, PackageLite> apkPackages;
// Path: src/android/taobao/atlas/log/Logger.java // public interface Logger { // void debug(String str); // // void error(String str); // // void error(String str, Throwable th); // // void error(StringBuffer stringBuffer, Throwable th); // // void fatal(String str); // // void fatal(String str, Throwable th); // // void info(String str); // // boolean isDebugEnabled(); // // boolean isErrorEnabled(); // // boolean isFatalEnabled(); // // boolean isInfoEnabled(); // // boolean isVerboseEnabled(); // // boolean isWarnEnabled(); // // void verbose(String str); // // void warn(String str); // // void warn(String str, Throwable th); // // void warn(StringBuffer stringBuffer, Throwable th); // } // // Path: src/android/taobao/atlas/log/LoggerFactory.java // public class LoggerFactory { // public static int logLevel; // // static { // logLevel = 3; // } // // public static Logger getInstance(String str) { // return getInstance(str, null); // } // // public static Logger getInstance(Class<?> cls) { // return getInstance(null, cls); // } // // private static Logger getInstance(String str, Class<?> cls) { // if (cls != null) { // return new AndroidLogger((Class) cls); // } // return new AndroidLogger(str); // } // } // Path: src/android/taobao/atlas/runtime/DelegateComponent.java import android.app.Application; import android.taobao.atlas.log.Logger; import android.taobao.atlas.log.LoggerFactory; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; package android.taobao.atlas.runtime; public class DelegateComponent { static Map<String, Application> apkApplications; private static Map<String, PackageLite> apkPackages;
static final Logger log;
achellies/AtlasForAndroid
src/android/taobao/atlas/runtime/DelegateComponent.java
// Path: src/android/taobao/atlas/log/Logger.java // public interface Logger { // void debug(String str); // // void error(String str); // // void error(String str, Throwable th); // // void error(StringBuffer stringBuffer, Throwable th); // // void fatal(String str); // // void fatal(String str, Throwable th); // // void info(String str); // // boolean isDebugEnabled(); // // boolean isErrorEnabled(); // // boolean isFatalEnabled(); // // boolean isInfoEnabled(); // // boolean isVerboseEnabled(); // // boolean isWarnEnabled(); // // void verbose(String str); // // void warn(String str); // // void warn(String str, Throwable th); // // void warn(StringBuffer stringBuffer, Throwable th); // } // // Path: src/android/taobao/atlas/log/LoggerFactory.java // public class LoggerFactory { // public static int logLevel; // // static { // logLevel = 3; // } // // public static Logger getInstance(String str) { // return getInstance(str, null); // } // // public static Logger getInstance(Class<?> cls) { // return getInstance(null, cls); // } // // private static Logger getInstance(String str, Class<?> cls) { // if (cls != null) { // return new AndroidLogger((Class) cls); // } // return new AndroidLogger(str); // } // }
import android.app.Application; import android.taobao.atlas.log.Logger; import android.taobao.atlas.log.LoggerFactory; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap;
package android.taobao.atlas.runtime; public class DelegateComponent { static Map<String, Application> apkApplications; private static Map<String, PackageLite> apkPackages; static final Logger log; static {
// Path: src/android/taobao/atlas/log/Logger.java // public interface Logger { // void debug(String str); // // void error(String str); // // void error(String str, Throwable th); // // void error(StringBuffer stringBuffer, Throwable th); // // void fatal(String str); // // void fatal(String str, Throwable th); // // void info(String str); // // boolean isDebugEnabled(); // // boolean isErrorEnabled(); // // boolean isFatalEnabled(); // // boolean isInfoEnabled(); // // boolean isVerboseEnabled(); // // boolean isWarnEnabled(); // // void verbose(String str); // // void warn(String str); // // void warn(String str, Throwable th); // // void warn(StringBuffer stringBuffer, Throwable th); // } // // Path: src/android/taobao/atlas/log/LoggerFactory.java // public class LoggerFactory { // public static int logLevel; // // static { // logLevel = 3; // } // // public static Logger getInstance(String str) { // return getInstance(str, null); // } // // public static Logger getInstance(Class<?> cls) { // return getInstance(null, cls); // } // // private static Logger getInstance(String str, Class<?> cls) { // if (cls != null) { // return new AndroidLogger((Class) cls); // } // return new AndroidLogger(str); // } // } // Path: src/android/taobao/atlas/runtime/DelegateComponent.java import android.app.Application; import android.taobao.atlas.log.Logger; import android.taobao.atlas.log.LoggerFactory; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.ConcurrentHashMap; package android.taobao.atlas.runtime; public class DelegateComponent { static Map<String, Application> apkApplications; private static Map<String, PackageLite> apkPackages; static final Logger log; static {
log = LoggerFactory.getInstance("DelegateComponent");
achellies/AtlasForAndroid
src/android/taobao/atlas/hack/AssertionArrayException.java
// Path: src/android/taobao/atlas/hack/Hack.java // public static class HackAssertionException extends Throwable { // private static final long serialVersionUID = 1; // private Class<?> mHackedClass; // private String mHackedFieldName; // private String mHackedMethodName; // // public HackAssertionException(String str) { // super(str); // } // // public HackAssertionException(Exception exception) { // super(exception); // } // // public String toString() { // return getCause() != null ? getClass().getName() + ": " + getCause() : super.toString(); // } // // public Class<?> getHackedClass() { // return this.mHackedClass; // } // // public void setHackedClass(Class<?> cls) { // this.mHackedClass = cls; // } // // public String getHackedMethodName() { // return this.mHackedMethodName; // } // // public void setHackedMethodName(String str) { // this.mHackedMethodName = str; // } // // public String getHackedFieldName() { // return this.mHackedFieldName; // } // // public void setHackedFieldName(String str) { // this.mHackedFieldName = str; // } // }
import android.taobao.atlas.hack.Hack.HackDeclaration.HackAssertionException; import com.tencent.mm.sdk.platformtools.FilePathGenerator; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import mtopsdk.common.util.SymbolExpUtil;
package android.taobao.atlas.hack; public class AssertionArrayException extends Exception { private static final long serialVersionUID = 1;
// Path: src/android/taobao/atlas/hack/Hack.java // public static class HackAssertionException extends Throwable { // private static final long serialVersionUID = 1; // private Class<?> mHackedClass; // private String mHackedFieldName; // private String mHackedMethodName; // // public HackAssertionException(String str) { // super(str); // } // // public HackAssertionException(Exception exception) { // super(exception); // } // // public String toString() { // return getCause() != null ? getClass().getName() + ": " + getCause() : super.toString(); // } // // public Class<?> getHackedClass() { // return this.mHackedClass; // } // // public void setHackedClass(Class<?> cls) { // this.mHackedClass = cls; // } // // public String getHackedMethodName() { // return this.mHackedMethodName; // } // // public void setHackedMethodName(String str) { // this.mHackedMethodName = str; // } // // public String getHackedFieldName() { // return this.mHackedFieldName; // } // // public void setHackedFieldName(String str) { // this.mHackedFieldName = str; // } // } // Path: src/android/taobao/atlas/hack/AssertionArrayException.java import android.taobao.atlas.hack.Hack.HackDeclaration.HackAssertionException; import com.tencent.mm.sdk.platformtools.FilePathGenerator; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; import mtopsdk.common.util.SymbolExpUtil; package android.taobao.atlas.hack; public class AssertionArrayException extends Exception { private static final long serialVersionUID = 1;
private List<HackAssertionException> mAssertionErr;
DemandCube/Sparkngin
src/main/java/com/neverwinterdp/sparkngin/log4j/SparknginLog4jAppender.java
// Path: src/main/java/com/neverwinterdp/sparkngin/http/JSONHttpSparknginClient.java // public class JSONHttpSparknginClient extends AbstractHttpSparknginClient { // // public JSONHttpSparknginClient(String host, int port, int bufferSize, boolean connect) throws Exception { // super(host, port, bufferSize, connect) ; // setPath("/message/json") ; // } // // protected Ack toAck(HttpContent content) { // String json = content.content().toString(CharsetUtil.UTF_8); // Ack ack = JSONSerializer.INSTANCE.fromString(json, Ack.class) ; // return ack ; // } // // // @Override // protected byte[] toBinData(Message message) { // return JSONSerializer.INSTANCE.toBytes(message) ; // } // // protected String toStringData(Message message) { // return JSONSerializer.INSTANCE.toString(message); // } // // }
import java.io.IOException; import org.apache.log4j.AppenderSkeleton; import org.apache.log4j.spi.LoggingEvent; import com.neverwinterdp.buffer.chronicle.MultiSegmentQueue; import com.neverwinterdp.buffer.chronicle.Segment; import com.neverwinterdp.message.Message; import com.neverwinterdp.sparkngin.http.JSONHttpSparknginClient;
public void setSparknginHost(String sparknginHost) { this.sparknginHost = sparknginHost; } public void setSparknginPort(int sparknginPort) { this.sparknginPort = sparknginPort; } public void setSparknginReconnectPeriod(long sparknginReconnectPeriod) { this.sparknginReconnectPeriod = sparknginReconnectPeriod; } public void setMessageTopic(String messageTopic) { this.messageTopic = messageTopic; } public boolean requiresLayout() { return false; } protected void append(LoggingEvent event) { if(queueError) return ; Log4jRecord record = new Log4jRecord(event) ; try { queue.writeObject(record) ; } catch (Exception e) { queueError = true ; e.printStackTrace(); } } public class DeamonThread extends Thread {
// Path: src/main/java/com/neverwinterdp/sparkngin/http/JSONHttpSparknginClient.java // public class JSONHttpSparknginClient extends AbstractHttpSparknginClient { // // public JSONHttpSparknginClient(String host, int port, int bufferSize, boolean connect) throws Exception { // super(host, port, bufferSize, connect) ; // setPath("/message/json") ; // } // // protected Ack toAck(HttpContent content) { // String json = content.content().toString(CharsetUtil.UTF_8); // Ack ack = JSONSerializer.INSTANCE.fromString(json, Ack.class) ; // return ack ; // } // // // @Override // protected byte[] toBinData(Message message) { // return JSONSerializer.INSTANCE.toBytes(message) ; // } // // protected String toStringData(Message message) { // return JSONSerializer.INSTANCE.toString(message); // } // // } // Path: src/main/java/com/neverwinterdp/sparkngin/log4j/SparknginLog4jAppender.java import java.io.IOException; import org.apache.log4j.AppenderSkeleton; import org.apache.log4j.spi.LoggingEvent; import com.neverwinterdp.buffer.chronicle.MultiSegmentQueue; import com.neverwinterdp.buffer.chronicle.Segment; import com.neverwinterdp.message.Message; import com.neverwinterdp.sparkngin.http.JSONHttpSparknginClient; public void setSparknginHost(String sparknginHost) { this.sparknginHost = sparknginHost; } public void setSparknginPort(int sparknginPort) { this.sparknginPort = sparknginPort; } public void setSparknginReconnectPeriod(long sparknginReconnectPeriod) { this.sparknginReconnectPeriod = sparknginReconnectPeriod; } public void setMessageTopic(String messageTopic) { this.messageTopic = messageTopic; } public boolean requiresLayout() { return false; } protected void append(LoggingEvent event) { if(queueError) return ; Log4jRecord record = new Log4jRecord(event) ; try { queue.writeObject(record) ; } catch (Exception e) { queueError = true ; e.printStackTrace(); } } public class DeamonThread extends Thread {
private JSONHttpSparknginClient client = null ;
DemandCube/Sparkngin
src/main/java/com/neverwinterdp/sparkngin/http/JSONMessageRouteHandler.java
// Path: src/main/java/com/neverwinterdp/sparkngin/Ack.java // public class Ack implements Serializable { // static public enum Status { OK, ERROR, NOT_AVAIBLE } // // private Object messageId ; // private Status status; // private String message; // // public Object getMessageId() { return messageId; } // public void setMessageId(Object objectId) { // this.messageId = objectId; // } // // public Status getStatus() { // return status; // } // // public void setStatus(Status status) { // this.status = status; // } // // public String getMessage() { // return message; // } // // public void setMessage(String message) { // this.message = message; // } // }
import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.QueryStringDecoder; import com.neverwinterdp.message.Message; import com.neverwinterdp.netty.http.RouteHandlerGeneric; import com.neverwinterdp.sparkngin.Ack; import com.neverwinterdp.sparkngin.Sparkngin; import com.neverwinterdp.util.JSONSerializer;
package com.neverwinterdp.sparkngin.http; /** * @author Tuan Nguyen * @email tuan08@gmail.com */ public class JSONMessageRouteHandler extends RouteHandlerGeneric { private Sparkngin sparkngin ; public JSONMessageRouteHandler(Sparkngin sparkngin) { this.sparkngin = sparkngin ; } @Override protected void doGet(ChannelHandlerContext ctx, HttpRequest httpReq) { QueryStringDecoder reqDecoder = new QueryStringDecoder(httpReq.getUri()) ; String data = reqDecoder.parameters().get("data").get(0) ; Message message = JSONSerializer.INSTANCE.fromString(data, Message.class) ;
// Path: src/main/java/com/neverwinterdp/sparkngin/Ack.java // public class Ack implements Serializable { // static public enum Status { OK, ERROR, NOT_AVAIBLE } // // private Object messageId ; // private Status status; // private String message; // // public Object getMessageId() { return messageId; } // public void setMessageId(Object objectId) { // this.messageId = objectId; // } // // public Status getStatus() { // return status; // } // // public void setStatus(Status status) { // this.status = status; // } // // public String getMessage() { // return message; // } // // public void setMessage(String message) { // this.message = message; // } // } // Path: src/main/java/com/neverwinterdp/sparkngin/http/JSONMessageRouteHandler.java import io.netty.buffer.ByteBuf; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.QueryStringDecoder; import com.neverwinterdp.message.Message; import com.neverwinterdp.netty.http.RouteHandlerGeneric; import com.neverwinterdp.sparkngin.Ack; import com.neverwinterdp.sparkngin.Sparkngin; import com.neverwinterdp.util.JSONSerializer; package com.neverwinterdp.sparkngin.http; /** * @author Tuan Nguyen * @email tuan08@gmail.com */ public class JSONMessageRouteHandler extends RouteHandlerGeneric { private Sparkngin sparkngin ; public JSONMessageRouteHandler(Sparkngin sparkngin) { this.sparkngin = sparkngin ; } @Override protected void doGet(ChannelHandlerContext ctx, HttpRequest httpReq) { QueryStringDecoder reqDecoder = new QueryStringDecoder(httpReq.getUri()) ; String data = reqDecoder.parameters().get("data").get(0) ; Message message = JSONSerializer.INSTANCE.fromString(data, Message.class) ;
Ack ack = sparkngin.push(message);
DemandCube/Sparkngin
src/test/java/com/neverwinterdp/sparkngin/http/SparknginClusterBuilder.java
// Path: src/main/java/com/neverwinterdp/sparkngin/NullDevMessageForwarder.java // public class NullDevMessageForwarder implements MessageForwarder { // private boolean dump = false ; // private int count ; // private Throwable error ; // // // public NullDevMessageForwarder() { // } // // public NullDevMessageForwarder(Map<String, String> props) { // dump = MapUtil.getBool(props, "forwarder.nulldev.dump", false) ; // } // // public boolean hasError() { return error != null ; } // // public void setError(Throwable error) { this.error = error ; } // // public boolean reconnect() { // error = null ; // return true ; // } // // public int getProcessCount() { return count ; } // // public void forward(Message message) { // count++ ; // dump(message) ; // } // // public void dump(Message message) { // if(!dump) return ; // System.out.println(JSONSerializer.INSTANCE.toString(message.getHeader())); // try { // Class<?> type = Class.forName(message.getData().getType()) ; // Object object = message.getData().getDataAs(type) ; // System.out.println(JSONSerializer.INSTANCE.toString(object)); // } catch (ClassNotFoundException e) { // e.printStackTrace(); // } // } // // public void close() { // } // }
import com.neverwinterdp.server.Server; import com.neverwinterdp.server.shell.Shell; import com.neverwinterdp.sparkngin.NullDevMessageForwarder; import com.neverwinterdp.util.FileUtil;
String kafkaReplication = kafkaServer.length >= 2 ? "2" : "1" ; for(int i = 0; i < kafkaServer.length; i++) { int id = i + 1; shell.execute( "module install "+ " --member-name kafka" + id + " --autostart" + " --module Kafka" + " -Pmodule.data.drop=true" + " -Pkafka:broker.id=" + id + " -Pkafka:port=" + (9092 + i) + " -Pkafka:zookeeper.connect=127.0.0.1:2181" + " -Pkafka:default.replication.factor=" + kafkaReplication + " -Pkafka:controller.socket.timeout.ms=90000" + " -Pkafka:controlled.shutdown.enable=true" + " -Pkafka:controlled.shutdown.max.retries=3" + " -Pkafka:controlled.shutdown.retry.backoff.ms=60000" ) ; } shell.execute( "module install " + " -Pmodule.data.drop=true" + " -Pkafka:zookeeper.connect=127.0.0.1:2181" + " --member-role generic --autostart --module KafkaConsumer" ) ; shell.execute( "module install" + " -Pmodule.data.drop=true" + " -Psparkngin:http-listen-port=7080" +
// Path: src/main/java/com/neverwinterdp/sparkngin/NullDevMessageForwarder.java // public class NullDevMessageForwarder implements MessageForwarder { // private boolean dump = false ; // private int count ; // private Throwable error ; // // // public NullDevMessageForwarder() { // } // // public NullDevMessageForwarder(Map<String, String> props) { // dump = MapUtil.getBool(props, "forwarder.nulldev.dump", false) ; // } // // public boolean hasError() { return error != null ; } // // public void setError(Throwable error) { this.error = error ; } // // public boolean reconnect() { // error = null ; // return true ; // } // // public int getProcessCount() { return count ; } // // public void forward(Message message) { // count++ ; // dump(message) ; // } // // public void dump(Message message) { // if(!dump) return ; // System.out.println(JSONSerializer.INSTANCE.toString(message.getHeader())); // try { // Class<?> type = Class.forName(message.getData().getType()) ; // Object object = message.getData().getDataAs(type) ; // System.out.println(JSONSerializer.INSTANCE.toString(object)); // } catch (ClassNotFoundException e) { // e.printStackTrace(); // } // } // // public void close() { // } // } // Path: src/test/java/com/neverwinterdp/sparkngin/http/SparknginClusterBuilder.java import com.neverwinterdp.server.Server; import com.neverwinterdp.server.shell.Shell; import com.neverwinterdp.sparkngin.NullDevMessageForwarder; import com.neverwinterdp.util.FileUtil; String kafkaReplication = kafkaServer.length >= 2 ? "2" : "1" ; for(int i = 0; i < kafkaServer.length; i++) { int id = i + 1; shell.execute( "module install "+ " --member-name kafka" + id + " --autostart" + " --module Kafka" + " -Pmodule.data.drop=true" + " -Pkafka:broker.id=" + id + " -Pkafka:port=" + (9092 + i) + " -Pkafka:zookeeper.connect=127.0.0.1:2181" + " -Pkafka:default.replication.factor=" + kafkaReplication + " -Pkafka:controller.socket.timeout.ms=90000" + " -Pkafka:controlled.shutdown.enable=true" + " -Pkafka:controlled.shutdown.max.retries=3" + " -Pkafka:controlled.shutdown.retry.backoff.ms=60000" ) ; } shell.execute( "module install " + " -Pmodule.data.drop=true" + " -Pkafka:zookeeper.connect=127.0.0.1:2181" + " --member-role generic --autostart --module KafkaConsumer" ) ; shell.execute( "module install" + " -Pmodule.data.drop=true" + " -Psparkngin:http-listen-port=7080" +
" -Psparkngin:forwarder-class=" + NullDevMessageForwarder.class.getName() +
DemandCube/Sparkngin
src/test/java/com/neverwinterdp/sparkngin/http/SparknginServer.java
// Path: src/main/java/com/neverwinterdp/sparkngin/NullDevMessageForwarder.java // public class NullDevMessageForwarder implements MessageForwarder { // private boolean dump = false ; // private int count ; // private Throwable error ; // // // public NullDevMessageForwarder() { // } // // public NullDevMessageForwarder(Map<String, String> props) { // dump = MapUtil.getBool(props, "forwarder.nulldev.dump", false) ; // } // // public boolean hasError() { return error != null ; } // // public void setError(Throwable error) { this.error = error ; } // // public boolean reconnect() { // error = null ; // return true ; // } // // public int getProcessCount() { return count ; } // // public void forward(Message message) { // count++ ; // dump(message) ; // } // // public void dump(Message message) { // if(!dump) return ; // System.out.println(JSONSerializer.INSTANCE.toString(message.getHeader())); // try { // Class<?> type = Class.forName(message.getData().getType()) ; // Object object = message.getData().getDataAs(type) ; // System.out.println(JSONSerializer.INSTANCE.toString(object)); // } catch (ClassNotFoundException e) { // e.printStackTrace(); // } // } // // public void close() { // } // }
import com.neverwinterdp.netty.http.HttpServer; import com.neverwinterdp.netty.http.StaticFileHandler; import com.neverwinterdp.sparkngin.NullDevMessageForwarder; import com.neverwinterdp.sparkngin.Sparkngin; import com.neverwinterdp.util.FileUtil; import com.neverwinterdp.yara.MetricRegistry;
package com.neverwinterdp.sparkngin.http; /** * @author Tuan Nguyen * @email tuan08@gmail.com */ public class SparknginServer { static { System.setProperty("log4j.configuration", "file:src/main/resources/log4j.properties") ; }
// Path: src/main/java/com/neverwinterdp/sparkngin/NullDevMessageForwarder.java // public class NullDevMessageForwarder implements MessageForwarder { // private boolean dump = false ; // private int count ; // private Throwable error ; // // // public NullDevMessageForwarder() { // } // // public NullDevMessageForwarder(Map<String, String> props) { // dump = MapUtil.getBool(props, "forwarder.nulldev.dump", false) ; // } // // public boolean hasError() { return error != null ; } // // public void setError(Throwable error) { this.error = error ; } // // public boolean reconnect() { // error = null ; // return true ; // } // // public int getProcessCount() { return count ; } // // public void forward(Message message) { // count++ ; // dump(message) ; // } // // public void dump(Message message) { // if(!dump) return ; // System.out.println(JSONSerializer.INSTANCE.toString(message.getHeader())); // try { // Class<?> type = Class.forName(message.getData().getType()) ; // Object object = message.getData().getDataAs(type) ; // System.out.println(JSONSerializer.INSTANCE.toString(object)); // } catch (ClassNotFoundException e) { // e.printStackTrace(); // } // } // // public void close() { // } // } // Path: src/test/java/com/neverwinterdp/sparkngin/http/SparknginServer.java import com.neverwinterdp.netty.http.HttpServer; import com.neverwinterdp.netty.http.StaticFileHandler; import com.neverwinterdp.sparkngin.NullDevMessageForwarder; import com.neverwinterdp.sparkngin.Sparkngin; import com.neverwinterdp.util.FileUtil; import com.neverwinterdp.yara.MetricRegistry; package com.neverwinterdp.sparkngin.http; /** * @author Tuan Nguyen * @email tuan08@gmail.com */ public class SparknginServer { static { System.setProperty("log4j.configuration", "file:src/main/resources/log4j.properties") ; }
NullDevMessageForwarder forwarder ;
DemandCube/Sparkngin
src/main/java/com/neverwinterdp/sparkngin/http/AbstractHttpSparknginClient.java
// Path: src/main/java/com/neverwinterdp/sparkngin/Ack.java // public class Ack implements Serializable { // static public enum Status { OK, ERROR, NOT_AVAIBLE } // // private Object messageId ; // private Status status; // private String message; // // public Object getMessageId() { return messageId; } // public void setMessageId(Object objectId) { // this.messageId = objectId; // } // // public Status getStatus() { // return status; // } // // public void setStatus(Status status) { // this.status = status; // } // // public String getMessage() { // return message; // } // // public void setMessage(String message) { // this.message = message; // } // }
import io.netty.handler.codec.http.HttpContent; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.QueryStringEncoder; import java.util.LinkedHashMap; import java.util.Map; import java.util.concurrent.TimeoutException; import com.neverwinterdp.message.Message; import com.neverwinterdp.netty.http.client.AsyncHttpClient; import com.neverwinterdp.netty.http.client.ResponseHandler; import com.neverwinterdp.sparkngin.Ack;
if(waitingAckMessages.size() >= bufferSize) { waitingAckMessages.wait(timeout); if(waitingAckMessages.size() >= bufferSize) { throw new TimeoutException("fail to send the message in " + timeout + "ms") ; } } QueryStringEncoder encoder = new QueryStringEncoder(path); encoder.addParam("data", toStringData(message)); client.get(encoder.toString()); sendCount++ ; String messageId = message.getHeader().getKey() ; waitingAckMessages.put(messageId, message) ; } } public void sendPost(Message message, long timeout) throws Exception { synchronized(waitingAckMessages) { if(waitingAckMessages.size() >= bufferSize) { waitingAckMessages.wait(timeout); if(waitingAckMessages.size() >= bufferSize) { throw new TimeoutException("fail to send the message in " + timeout + "ms") ; } } client.post(path, toBinData(message)); sendCount++ ; String messageId = message.getHeader().getKey() ; waitingAckMessages.put(messageId, message) ; } }
// Path: src/main/java/com/neverwinterdp/sparkngin/Ack.java // public class Ack implements Serializable { // static public enum Status { OK, ERROR, NOT_AVAIBLE } // // private Object messageId ; // private Status status; // private String message; // // public Object getMessageId() { return messageId; } // public void setMessageId(Object objectId) { // this.messageId = objectId; // } // // public Status getStatus() { // return status; // } // // public void setStatus(Status status) { // this.status = status; // } // // public String getMessage() { // return message; // } // // public void setMessage(String message) { // this.message = message; // } // } // Path: src/main/java/com/neverwinterdp/sparkngin/http/AbstractHttpSparknginClient.java import io.netty.handler.codec.http.HttpContent; import io.netty.handler.codec.http.HttpResponse; import io.netty.handler.codec.http.QueryStringEncoder; import java.util.LinkedHashMap; import java.util.Map; import java.util.concurrent.TimeoutException; import com.neverwinterdp.message.Message; import com.neverwinterdp.netty.http.client.AsyncHttpClient; import com.neverwinterdp.netty.http.client.ResponseHandler; import com.neverwinterdp.sparkngin.Ack; if(waitingAckMessages.size() >= bufferSize) { waitingAckMessages.wait(timeout); if(waitingAckMessages.size() >= bufferSize) { throw new TimeoutException("fail to send the message in " + timeout + "ms") ; } } QueryStringEncoder encoder = new QueryStringEncoder(path); encoder.addParam("data", toStringData(message)); client.get(encoder.toString()); sendCount++ ; String messageId = message.getHeader().getKey() ; waitingAckMessages.put(messageId, message) ; } } public void sendPost(Message message, long timeout) throws Exception { synchronized(waitingAckMessages) { if(waitingAckMessages.size() >= bufferSize) { waitingAckMessages.wait(timeout); if(waitingAckMessages.size() >= bufferSize) { throw new TimeoutException("fail to send the message in " + timeout + "ms") ; } } client.post(path, toBinData(message)); sendCount++ ; String messageId = message.getHeader().getKey() ; waitingAckMessages.put(messageId, message) ; } }
public void onFailedMessage(Ack ack, Message message) {
DemandCube/Sparkngin
src/main/java/com/neverwinterdp/sparkngin/http/JBinaryHttpSparknginClient.java
// Path: src/main/java/com/neverwinterdp/sparkngin/Ack.java // public class Ack implements Serializable { // static public enum Status { OK, ERROR, NOT_AVAIBLE } // // private Object messageId ; // private Status status; // private String message; // // public Object getMessageId() { return messageId; } // public void setMessageId(Object objectId) { // this.messageId = objectId; // } // // public Status getStatus() { // return status; // } // // public void setStatus(Status status) { // this.status = status; // } // // public String getMessage() { // return message; // } // // public void setMessage(String message) { // this.message = message; // } // }
import java.io.IOException; import io.netty.buffer.ByteBuf; import io.netty.handler.codec.http.HttpContent; import com.neverwinterdp.message.Message; import com.neverwinterdp.sparkngin.Ack; import com.neverwinterdp.util.IOUtil; import com.neverwinterdp.util.JSONSerializer;
package com.neverwinterdp.sparkngin.http; public class JBinaryHttpSparknginClient extends AbstractHttpSparknginClient { public JBinaryHttpSparknginClient(String host, int port, int bufferSize, boolean connect) throws Exception { super(host, port, bufferSize, connect) ; setPath("/message/jbinary") ; }
// Path: src/main/java/com/neverwinterdp/sparkngin/Ack.java // public class Ack implements Serializable { // static public enum Status { OK, ERROR, NOT_AVAIBLE } // // private Object messageId ; // private Status status; // private String message; // // public Object getMessageId() { return messageId; } // public void setMessageId(Object objectId) { // this.messageId = objectId; // } // // public Status getStatus() { // return status; // } // // public void setStatus(Status status) { // this.status = status; // } // // public String getMessage() { // return message; // } // // public void setMessage(String message) { // this.message = message; // } // } // Path: src/main/java/com/neverwinterdp/sparkngin/http/JBinaryHttpSparknginClient.java import java.io.IOException; import io.netty.buffer.ByteBuf; import io.netty.handler.codec.http.HttpContent; import com.neverwinterdp.message.Message; import com.neverwinterdp.sparkngin.Ack; import com.neverwinterdp.util.IOUtil; import com.neverwinterdp.util.JSONSerializer; package com.neverwinterdp.sparkngin.http; public class JBinaryHttpSparknginClient extends AbstractHttpSparknginClient { public JBinaryHttpSparknginClient(String host, int port, int bufferSize, boolean connect) throws Exception { super(host, port, bufferSize, connect) ; setPath("/message/jbinary") ; }
protected Ack toAck(HttpContent content) {
DemandCube/Sparkngin
src/main/java/com/neverwinterdp/sparkngin/http/JSONHttpSparknginClient.java
// Path: src/main/java/com/neverwinterdp/sparkngin/Ack.java // public class Ack implements Serializable { // static public enum Status { OK, ERROR, NOT_AVAIBLE } // // private Object messageId ; // private Status status; // private String message; // // public Object getMessageId() { return messageId; } // public void setMessageId(Object objectId) { // this.messageId = objectId; // } // // public Status getStatus() { // return status; // } // // public void setStatus(Status status) { // this.status = status; // } // // public String getMessage() { // return message; // } // // public void setMessage(String message) { // this.message = message; // } // }
import io.netty.handler.codec.http.HttpContent; import io.netty.util.CharsetUtil; import com.neverwinterdp.message.Message; import com.neverwinterdp.sparkngin.Ack; import com.neverwinterdp.util.JSONSerializer;
package com.neverwinterdp.sparkngin.http; public class JSONHttpSparknginClient extends AbstractHttpSparknginClient { public JSONHttpSparknginClient(String host, int port, int bufferSize, boolean connect) throws Exception { super(host, port, bufferSize, connect) ; setPath("/message/json") ; }
// Path: src/main/java/com/neverwinterdp/sparkngin/Ack.java // public class Ack implements Serializable { // static public enum Status { OK, ERROR, NOT_AVAIBLE } // // private Object messageId ; // private Status status; // private String message; // // public Object getMessageId() { return messageId; } // public void setMessageId(Object objectId) { // this.messageId = objectId; // } // // public Status getStatus() { // return status; // } // // public void setStatus(Status status) { // this.status = status; // } // // public String getMessage() { // return message; // } // // public void setMessage(String message) { // this.message = message; // } // } // Path: src/main/java/com/neverwinterdp/sparkngin/http/JSONHttpSparknginClient.java import io.netty.handler.codec.http.HttpContent; import io.netty.util.CharsetUtil; import com.neverwinterdp.message.Message; import com.neverwinterdp.sparkngin.Ack; import com.neverwinterdp.util.JSONSerializer; package com.neverwinterdp.sparkngin.http; public class JSONHttpSparknginClient extends AbstractHttpSparknginClient { public JSONHttpSparknginClient(String host, int port, int bufferSize, boolean connect) throws Exception { super(host, port, bufferSize, connect) ; setPath("/message/json") ; }
protected Ack toAck(HttpContent content) {
JoelGodOfwar/SinglePlayerSleep
1.13_2.13.46/src/com/github/joelgodofwar/sps/api/YmlConfiguration.java
// Path: 1.13_2.13.45.D3/src/main/java/jdk/internal/joptsimple/internal/Strings.java // public final class Strings { // public static final String EMPTY = ""; // public static final String LINE_SEPARATOR = getProperty( "line.separator" ); // // private Strings() { // throw new UnsupportedOperationException(); // } // // /** // * Gives a string consisting of the given character repeated the given number of times. // * // * @param ch the character to repeat // * @param count how many times to repeat the character // * @return the resultant string // */ // public static String repeat( char ch, int count ) { // StringBuilder buffer = new StringBuilder(); // // for ( int i = 0; i < count; ++i ) // buffer.append( ch ); // // return buffer.toString(); // } // // /** // * Tells whether the given string is either {@code} or consists solely of whitespace characters. // * // * @param target string to check // * @return {@code true} if the target string is null or empty // */ // public static boolean isNullOrEmpty( String target ) { // return target == null || target.isEmpty(); // } // // // /** // * Gives a string consisting of a given string prepended and appended with surrounding characters. // * // * @param target a string // * @param begin character to prepend // * @param end character to append // * @return the surrounded string // */ // public static String surround( String target, char begin, char end ) { // return begin + target + end; // } // // /** // * Gives a string consisting of the elements of a given array of strings, each separated by a given separator // * string. // * // * @param pieces the strings to join // * @param separator the separator // * @return the joined string // */ // public static String join( String[] pieces, String separator ) { // return join( asList( pieces ), separator ); // } // // /** // * Gives a string consisting of the string representations of the elements of a given array of objects, // * each separated by a given separator string. // * // * @param pieces the elements whose string representations are to be joined // * @param separator the separator // * @return the joined string // */ // public static String join( Iterable<String> pieces, String separator ) { // StringBuilder buffer = new StringBuilder(); // // for ( Iterator<String> iter = pieces.iterator(); iter.hasNext(); ) { // buffer.append( iter.next() ); // // if ( iter.hasNext() ) // buffer.append( separator ); // } // // return buffer.toString(); // } // }
import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; import jdk.internal.joptsimple.internal.Strings; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConstructor; import org.bukkit.configuration.file.YamlRepresenter; import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.representer.Representer; import com.google.common.base.Charsets;
package com.github.joelgodofwar.sps.api; /* * @author: Aoife (Josh) * @date: 2020-04-25 * @project: WarpConverter */ public class YmlConfiguration extends YamlConfiguration { private final DumperOptions yamlOptions = new DumperOptions(); private final Representer yamlRepresenter = new YamlRepresenter(); private final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions); private Map<Integer, String> commentContainer = new HashMap<>(); public void save(File file) throws IOException { Validate.notNull(file); try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8)) { writer.write(saveToString()); } } public static void saveConfig(File file, YmlConfiguration config) { try { config.save(file); } catch (IOException e) { e.printStackTrace(); } } @Override public String saveToString(){ yamlOptions.setIndent(options().indent()); yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); String header = "";//buildHeader(); String dump = yaml.dump(getValues(false)); if (dump.equals(BLANK_CONFIG)) {
// Path: 1.13_2.13.45.D3/src/main/java/jdk/internal/joptsimple/internal/Strings.java // public final class Strings { // public static final String EMPTY = ""; // public static final String LINE_SEPARATOR = getProperty( "line.separator" ); // // private Strings() { // throw new UnsupportedOperationException(); // } // // /** // * Gives a string consisting of the given character repeated the given number of times. // * // * @param ch the character to repeat // * @param count how many times to repeat the character // * @return the resultant string // */ // public static String repeat( char ch, int count ) { // StringBuilder buffer = new StringBuilder(); // // for ( int i = 0; i < count; ++i ) // buffer.append( ch ); // // return buffer.toString(); // } // // /** // * Tells whether the given string is either {@code} or consists solely of whitespace characters. // * // * @param target string to check // * @return {@code true} if the target string is null or empty // */ // public static boolean isNullOrEmpty( String target ) { // return target == null || target.isEmpty(); // } // // // /** // * Gives a string consisting of a given string prepended and appended with surrounding characters. // * // * @param target a string // * @param begin character to prepend // * @param end character to append // * @return the surrounded string // */ // public static String surround( String target, char begin, char end ) { // return begin + target + end; // } // // /** // * Gives a string consisting of the elements of a given array of strings, each separated by a given separator // * string. // * // * @param pieces the strings to join // * @param separator the separator // * @return the joined string // */ // public static String join( String[] pieces, String separator ) { // return join( asList( pieces ), separator ); // } // // /** // * Gives a string consisting of the string representations of the elements of a given array of objects, // * each separated by a given separator string. // * // * @param pieces the elements whose string representations are to be joined // * @param separator the separator // * @return the joined string // */ // public static String join( Iterable<String> pieces, String separator ) { // StringBuilder buffer = new StringBuilder(); // // for ( Iterator<String> iter = pieces.iterator(); iter.hasNext(); ) { // buffer.append( iter.next() ); // // if ( iter.hasNext() ) // buffer.append( separator ); // } // // return buffer.toString(); // } // } // Path: 1.13_2.13.46/src/com/github/joelgodofwar/sps/api/YmlConfiguration.java import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; import java.util.HashMap; import java.util.Map; import java.util.logging.Level; import jdk.internal.joptsimple.internal.Strings; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConstructor; import org.bukkit.configuration.file.YamlRepresenter; import org.yaml.snakeyaml.DumperOptions; import org.yaml.snakeyaml.Yaml; import org.yaml.snakeyaml.representer.Representer; import com.google.common.base.Charsets; package com.github.joelgodofwar.sps.api; /* * @author: Aoife (Josh) * @date: 2020-04-25 * @project: WarpConverter */ public class YmlConfiguration extends YamlConfiguration { private final DumperOptions yamlOptions = new DumperOptions(); private final Representer yamlRepresenter = new YamlRepresenter(); private final Yaml yaml = new Yaml(new YamlConstructor(), yamlRepresenter, yamlOptions); private Map<Integer, String> commentContainer = new HashMap<>(); public void save(File file) throws IOException { Validate.notNull(file); try (Writer writer = new OutputStreamWriter(new FileOutputStream(file), Charsets.UTF_8)) { writer.write(saveToString()); } } public static void saveConfig(File file, YmlConfiguration config) { try { config.save(file); } catch (IOException e) { e.printStackTrace(); } } @Override public String saveToString(){ yamlOptions.setIndent(options().indent()); yamlOptions.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); yamlRepresenter.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK); String header = "";//buildHeader(); String dump = yaml.dump(getValues(false)); if (dump.equals(BLANK_CONFIG)) {
dump = Strings.EMPTY;
JoelGodOfwar/SinglePlayerSleep
1.13_2.13.46/src/com/github/joelgodofwar/sps/api/UpdateChecker.java
// Path: 1.13_2.13.46/src/com/github/joelgodofwar/sps/util/Ansi.java // public class Ansi { // public static final ChatColor AQUA = ChatColor.AQUA; // public static final ChatColor BLACK = ChatColor.BLACK; // public static final ChatColor BLUE = ChatColor.BLUE; // public static final ChatColor DARK_AQUA = ChatColor.DARK_AQUA; // public static final ChatColor DARK_BLUE = ChatColor.DARK_BLUE; // public static final ChatColor DARK_GRAY = ChatColor.DARK_GRAY; // public static final ChatColor DARK_GREEN = ChatColor.DARK_GREEN; // public static final ChatColor DARK_PURPLE = ChatColor.DARK_PURPLE; // public static final ChatColor DARK_RED = ChatColor.DARK_RED; // public static final ChatColor GOLD = ChatColor.GOLD; // public static final ChatColor GRAY = ChatColor.GRAY; // public static final ChatColor GREEN = ChatColor.GREEN; // public static final ChatColor MAGENTA = ChatColor.LIGHT_PURPLE; // public static final ChatColor RED = ChatColor.RED; // public static final ChatColor WHITE = ChatColor.WHITE; // public static final ChatColor YELLOW = ChatColor.YELLOW; // // public static final ChatColor BOLD = ChatColor.BOLD; // public static final ChatColor ITALIC = ChatColor.ITALIC; // public static final ChatColor MAGIC = ChatColor.MAGIC; // public static final ChatColor RESET = ChatColor.RESET; // public static final ChatColor STRIKETHROUGH = ChatColor.STRIKETHROUGH; // public static final ChatColor UNDERLINE = ChatColor.UNDERLINE; // // // // }
import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import org.apache.commons.lang.math.NumberUtils; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import com.github.joelgodofwar.sps.util.Ansi;
package com.github.joelgodofwar.sps.api; public class UpdateChecker { private static int project; private URL checkURL; private String newVersion; private String newMinVers; private String oldVersion; private String oldMinVers; @SuppressWarnings("unused") private JavaPlugin plugin; String[] strVersionNew; // [0]=1.14 [1]=1.0.0.? String[] strVersionCurrent; // [0]=1.14 [1]=1.0.0.? String URLString = "https://github.com/JoelGodOfwar/SinglePlayerSleep/raw/master/versioncheck/"; String URLFile = "/version.txt"; public UpdateChecker(JavaPlugin plugin, int projectID) { this.plugin = plugin; project = projectID; oldVersion = plugin.getDescription().getVersion(); try { checkURL = new URL(URLString + oldVersion.substring(0, 4) + URLFile); }catch(MalformedURLException e) {
// Path: 1.13_2.13.46/src/com/github/joelgodofwar/sps/util/Ansi.java // public class Ansi { // public static final ChatColor AQUA = ChatColor.AQUA; // public static final ChatColor BLACK = ChatColor.BLACK; // public static final ChatColor BLUE = ChatColor.BLUE; // public static final ChatColor DARK_AQUA = ChatColor.DARK_AQUA; // public static final ChatColor DARK_BLUE = ChatColor.DARK_BLUE; // public static final ChatColor DARK_GRAY = ChatColor.DARK_GRAY; // public static final ChatColor DARK_GREEN = ChatColor.DARK_GREEN; // public static final ChatColor DARK_PURPLE = ChatColor.DARK_PURPLE; // public static final ChatColor DARK_RED = ChatColor.DARK_RED; // public static final ChatColor GOLD = ChatColor.GOLD; // public static final ChatColor GRAY = ChatColor.GRAY; // public static final ChatColor GREEN = ChatColor.GREEN; // public static final ChatColor MAGENTA = ChatColor.LIGHT_PURPLE; // public static final ChatColor RED = ChatColor.RED; // public static final ChatColor WHITE = ChatColor.WHITE; // public static final ChatColor YELLOW = ChatColor.YELLOW; // // public static final ChatColor BOLD = ChatColor.BOLD; // public static final ChatColor ITALIC = ChatColor.ITALIC; // public static final ChatColor MAGIC = ChatColor.MAGIC; // public static final ChatColor RESET = ChatColor.RESET; // public static final ChatColor STRIKETHROUGH = ChatColor.STRIKETHROUGH; // public static final ChatColor UNDERLINE = ChatColor.UNDERLINE; // // // // } // Path: 1.13_2.13.46/src/com/github/joelgodofwar/sps/api/UpdateChecker.java import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import org.apache.commons.lang.math.NumberUtils; import org.bukkit.Bukkit; import org.bukkit.plugin.java.JavaPlugin; import com.github.joelgodofwar.sps.util.Ansi; package com.github.joelgodofwar.sps.api; public class UpdateChecker { private static int project; private URL checkURL; private String newVersion; private String newMinVers; private String oldVersion; private String oldMinVers; @SuppressWarnings("unused") private JavaPlugin plugin; String[] strVersionNew; // [0]=1.14 [1]=1.0.0.? String[] strVersionCurrent; // [0]=1.14 [1]=1.0.0.? String URLString = "https://github.com/JoelGodOfwar/SinglePlayerSleep/raw/master/versioncheck/"; String URLFile = "/version.txt"; public UpdateChecker(JavaPlugin plugin, int projectID) { this.plugin = plugin; project = projectID; oldVersion = plugin.getDescription().getVersion(); try { checkURL = new URL(URLString + oldVersion.substring(0, 4) + URLFile); }catch(MalformedURLException e) {
Bukkit.getLogger().warning(Ansi.RED + "Could not connect to update server.");
tonilopezmr/Android-Examples
dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/di/MainComponent.java
// Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/view/MainActivity.java // public class MainActivity extends AppCompatActivity implements PersonListPresenter.View{ // // RecyclerView recyclerView; // View emptyCase; // View loadingView; // // private PersonAdapter adapter; // // @Inject // PersonListPresenter presenter; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_main); // // initDependencyInjector(); // initToolbar(); // initFloatinActionButton(); // initRecyclerView(); // initEmptyCaseView(); // initLoadingView(); // // // presenter.setView(this); // presenter.init(); // } // // private void initDependencyInjector() { // PersonApplication app = (PersonApplication) getApplication(); // app.getMainComponent().inject(this); // } // // private void initLoadingView() { // loadingView = findViewById(R.id.progress_bar); // } // // private void initEmptyCaseView() { // emptyCase = findViewById(R.id.tv_empty_case); // } // // private void initRecyclerView() { // recyclerView = (RecyclerView) findViewById(R.id.recycler_view); // recyclerView.setLayoutManager(new LinearLayoutManager(this)); // recyclerView.setHasFixedSize(true); // adapter = new PersonAdapter(); // recyclerView.setAdapter(adapter); // } // // private void initFloatinActionButton() { // FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); // fab.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) // .setAction("Action", null).show(); // } // }); // } // // @Override // protected void onPause() { // super.onPause(); // presenter.onPause(); // } // // private void initToolbar() { // Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); // setSupportActionBar(toolbar); // } // // @Override // public boolean onCreateOptionsMenu(Menu menu) { // // Inflate the menu; this adds items to the action bar if it is present. // getMenuInflater().inflate(R.menu.menu_main, menu); // return true; // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // // Handle action bar item clicks here. The action bar will // // automatically handle clicks on the Home/Up button, so long // // as you specify a parent activity in AndroidManifest.xml. // int id = item.getItemId(); // // //noinspection SimplifiableIfStatement // if (id == R.id.action_settings) { // return true; // } // // return super.onOptionsItemSelected(item); // } // // @Override // public void showEmptyView() { // emptyCase.setVisibility(View.VISIBLE); // } // // @Override // public void hideEmptyView() { // emptyCase.setVisibility(View.GONE); // } // // @Override // public void showPersons(List<Person> persons) { // adapter.addAll(persons); // adapter.notifyDataSetChanged(); // } // // @Override // public void showError() { // Snackbar.make(findViewById(R.id.coordinator_layout), "RAMDOM ERROR", Snackbar.LENGTH_SHORT).show(); // } // // @Override // public void showLoading() { // loadingView.setVisibility(View.VISIBLE); // } // // @Override // public void hideLoading() { // loadingView.setVisibility(View.GONE); // } // }
import com.tonilopezmr.dagger2rxjava.view.MainActivity; import javax.inject.Named; import javax.inject.Singleton; import dagger.Component; import rx.Scheduler;
package com.tonilopezmr.dagger2rxjava.di; /** * @author Antonio López. */ @Singleton @Component(modules = MainModule.class) public interface MainComponent {
// Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/view/MainActivity.java // public class MainActivity extends AppCompatActivity implements PersonListPresenter.View{ // // RecyclerView recyclerView; // View emptyCase; // View loadingView; // // private PersonAdapter adapter; // // @Inject // PersonListPresenter presenter; // // @Override // protected void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // setContentView(R.layout.activity_main); // // initDependencyInjector(); // initToolbar(); // initFloatinActionButton(); // initRecyclerView(); // initEmptyCaseView(); // initLoadingView(); // // // presenter.setView(this); // presenter.init(); // } // // private void initDependencyInjector() { // PersonApplication app = (PersonApplication) getApplication(); // app.getMainComponent().inject(this); // } // // private void initLoadingView() { // loadingView = findViewById(R.id.progress_bar); // } // // private void initEmptyCaseView() { // emptyCase = findViewById(R.id.tv_empty_case); // } // // private void initRecyclerView() { // recyclerView = (RecyclerView) findViewById(R.id.recycler_view); // recyclerView.setLayoutManager(new LinearLayoutManager(this)); // recyclerView.setHasFixedSize(true); // adapter = new PersonAdapter(); // recyclerView.setAdapter(adapter); // } // // private void initFloatinActionButton() { // FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab); // fab.setOnClickListener(new View.OnClickListener() { // @Override // public void onClick(View view) { // Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG) // .setAction("Action", null).show(); // } // }); // } // // @Override // protected void onPause() { // super.onPause(); // presenter.onPause(); // } // // private void initToolbar() { // Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); // setSupportActionBar(toolbar); // } // // @Override // public boolean onCreateOptionsMenu(Menu menu) { // // Inflate the menu; this adds items to the action bar if it is present. // getMenuInflater().inflate(R.menu.menu_main, menu); // return true; // } // // @Override // public boolean onOptionsItemSelected(MenuItem item) { // // Handle action bar item clicks here. The action bar will // // automatically handle clicks on the Home/Up button, so long // // as you specify a parent activity in AndroidManifest.xml. // int id = item.getItemId(); // // //noinspection SimplifiableIfStatement // if (id == R.id.action_settings) { // return true; // } // // return super.onOptionsItemSelected(item); // } // // @Override // public void showEmptyView() { // emptyCase.setVisibility(View.VISIBLE); // } // // @Override // public void hideEmptyView() { // emptyCase.setVisibility(View.GONE); // } // // @Override // public void showPersons(List<Person> persons) { // adapter.addAll(persons); // adapter.notifyDataSetChanged(); // } // // @Override // public void showError() { // Snackbar.make(findViewById(R.id.coordinator_layout), "RAMDOM ERROR", Snackbar.LENGTH_SHORT).show(); // } // // @Override // public void showLoading() { // loadingView.setVisibility(View.VISIBLE); // } // // @Override // public void hideLoading() { // loadingView.setVisibility(View.GONE); // } // } // Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/di/MainComponent.java import com.tonilopezmr.dagger2rxjava.view.MainActivity; import javax.inject.Named; import javax.inject.Singleton; import dagger.Component; import rx.Scheduler; package com.tonilopezmr.dagger2rxjava.di; /** * @author Antonio López. */ @Singleton @Component(modules = MainModule.class) public interface MainComponent {
void inject(MainActivity activity);
tonilopezmr/Android-Examples
dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/presenter/PersonListPresenter.java
// Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/domain/Person.java // public class Person { // // private String name; // // public Person(String name) { // this.name = name; // } // // public String getName() { // return name; // } // } // // Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/domain/usecase/GetAllPersonsUseCase.java // public class GetAllPersonsUseCase extends UseCase<List<Person>>{ // private final PersonRepositoryImp repository; // // private final Scheduler uiThread; // private final Scheduler executorThread; // // @Inject // public GetAllPersonsUseCase(PersonRepositoryImp repository, @Named("mainThread") Scheduler uiThread, @Named("executorThread") Scheduler executorThread) { // this.repository = repository; // this.uiThread = uiThread; // this.executorThread = executorThread; // } // // @Override // protected Observable<List<Person>> buildUseCaseObservable() { // return repository.getAll() // .observeOn(uiThread) // .subscribeOn(executorThread); // } // }
import com.tonilopezmr.dagger2rxjava.domain.Person; import com.tonilopezmr.dagger2rxjava.domain.usecase.GetAllPersonsUseCase; import java.util.List; import javax.inject.Inject; import rx.Subscription;
package com.tonilopezmr.dagger2rxjava.presenter; /** * @author Antonio López. */ public class PersonListPresenter implements Presenter<PersonListPresenter.View> { private final GetAllPersonsUseCase personsUseCase; private PersonListPresenter.View view; private Subscription personsSubscription; @Inject public PersonListPresenter(GetAllPersonsUseCase personsUseCase) { this.personsUseCase = personsUseCase; } @Override public void init() { askForPersons(); } private void askForPersons() { personsSubscription = personsUseCase.execute() .subscribe(this::onPersonReceived, this::showError); }
// Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/domain/Person.java // public class Person { // // private String name; // // public Person(String name) { // this.name = name; // } // // public String getName() { // return name; // } // } // // Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/domain/usecase/GetAllPersonsUseCase.java // public class GetAllPersonsUseCase extends UseCase<List<Person>>{ // private final PersonRepositoryImp repository; // // private final Scheduler uiThread; // private final Scheduler executorThread; // // @Inject // public GetAllPersonsUseCase(PersonRepositoryImp repository, @Named("mainThread") Scheduler uiThread, @Named("executorThread") Scheduler executorThread) { // this.repository = repository; // this.uiThread = uiThread; // this.executorThread = executorThread; // } // // @Override // protected Observable<List<Person>> buildUseCaseObservable() { // return repository.getAll() // .observeOn(uiThread) // .subscribeOn(executorThread); // } // } // Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/presenter/PersonListPresenter.java import com.tonilopezmr.dagger2rxjava.domain.Person; import com.tonilopezmr.dagger2rxjava.domain.usecase.GetAllPersonsUseCase; import java.util.List; import javax.inject.Inject; import rx.Subscription; package com.tonilopezmr.dagger2rxjava.presenter; /** * @author Antonio López. */ public class PersonListPresenter implements Presenter<PersonListPresenter.View> { private final GetAllPersonsUseCase personsUseCase; private PersonListPresenter.View view; private Subscription personsSubscription; @Inject public PersonListPresenter(GetAllPersonsUseCase personsUseCase) { this.personsUseCase = personsUseCase; } @Override public void init() { askForPersons(); } private void askForPersons() { personsSubscription = personsUseCase.execute() .subscribe(this::onPersonReceived, this::showError); }
private void onPersonReceived(List<Person> persons) {
tonilopezmr/Android-Examples
animations/src/main/java/com/tonilopezmr/animations/MainActivity.java
// Path: animations/src/main/java/com/tonilopezmr/animations/adapter/SimpleStringRecyclerViewAdapter.java // public class SimpleStringRecyclerViewAdapter extends RecyclerView.Adapter<SimpleStringRecyclerViewAdapter.ViewHolder>{ // // private List<String> mValues; // // public SimpleStringRecyclerViewAdapter(List<String> mValues) { // this.mValues = mValues; // } // // @Override // public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View view = LayoutInflater.from(parent.getContext()) // .inflate(R.layout.list_item, parent, false); // return new ViewHolder(view); // } // // @Override // public void onBindViewHolder(ViewHolder holder, int position) { // holder.mTextView.setText(mValues.get(position)); // } // // @Override // public int getItemCount() { // return mValues.size(); // } // // public static class ViewHolder extends RecyclerView.ViewHolder { // // public final View mView; // public final TextView mTextView; // // public ViewHolder(View view) { // super(view); // mView = view; // mTextView = (TextView) view.findViewById(android.R.id.text1); // } // // @Override // public String toString() { // return super.toString() + " '" + mTextView.getText(); // } // } // }
import android.app.ActivityOptions; import android.content.Intent; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.view.View; import com.tonilopezmr.animations.adapter.SimpleStringRecyclerViewAdapter; import java.util.ArrayList; import java.util.List;
package com.tonilopezmr.animations; public class MainActivity extends AppCompatActivity { FloatingActionButton fab; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview); recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
// Path: animations/src/main/java/com/tonilopezmr/animations/adapter/SimpleStringRecyclerViewAdapter.java // public class SimpleStringRecyclerViewAdapter extends RecyclerView.Adapter<SimpleStringRecyclerViewAdapter.ViewHolder>{ // // private List<String> mValues; // // public SimpleStringRecyclerViewAdapter(List<String> mValues) { // this.mValues = mValues; // } // // @Override // public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { // View view = LayoutInflater.from(parent.getContext()) // .inflate(R.layout.list_item, parent, false); // return new ViewHolder(view); // } // // @Override // public void onBindViewHolder(ViewHolder holder, int position) { // holder.mTextView.setText(mValues.get(position)); // } // // @Override // public int getItemCount() { // return mValues.size(); // } // // public static class ViewHolder extends RecyclerView.ViewHolder { // // public final View mView; // public final TextView mTextView; // // public ViewHolder(View view) { // super(view); // mView = view; // mTextView = (TextView) view.findViewById(android.R.id.text1); // } // // @Override // public String toString() { // return super.toString() + " '" + mTextView.getText(); // } // } // } // Path: animations/src/main/java/com/tonilopezmr/animations/MainActivity.java import android.app.ActivityOptions; import android.content.Intent; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.view.View; import com.tonilopezmr.animations.adapter.SimpleStringRecyclerViewAdapter; import java.util.ArrayList; import java.util.List; package com.tonilopezmr.animations; public class MainActivity extends AppCompatActivity { FloatingActionButton fab; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerview); recyclerView.setLayoutManager(new LinearLayoutManager(recyclerView.getContext()));
recyclerView.setAdapter(new SimpleStringRecyclerViewAdapter(getList()));
tonilopezmr/Android-Examples
dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/view/MainActivity.java
// Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/PersonApplication.java // public class PersonApplication extends Application{ // // private MainComponent mainComponent; // // @Override public void onCreate() { // super.onCreate(); // mainComponent = DaggerMainComponent.builder() // .mainModule(new MainModule()) // .build(); // } // // public MainComponent getMainComponent() { // return mainComponent; // } // // @VisibleForTesting // public void setComponent(MainComponent mainComponent) { // this.mainComponent = mainComponent; // } // // } // // Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/domain/Person.java // public class Person { // // private String name; // // public Person(String name) { // this.name = name; // } // // public String getName() { // return name; // } // } // // Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/presenter/PersonListPresenter.java // public class PersonListPresenter implements Presenter<PersonListPresenter.View> { // // private final GetAllPersonsUseCase personsUseCase; // private PersonListPresenter.View view; // // private Subscription personsSubscription; // // @Inject // public PersonListPresenter(GetAllPersonsUseCase personsUseCase) { // this.personsUseCase = personsUseCase; // } // // @Override // public void init() { // askForPersons(); // } // // private void askForPersons() { // personsSubscription = personsUseCase.execute() // .subscribe(this::onPersonReceived, this::showError); // } // // private void onPersonReceived(List<Person> persons) { // view.showPersons(persons); // view.hideLoading(); // if (persons.isEmpty()){ // view.showEmptyView(); // }else{ // view.hideEmptyView(); // } // } // // private void showError(Throwable error){ // view.hideLoading(); // view.showError(); // } // // @Override // public void setView(View view) { // this.view = view; // } // // @Override // public void onPause() { // personsSubscription.unsubscribe(); // } // // public interface View extends Presenter.View{ // void showEmptyView(); // void hideEmptyView(); // void showPersons(List<Person> persons); // void showError(); // } // }
import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.view.View; import com.tonilopezmr.dagger2rxjava.PersonApplication; import com.tonilopezmr.dagger2rxjava.R; import com.tonilopezmr.dagger2rxjava.domain.Person; import com.tonilopezmr.dagger2rxjava.presenter.PersonListPresenter; import java.util.List; import javax.inject.Inject;
package com.tonilopezmr.dagger2rxjava.view; /** * @author Antonio López. */ public class MainActivity extends AppCompatActivity implements PersonListPresenter.View{ RecyclerView recyclerView; View emptyCase; View loadingView; private PersonAdapter adapter; @Inject PersonListPresenter presenter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initDependencyInjector(); initToolbar(); initFloatinActionButton(); initRecyclerView(); initEmptyCaseView(); initLoadingView(); presenter.setView(this); presenter.init(); } private void initDependencyInjector() {
// Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/PersonApplication.java // public class PersonApplication extends Application{ // // private MainComponent mainComponent; // // @Override public void onCreate() { // super.onCreate(); // mainComponent = DaggerMainComponent.builder() // .mainModule(new MainModule()) // .build(); // } // // public MainComponent getMainComponent() { // return mainComponent; // } // // @VisibleForTesting // public void setComponent(MainComponent mainComponent) { // this.mainComponent = mainComponent; // } // // } // // Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/domain/Person.java // public class Person { // // private String name; // // public Person(String name) { // this.name = name; // } // // public String getName() { // return name; // } // } // // Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/presenter/PersonListPresenter.java // public class PersonListPresenter implements Presenter<PersonListPresenter.View> { // // private final GetAllPersonsUseCase personsUseCase; // private PersonListPresenter.View view; // // private Subscription personsSubscription; // // @Inject // public PersonListPresenter(GetAllPersonsUseCase personsUseCase) { // this.personsUseCase = personsUseCase; // } // // @Override // public void init() { // askForPersons(); // } // // private void askForPersons() { // personsSubscription = personsUseCase.execute() // .subscribe(this::onPersonReceived, this::showError); // } // // private void onPersonReceived(List<Person> persons) { // view.showPersons(persons); // view.hideLoading(); // if (persons.isEmpty()){ // view.showEmptyView(); // }else{ // view.hideEmptyView(); // } // } // // private void showError(Throwable error){ // view.hideLoading(); // view.showError(); // } // // @Override // public void setView(View view) { // this.view = view; // } // // @Override // public void onPause() { // personsSubscription.unsubscribe(); // } // // public interface View extends Presenter.View{ // void showEmptyView(); // void hideEmptyView(); // void showPersons(List<Person> persons); // void showError(); // } // } // Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/view/MainActivity.java import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.view.View; import com.tonilopezmr.dagger2rxjava.PersonApplication; import com.tonilopezmr.dagger2rxjava.R; import com.tonilopezmr.dagger2rxjava.domain.Person; import com.tonilopezmr.dagger2rxjava.presenter.PersonListPresenter; import java.util.List; import javax.inject.Inject; package com.tonilopezmr.dagger2rxjava.view; /** * @author Antonio López. */ public class MainActivity extends AppCompatActivity implements PersonListPresenter.View{ RecyclerView recyclerView; View emptyCase; View loadingView; private PersonAdapter adapter; @Inject PersonListPresenter presenter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); initDependencyInjector(); initToolbar(); initFloatinActionButton(); initRecyclerView(); initEmptyCaseView(); initLoadingView(); presenter.setView(this); presenter.init(); } private void initDependencyInjector() {
PersonApplication app = (PersonApplication) getApplication();
tonilopezmr/Android-Examples
dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/view/MainActivity.java
// Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/PersonApplication.java // public class PersonApplication extends Application{ // // private MainComponent mainComponent; // // @Override public void onCreate() { // super.onCreate(); // mainComponent = DaggerMainComponent.builder() // .mainModule(new MainModule()) // .build(); // } // // public MainComponent getMainComponent() { // return mainComponent; // } // // @VisibleForTesting // public void setComponent(MainComponent mainComponent) { // this.mainComponent = mainComponent; // } // // } // // Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/domain/Person.java // public class Person { // // private String name; // // public Person(String name) { // this.name = name; // } // // public String getName() { // return name; // } // } // // Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/presenter/PersonListPresenter.java // public class PersonListPresenter implements Presenter<PersonListPresenter.View> { // // private final GetAllPersonsUseCase personsUseCase; // private PersonListPresenter.View view; // // private Subscription personsSubscription; // // @Inject // public PersonListPresenter(GetAllPersonsUseCase personsUseCase) { // this.personsUseCase = personsUseCase; // } // // @Override // public void init() { // askForPersons(); // } // // private void askForPersons() { // personsSubscription = personsUseCase.execute() // .subscribe(this::onPersonReceived, this::showError); // } // // private void onPersonReceived(List<Person> persons) { // view.showPersons(persons); // view.hideLoading(); // if (persons.isEmpty()){ // view.showEmptyView(); // }else{ // view.hideEmptyView(); // } // } // // private void showError(Throwable error){ // view.hideLoading(); // view.showError(); // } // // @Override // public void setView(View view) { // this.view = view; // } // // @Override // public void onPause() { // personsSubscription.unsubscribe(); // } // // public interface View extends Presenter.View{ // void showEmptyView(); // void hideEmptyView(); // void showPersons(List<Person> persons); // void showError(); // } // }
import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.view.View; import com.tonilopezmr.dagger2rxjava.PersonApplication; import com.tonilopezmr.dagger2rxjava.R; import com.tonilopezmr.dagger2rxjava.domain.Person; import com.tonilopezmr.dagger2rxjava.presenter.PersonListPresenter; import java.util.List; import javax.inject.Inject;
getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } @Override public void showEmptyView() { emptyCase.setVisibility(View.VISIBLE); } @Override public void hideEmptyView() { emptyCase.setVisibility(View.GONE); } @Override
// Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/PersonApplication.java // public class PersonApplication extends Application{ // // private MainComponent mainComponent; // // @Override public void onCreate() { // super.onCreate(); // mainComponent = DaggerMainComponent.builder() // .mainModule(new MainModule()) // .build(); // } // // public MainComponent getMainComponent() { // return mainComponent; // } // // @VisibleForTesting // public void setComponent(MainComponent mainComponent) { // this.mainComponent = mainComponent; // } // // } // // Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/domain/Person.java // public class Person { // // private String name; // // public Person(String name) { // this.name = name; // } // // public String getName() { // return name; // } // } // // Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/presenter/PersonListPresenter.java // public class PersonListPresenter implements Presenter<PersonListPresenter.View> { // // private final GetAllPersonsUseCase personsUseCase; // private PersonListPresenter.View view; // // private Subscription personsSubscription; // // @Inject // public PersonListPresenter(GetAllPersonsUseCase personsUseCase) { // this.personsUseCase = personsUseCase; // } // // @Override // public void init() { // askForPersons(); // } // // private void askForPersons() { // personsSubscription = personsUseCase.execute() // .subscribe(this::onPersonReceived, this::showError); // } // // private void onPersonReceived(List<Person> persons) { // view.showPersons(persons); // view.hideLoading(); // if (persons.isEmpty()){ // view.showEmptyView(); // }else{ // view.hideEmptyView(); // } // } // // private void showError(Throwable error){ // view.hideLoading(); // view.showError(); // } // // @Override // public void setView(View view) { // this.view = view; // } // // @Override // public void onPause() { // personsSubscription.unsubscribe(); // } // // public interface View extends Presenter.View{ // void showEmptyView(); // void hideEmptyView(); // void showPersons(List<Person> persons); // void showError(); // } // } // Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/view/MainActivity.java import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.Menu; import android.view.MenuItem; import android.view.View; import com.tonilopezmr.dagger2rxjava.PersonApplication; import com.tonilopezmr.dagger2rxjava.R; import com.tonilopezmr.dagger2rxjava.domain.Person; import com.tonilopezmr.dagger2rxjava.presenter.PersonListPresenter; import java.util.List; import javax.inject.Inject; getMenuInflater().inflate(R.menu.menu_main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); //noinspection SimplifiableIfStatement if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } @Override public void showEmptyView() { emptyCase.setVisibility(View.VISIBLE); } @Override public void hideEmptyView() { emptyCase.setVisibility(View.GONE); } @Override
public void showPersons(List<Person> persons) {
tonilopezmr/Android-Examples
dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/PersonApplication.java
// Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/di/MainComponent.java // @Singleton // @Component(modules = MainModule.class) public interface MainComponent { // // void inject(MainActivity activity); // // @Named("executorThread") Scheduler executorThread(); // @Named("mainThread") Scheduler mainThread(); // } // // Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/di/MainModule.java // @Module public class MainModule { // // @Provides @Singleton public PersonRepositoryImp providePersonRepository(){ // return new PersonRepositoryImp(); // } // // @Provides @Named("executorThread") public Scheduler provideExecutorThread(){ // return Schedulers.newThread(); // } // // @Provides @Named("mainThread") public Scheduler provideMainThread(){ // return AndroidSchedulers.mainThread(); // } // }
import android.app.Application; import android.support.annotation.VisibleForTesting; import com.tonilopezmr.dagger2rxjava.di.DaggerMainComponent; import com.tonilopezmr.dagger2rxjava.di.MainComponent; import com.tonilopezmr.dagger2rxjava.di.MainModule;
package com.tonilopezmr.dagger2rxjava; /** * @author Antonio López. */ public class PersonApplication extends Application{ private MainComponent mainComponent; @Override public void onCreate() { super.onCreate(); mainComponent = DaggerMainComponent.builder()
// Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/di/MainComponent.java // @Singleton // @Component(modules = MainModule.class) public interface MainComponent { // // void inject(MainActivity activity); // // @Named("executorThread") Scheduler executorThread(); // @Named("mainThread") Scheduler mainThread(); // } // // Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/di/MainModule.java // @Module public class MainModule { // // @Provides @Singleton public PersonRepositoryImp providePersonRepository(){ // return new PersonRepositoryImp(); // } // // @Provides @Named("executorThread") public Scheduler provideExecutorThread(){ // return Schedulers.newThread(); // } // // @Provides @Named("mainThread") public Scheduler provideMainThread(){ // return AndroidSchedulers.mainThread(); // } // } // Path: dagger2-rxjava/src/main/java/com/tonilopezmr/dagger2rxjava/PersonApplication.java import android.app.Application; import android.support.annotation.VisibleForTesting; import com.tonilopezmr.dagger2rxjava.di.DaggerMainComponent; import com.tonilopezmr.dagger2rxjava.di.MainComponent; import com.tonilopezmr.dagger2rxjava.di.MainModule; package com.tonilopezmr.dagger2rxjava; /** * @author Antonio López. */ public class PersonApplication extends Application{ private MainComponent mainComponent; @Override public void onCreate() { super.onCreate(); mainComponent = DaggerMainComponent.builder()
.mainModule(new MainModule())
liuguangqiang/Idaily
app/src/main/java/com/liuguangqiang/idaily/feature/detail/StoryViewModel.java
// Path: app/src/main/java/com/liuguangqiang/idaily/api/ServiceFactory.java // public class ServiceFactory { // // private static String HOST_NAME = "http://news-at.zhihu.com/api/4/"; // // private static final ServiceFactory instance = new ServiceFactory(); // // public static ServiceFactory getInstance() { // return instance; // } // // private Retrofit retrofit; // // public ServiceFactory() { // createRetrofit(); // } // // private void createRetrofit() { // HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); // interceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS); // OkHttpClient okHttpClient = new OkHttpClient.Builder() // .addInterceptor(interceptor) // .build(); // // retrofit = new Retrofit.Builder() // .baseUrl(HOST_NAME) // .client(okHttpClient) // .addConverterFactory(GsonConverterFactory.create()) // .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) // .build(); // } // // // public <T> T create(Class<?> clazz) { // return (T) retrofit.create(clazz); // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/entity/Story.java // public class Story extends BaseEntity implements Parcelable { // // public int id; // // public String title; // // public int type = 0; // // public List<String> images = new ArrayList<>(); // // public String image; // // public String body; // // public List<String> css; // // public String share_url; // // public String hint; // // public List<String> getCss() { // return css; // } // // public void setCss(List<String> css) { // this.css = css; // } // // public String getBody() { // return body; // } // // public void setBody(String body) { // this.body = body; // } // // public String getImage() { // return image; // } // // public void setImage(String image) { // this.image = image; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // // public List<String> getImages() { // return images; // } // // public void setImages(List<String> images) { // this.images = images; // } // // public int getType() { // return type; // } // // public void setType(int type) { // this.type = type; // } // // public Story() { // } // // public int getId() { // return id; // } // // public void setId(int id) { // this.id = id; // } // // @Override // public String toString() { // return "Story{" + // "id=" + id + // ", title='" + title + '\'' + // ", type=" + type + // ", images=" + images + // ", image='" + image + '\'' + // ", body='" + body + '\'' + // ", css=" + css + // '}'; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(this.id); // dest.writeString(this.title); // dest.writeInt(this.type); // dest.writeStringList(this.images); // dest.writeString(this.image); // dest.writeString(this.body); // dest.writeStringList(this.css); // dest.writeString(this.share_url); // } // // protected Story(Parcel in) { // this.id = in.readInt(); // this.title = in.readString(); // this.type = in.readInt(); // this.images = in.createStringArrayList(); // this.image = in.readString(); // this.body = in.readString(); // this.css = in.createStringArrayList(); // this.share_url = in.readString(); // } // // public static final Creator<Story> CREATOR = new Creator<Story>() { // public Story createFromParcel(Parcel source) { // return new Story(source); // } // // public Story[] newArray(int size) { // return new Story[size]; // } // }; // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_STORY; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/api/service/StoryService.java // public interface StoryService { // // @GET("story/{story_id}") // Observable<Story> getStory(@Path("story_id") int storyId); // // }
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; import android.os.Bundle; import com.liuguangqiang.idaily.api.ServiceFactory; import com.liuguangqiang.idaily.entity.Story; import com.liuguangqiang.idaily.api.service.StoryService; import io.reactivex.Observer; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers;
} } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getImage() { if (story == null) return ""; return story.getImage(); } public String getBody() { return getBody(storyLiveData.getValue()); } public void setStory(Story story) { storyLiveData.postValue(story); } public Story getStory() { return story; } public void getStory(int id) {
// Path: app/src/main/java/com/liuguangqiang/idaily/api/ServiceFactory.java // public class ServiceFactory { // // private static String HOST_NAME = "http://news-at.zhihu.com/api/4/"; // // private static final ServiceFactory instance = new ServiceFactory(); // // public static ServiceFactory getInstance() { // return instance; // } // // private Retrofit retrofit; // // public ServiceFactory() { // createRetrofit(); // } // // private void createRetrofit() { // HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); // interceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS); // OkHttpClient okHttpClient = new OkHttpClient.Builder() // .addInterceptor(interceptor) // .build(); // // retrofit = new Retrofit.Builder() // .baseUrl(HOST_NAME) // .client(okHttpClient) // .addConverterFactory(GsonConverterFactory.create()) // .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) // .build(); // } // // // public <T> T create(Class<?> clazz) { // return (T) retrofit.create(clazz); // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/entity/Story.java // public class Story extends BaseEntity implements Parcelable { // // public int id; // // public String title; // // public int type = 0; // // public List<String> images = new ArrayList<>(); // // public String image; // // public String body; // // public List<String> css; // // public String share_url; // // public String hint; // // public List<String> getCss() { // return css; // } // // public void setCss(List<String> css) { // this.css = css; // } // // public String getBody() { // return body; // } // // public void setBody(String body) { // this.body = body; // } // // public String getImage() { // return image; // } // // public void setImage(String image) { // this.image = image; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // // public List<String> getImages() { // return images; // } // // public void setImages(List<String> images) { // this.images = images; // } // // public int getType() { // return type; // } // // public void setType(int type) { // this.type = type; // } // // public Story() { // } // // public int getId() { // return id; // } // // public void setId(int id) { // this.id = id; // } // // @Override // public String toString() { // return "Story{" + // "id=" + id + // ", title='" + title + '\'' + // ", type=" + type + // ", images=" + images + // ", image='" + image + '\'' + // ", body='" + body + '\'' + // ", css=" + css + // '}'; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(this.id); // dest.writeString(this.title); // dest.writeInt(this.type); // dest.writeStringList(this.images); // dest.writeString(this.image); // dest.writeString(this.body); // dest.writeStringList(this.css); // dest.writeString(this.share_url); // } // // protected Story(Parcel in) { // this.id = in.readInt(); // this.title = in.readString(); // this.type = in.readInt(); // this.images = in.createStringArrayList(); // this.image = in.readString(); // this.body = in.readString(); // this.css = in.createStringArrayList(); // this.share_url = in.readString(); // } // // public static final Creator<Story> CREATOR = new Creator<Story>() { // public Story createFromParcel(Parcel source) { // return new Story(source); // } // // public Story[] newArray(int size) { // return new Story[size]; // } // }; // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_STORY; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/api/service/StoryService.java // public interface StoryService { // // @GET("story/{story_id}") // Observable<Story> getStory(@Path("story_id") int storyId); // // } // Path: app/src/main/java/com/liuguangqiang/idaily/feature/detail/StoryViewModel.java import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; import android.os.Bundle; import com.liuguangqiang.idaily.api.ServiceFactory; import com.liuguangqiang.idaily.entity.Story; import com.liuguangqiang.idaily.api.service.StoryService; import io.reactivex.Observer; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; } } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getImage() { if (story == null) return ""; return story.getImage(); } public String getBody() { return getBody(storyLiveData.getValue()); } public void setStory(Story story) { storyLiveData.postValue(story); } public Story getStory() { return story; } public void getStory(int id) {
StoryService storyService = ServiceFactory.getInstance().create(StoryService.class);
liuguangqiang/Idaily
app/src/main/java/com/liuguangqiang/idaily/feature/detail/StoryViewModel.java
// Path: app/src/main/java/com/liuguangqiang/idaily/api/ServiceFactory.java // public class ServiceFactory { // // private static String HOST_NAME = "http://news-at.zhihu.com/api/4/"; // // private static final ServiceFactory instance = new ServiceFactory(); // // public static ServiceFactory getInstance() { // return instance; // } // // private Retrofit retrofit; // // public ServiceFactory() { // createRetrofit(); // } // // private void createRetrofit() { // HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); // interceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS); // OkHttpClient okHttpClient = new OkHttpClient.Builder() // .addInterceptor(interceptor) // .build(); // // retrofit = new Retrofit.Builder() // .baseUrl(HOST_NAME) // .client(okHttpClient) // .addConverterFactory(GsonConverterFactory.create()) // .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) // .build(); // } // // // public <T> T create(Class<?> clazz) { // return (T) retrofit.create(clazz); // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/entity/Story.java // public class Story extends BaseEntity implements Parcelable { // // public int id; // // public String title; // // public int type = 0; // // public List<String> images = new ArrayList<>(); // // public String image; // // public String body; // // public List<String> css; // // public String share_url; // // public String hint; // // public List<String> getCss() { // return css; // } // // public void setCss(List<String> css) { // this.css = css; // } // // public String getBody() { // return body; // } // // public void setBody(String body) { // this.body = body; // } // // public String getImage() { // return image; // } // // public void setImage(String image) { // this.image = image; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // // public List<String> getImages() { // return images; // } // // public void setImages(List<String> images) { // this.images = images; // } // // public int getType() { // return type; // } // // public void setType(int type) { // this.type = type; // } // // public Story() { // } // // public int getId() { // return id; // } // // public void setId(int id) { // this.id = id; // } // // @Override // public String toString() { // return "Story{" + // "id=" + id + // ", title='" + title + '\'' + // ", type=" + type + // ", images=" + images + // ", image='" + image + '\'' + // ", body='" + body + '\'' + // ", css=" + css + // '}'; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(this.id); // dest.writeString(this.title); // dest.writeInt(this.type); // dest.writeStringList(this.images); // dest.writeString(this.image); // dest.writeString(this.body); // dest.writeStringList(this.css); // dest.writeString(this.share_url); // } // // protected Story(Parcel in) { // this.id = in.readInt(); // this.title = in.readString(); // this.type = in.readInt(); // this.images = in.createStringArrayList(); // this.image = in.readString(); // this.body = in.readString(); // this.css = in.createStringArrayList(); // this.share_url = in.readString(); // } // // public static final Creator<Story> CREATOR = new Creator<Story>() { // public Story createFromParcel(Parcel source) { // return new Story(source); // } // // public Story[] newArray(int size) { // return new Story[size]; // } // }; // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_STORY; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/api/service/StoryService.java // public interface StoryService { // // @GET("story/{story_id}") // Observable<Story> getStory(@Path("story_id") int storyId); // // }
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; import android.os.Bundle; import com.liuguangqiang.idaily.api.ServiceFactory; import com.liuguangqiang.idaily.entity.Story; import com.liuguangqiang.idaily.api.service.StoryService; import io.reactivex.Observer; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers;
} } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getImage() { if (story == null) return ""; return story.getImage(); } public String getBody() { return getBody(storyLiveData.getValue()); } public void setStory(Story story) { storyLiveData.postValue(story); } public Story getStory() { return story; } public void getStory(int id) {
// Path: app/src/main/java/com/liuguangqiang/idaily/api/ServiceFactory.java // public class ServiceFactory { // // private static String HOST_NAME = "http://news-at.zhihu.com/api/4/"; // // private static final ServiceFactory instance = new ServiceFactory(); // // public static ServiceFactory getInstance() { // return instance; // } // // private Retrofit retrofit; // // public ServiceFactory() { // createRetrofit(); // } // // private void createRetrofit() { // HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor(); // interceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS); // OkHttpClient okHttpClient = new OkHttpClient.Builder() // .addInterceptor(interceptor) // .build(); // // retrofit = new Retrofit.Builder() // .baseUrl(HOST_NAME) // .client(okHttpClient) // .addConverterFactory(GsonConverterFactory.create()) // .addCallAdapterFactory(RxJava2CallAdapterFactory.create()) // .build(); // } // // // public <T> T create(Class<?> clazz) { // return (T) retrofit.create(clazz); // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/entity/Story.java // public class Story extends BaseEntity implements Parcelable { // // public int id; // // public String title; // // public int type = 0; // // public List<String> images = new ArrayList<>(); // // public String image; // // public String body; // // public List<String> css; // // public String share_url; // // public String hint; // // public List<String> getCss() { // return css; // } // // public void setCss(List<String> css) { // this.css = css; // } // // public String getBody() { // return body; // } // // public void setBody(String body) { // this.body = body; // } // // public String getImage() { // return image; // } // // public void setImage(String image) { // this.image = image; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // // public List<String> getImages() { // return images; // } // // public void setImages(List<String> images) { // this.images = images; // } // // public int getType() { // return type; // } // // public void setType(int type) { // this.type = type; // } // // public Story() { // } // // public int getId() { // return id; // } // // public void setId(int id) { // this.id = id; // } // // @Override // public String toString() { // return "Story{" + // "id=" + id + // ", title='" + title + '\'' + // ", type=" + type + // ", images=" + images + // ", image='" + image + '\'' + // ", body='" + body + '\'' + // ", css=" + css + // '}'; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(this.id); // dest.writeString(this.title); // dest.writeInt(this.type); // dest.writeStringList(this.images); // dest.writeString(this.image); // dest.writeString(this.body); // dest.writeStringList(this.css); // dest.writeString(this.share_url); // } // // protected Story(Parcel in) { // this.id = in.readInt(); // this.title = in.readString(); // this.type = in.readInt(); // this.images = in.createStringArrayList(); // this.image = in.readString(); // this.body = in.readString(); // this.css = in.createStringArrayList(); // this.share_url = in.readString(); // } // // public static final Creator<Story> CREATOR = new Creator<Story>() { // public Story createFromParcel(Parcel source) { // return new Story(source); // } // // public Story[] newArray(int size) { // return new Story[size]; // } // }; // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_STORY; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/api/service/StoryService.java // public interface StoryService { // // @GET("story/{story_id}") // Observable<Story> getStory(@Path("story_id") int storyId); // // } // Path: app/src/main/java/com/liuguangqiang/idaily/feature/detail/StoryViewModel.java import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.ViewModel; import android.os.Bundle; import com.liuguangqiang.idaily.api.ServiceFactory; import com.liuguangqiang.idaily.entity.Story; import com.liuguangqiang.idaily.api.service.StoryService; import io.reactivex.Observer; import io.reactivex.android.schedulers.AndroidSchedulers; import io.reactivex.disposables.Disposable; import io.reactivex.schedulers.Schedulers; } } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getImage() { if (story == null) return ""; return story.getImage(); } public String getBody() { return getBody(storyLiveData.getValue()); } public void setStory(Story story) { storyLiveData.postValue(story); } public Story getStory() { return story; } public void getStory(int id) {
StoryService storyService = ServiceFactory.getInstance().create(StoryService.class);
liuguangqiang/Idaily
app/src/main/java/com/liuguangqiang/idaily/feature/main/MainViewModel.java
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/BaseEntity.java // public class BaseEntity implements MultiItemEntity { // // @Override // public int getItemType() { // return 0; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/entity/Story.java // public class Story extends BaseEntity implements Parcelable { // // public int id; // // public String title; // // public int type = 0; // // public List<String> images = new ArrayList<>(); // // public String image; // // public String body; // // public List<String> css; // // public String share_url; // // public String hint; // // public List<String> getCss() { // return css; // } // // public void setCss(List<String> css) { // this.css = css; // } // // public String getBody() { // return body; // } // // public void setBody(String body) { // this.body = body; // } // // public String getImage() { // return image; // } // // public void setImage(String image) { // this.image = image; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // // public List<String> getImages() { // return images; // } // // public void setImages(List<String> images) { // this.images = images; // } // // public int getType() { // return type; // } // // public void setType(int type) { // this.type = type; // } // // public Story() { // } // // public int getId() { // return id; // } // // public void setId(int id) { // this.id = id; // } // // @Override // public String toString() { // return "Story{" + // "id=" + id + // ", title='" + title + '\'' + // ", type=" + type + // ", images=" + images + // ", image='" + image + '\'' + // ", body='" + body + '\'' + // ", css=" + css + // '}'; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(this.id); // dest.writeString(this.title); // dest.writeInt(this.type); // dest.writeStringList(this.images); // dest.writeString(this.image); // dest.writeString(this.body); // dest.writeStringList(this.css); // dest.writeString(this.share_url); // } // // protected Story(Parcel in) { // this.id = in.readInt(); // this.title = in.readString(); // this.type = in.readInt(); // this.images = in.createStringArrayList(); // this.image = in.readString(); // this.body = in.readString(); // this.css = in.createStringArrayList(); // this.share_url = in.readString(); // } // // public static final Creator<Story> CREATOR = new Creator<Story>() { // public Story createFromParcel(Parcel source) { // return new Story(source); // } // // public Story[] newArray(int size) { // return new Story[size]; // } // }; // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_STORY; // } // }
import android.app.Application; import androidx.lifecycle.AndroidViewModel; import androidx.lifecycle.MutableLiveData; import com.liuguangqiang.idaily.entity.BaseEntity; import com.liuguangqiang.idaily.entity.Story; import java.util.List;
package com.liuguangqiang.idaily.feature.main; /** * Created by Eric on 15/6/26. */ public class MainViewModel extends AndroidViewModel { private MainModel mainModel; public MainViewModel(Application application) { super(application); mainModel = new MainModel(); }
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/BaseEntity.java // public class BaseEntity implements MultiItemEntity { // // @Override // public int getItemType() { // return 0; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/entity/Story.java // public class Story extends BaseEntity implements Parcelable { // // public int id; // // public String title; // // public int type = 0; // // public List<String> images = new ArrayList<>(); // // public String image; // // public String body; // // public List<String> css; // // public String share_url; // // public String hint; // // public List<String> getCss() { // return css; // } // // public void setCss(List<String> css) { // this.css = css; // } // // public String getBody() { // return body; // } // // public void setBody(String body) { // this.body = body; // } // // public String getImage() { // return image; // } // // public void setImage(String image) { // this.image = image; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // // public List<String> getImages() { // return images; // } // // public void setImages(List<String> images) { // this.images = images; // } // // public int getType() { // return type; // } // // public void setType(int type) { // this.type = type; // } // // public Story() { // } // // public int getId() { // return id; // } // // public void setId(int id) { // this.id = id; // } // // @Override // public String toString() { // return "Story{" + // "id=" + id + // ", title='" + title + '\'' + // ", type=" + type + // ", images=" + images + // ", image='" + image + '\'' + // ", body='" + body + '\'' + // ", css=" + css + // '}'; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(this.id); // dest.writeString(this.title); // dest.writeInt(this.type); // dest.writeStringList(this.images); // dest.writeString(this.image); // dest.writeString(this.body); // dest.writeStringList(this.css); // dest.writeString(this.share_url); // } // // protected Story(Parcel in) { // this.id = in.readInt(); // this.title = in.readString(); // this.type = in.readInt(); // this.images = in.createStringArrayList(); // this.image = in.readString(); // this.body = in.readString(); // this.css = in.createStringArrayList(); // this.share_url = in.readString(); // } // // public static final Creator<Story> CREATOR = new Creator<Story>() { // public Story createFromParcel(Parcel source) { // return new Story(source); // } // // public Story[] newArray(int size) { // return new Story[size]; // } // }; // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_STORY; // } // } // Path: app/src/main/java/com/liuguangqiang/idaily/feature/main/MainViewModel.java import android.app.Application; import androidx.lifecycle.AndroidViewModel; import androidx.lifecycle.MutableLiveData; import com.liuguangqiang.idaily.entity.BaseEntity; import com.liuguangqiang.idaily.entity.Story; import java.util.List; package com.liuguangqiang.idaily.feature.main; /** * Created by Eric on 15/6/26. */ public class MainViewModel extends AndroidViewModel { private MainModel mainModel; public MainViewModel(Application application) { super(application); mainModel = new MainModel(); }
public MutableLiveData<List<BaseEntity>> getLiveData() {
liuguangqiang/Idaily
app/src/main/java/com/liuguangqiang/idaily/feature/main/MainViewModel.java
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/BaseEntity.java // public class BaseEntity implements MultiItemEntity { // // @Override // public int getItemType() { // return 0; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/entity/Story.java // public class Story extends BaseEntity implements Parcelable { // // public int id; // // public String title; // // public int type = 0; // // public List<String> images = new ArrayList<>(); // // public String image; // // public String body; // // public List<String> css; // // public String share_url; // // public String hint; // // public List<String> getCss() { // return css; // } // // public void setCss(List<String> css) { // this.css = css; // } // // public String getBody() { // return body; // } // // public void setBody(String body) { // this.body = body; // } // // public String getImage() { // return image; // } // // public void setImage(String image) { // this.image = image; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // // public List<String> getImages() { // return images; // } // // public void setImages(List<String> images) { // this.images = images; // } // // public int getType() { // return type; // } // // public void setType(int type) { // this.type = type; // } // // public Story() { // } // // public int getId() { // return id; // } // // public void setId(int id) { // this.id = id; // } // // @Override // public String toString() { // return "Story{" + // "id=" + id + // ", title='" + title + '\'' + // ", type=" + type + // ", images=" + images + // ", image='" + image + '\'' + // ", body='" + body + '\'' + // ", css=" + css + // '}'; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(this.id); // dest.writeString(this.title); // dest.writeInt(this.type); // dest.writeStringList(this.images); // dest.writeString(this.image); // dest.writeString(this.body); // dest.writeStringList(this.css); // dest.writeString(this.share_url); // } // // protected Story(Parcel in) { // this.id = in.readInt(); // this.title = in.readString(); // this.type = in.readInt(); // this.images = in.createStringArrayList(); // this.image = in.readString(); // this.body = in.readString(); // this.css = in.createStringArrayList(); // this.share_url = in.readString(); // } // // public static final Creator<Story> CREATOR = new Creator<Story>() { // public Story createFromParcel(Parcel source) { // return new Story(source); // } // // public Story[] newArray(int size) { // return new Story[size]; // } // }; // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_STORY; // } // }
import android.app.Application; import androidx.lifecycle.AndroidViewModel; import androidx.lifecycle.MutableLiveData; import com.liuguangqiang.idaily.entity.BaseEntity; import com.liuguangqiang.idaily.entity.Story; import java.util.List;
package com.liuguangqiang.idaily.feature.main; /** * Created by Eric on 15/6/26. */ public class MainViewModel extends AndroidViewModel { private MainModel mainModel; public MainViewModel(Application application) { super(application); mainModel = new MainModel(); } public MutableLiveData<List<BaseEntity>> getLiveData() { return mainModel.getLiveData(); }
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/BaseEntity.java // public class BaseEntity implements MultiItemEntity { // // @Override // public int getItemType() { // return 0; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/entity/Story.java // public class Story extends BaseEntity implements Parcelable { // // public int id; // // public String title; // // public int type = 0; // // public List<String> images = new ArrayList<>(); // // public String image; // // public String body; // // public List<String> css; // // public String share_url; // // public String hint; // // public List<String> getCss() { // return css; // } // // public void setCss(List<String> css) { // this.css = css; // } // // public String getBody() { // return body; // } // // public void setBody(String body) { // this.body = body; // } // // public String getImage() { // return image; // } // // public void setImage(String image) { // this.image = image; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // // public List<String> getImages() { // return images; // } // // public void setImages(List<String> images) { // this.images = images; // } // // public int getType() { // return type; // } // // public void setType(int type) { // this.type = type; // } // // public Story() { // } // // public int getId() { // return id; // } // // public void setId(int id) { // this.id = id; // } // // @Override // public String toString() { // return "Story{" + // "id=" + id + // ", title='" + title + '\'' + // ", type=" + type + // ", images=" + images + // ", image='" + image + '\'' + // ", body='" + body + '\'' + // ", css=" + css + // '}'; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(this.id); // dest.writeString(this.title); // dest.writeInt(this.type); // dest.writeStringList(this.images); // dest.writeString(this.image); // dest.writeString(this.body); // dest.writeStringList(this.css); // dest.writeString(this.share_url); // } // // protected Story(Parcel in) { // this.id = in.readInt(); // this.title = in.readString(); // this.type = in.readInt(); // this.images = in.createStringArrayList(); // this.image = in.readString(); // this.body = in.readString(); // this.css = in.createStringArrayList(); // this.share_url = in.readString(); // } // // public static final Creator<Story> CREATOR = new Creator<Story>() { // public Story createFromParcel(Parcel source) { // return new Story(source); // } // // public Story[] newArray(int size) { // return new Story[size]; // } // }; // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_STORY; // } // } // Path: app/src/main/java/com/liuguangqiang/idaily/feature/main/MainViewModel.java import android.app.Application; import androidx.lifecycle.AndroidViewModel; import androidx.lifecycle.MutableLiveData; import com.liuguangqiang.idaily.entity.BaseEntity; import com.liuguangqiang.idaily.entity.Story; import java.util.List; package com.liuguangqiang.idaily.feature.main; /** * Created by Eric on 15/6/26. */ public class MainViewModel extends AndroidViewModel { private MainModel mainModel; public MainViewModel(Application application) { super(application); mainModel = new MainModel(); } public MutableLiveData<List<BaseEntity>> getLiveData() { return mainModel.getLiveData(); }
public MutableLiveData<List<Story>> getTopLiveData() {
liuguangqiang/Idaily
app/src/main/java/com/liuguangqiang/idaily/api/service/StoryService.java
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/Story.java // public class Story extends BaseEntity implements Parcelable { // // public int id; // // public String title; // // public int type = 0; // // public List<String> images = new ArrayList<>(); // // public String image; // // public String body; // // public List<String> css; // // public String share_url; // // public String hint; // // public List<String> getCss() { // return css; // } // // public void setCss(List<String> css) { // this.css = css; // } // // public String getBody() { // return body; // } // // public void setBody(String body) { // this.body = body; // } // // public String getImage() { // return image; // } // // public void setImage(String image) { // this.image = image; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // // public List<String> getImages() { // return images; // } // // public void setImages(List<String> images) { // this.images = images; // } // // public int getType() { // return type; // } // // public void setType(int type) { // this.type = type; // } // // public Story() { // } // // public int getId() { // return id; // } // // public void setId(int id) { // this.id = id; // } // // @Override // public String toString() { // return "Story{" + // "id=" + id + // ", title='" + title + '\'' + // ", type=" + type + // ", images=" + images + // ", image='" + image + '\'' + // ", body='" + body + '\'' + // ", css=" + css + // '}'; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(this.id); // dest.writeString(this.title); // dest.writeInt(this.type); // dest.writeStringList(this.images); // dest.writeString(this.image); // dest.writeString(this.body); // dest.writeStringList(this.css); // dest.writeString(this.share_url); // } // // protected Story(Parcel in) { // this.id = in.readInt(); // this.title = in.readString(); // this.type = in.readInt(); // this.images = in.createStringArrayList(); // this.image = in.readString(); // this.body = in.readString(); // this.css = in.createStringArrayList(); // this.share_url = in.readString(); // } // // public static final Creator<Story> CREATOR = new Creator<Story>() { // public Story createFromParcel(Parcel source) { // return new Story(source); // } // // public Story[] newArray(int size) { // return new Story[size]; // } // }; // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_STORY; // } // }
import com.liuguangqiang.idaily.entity.Story; import io.reactivex.Observable; import retrofit2.http.GET; import retrofit2.http.Path;
package com.liuguangqiang.idaily.api.service; /** * Created by Eric on 16/3/21. */ public interface StoryService { @GET("story/{story_id}")
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/Story.java // public class Story extends BaseEntity implements Parcelable { // // public int id; // // public String title; // // public int type = 0; // // public List<String> images = new ArrayList<>(); // // public String image; // // public String body; // // public List<String> css; // // public String share_url; // // public String hint; // // public List<String> getCss() { // return css; // } // // public void setCss(List<String> css) { // this.css = css; // } // // public String getBody() { // return body; // } // // public void setBody(String body) { // this.body = body; // } // // public String getImage() { // return image; // } // // public void setImage(String image) { // this.image = image; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // // public List<String> getImages() { // return images; // } // // public void setImages(List<String> images) { // this.images = images; // } // // public int getType() { // return type; // } // // public void setType(int type) { // this.type = type; // } // // public Story() { // } // // public int getId() { // return id; // } // // public void setId(int id) { // this.id = id; // } // // @Override // public String toString() { // return "Story{" + // "id=" + id + // ", title='" + title + '\'' + // ", type=" + type + // ", images=" + images + // ", image='" + image + '\'' + // ", body='" + body + '\'' + // ", css=" + css + // '}'; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(this.id); // dest.writeString(this.title); // dest.writeInt(this.type); // dest.writeStringList(this.images); // dest.writeString(this.image); // dest.writeString(this.body); // dest.writeStringList(this.css); // dest.writeString(this.share_url); // } // // protected Story(Parcel in) { // this.id = in.readInt(); // this.title = in.readString(); // this.type = in.readInt(); // this.images = in.createStringArrayList(); // this.image = in.readString(); // this.body = in.readString(); // this.css = in.createStringArrayList(); // this.share_url = in.readString(); // } // // public static final Creator<Story> CREATOR = new Creator<Story>() { // public Story createFromParcel(Parcel source) { // return new Story(source); // } // // public Story[] newArray(int size) { // return new Story[size]; // } // }; // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_STORY; // } // } // Path: app/src/main/java/com/liuguangqiang/idaily/api/service/StoryService.java import com.liuguangqiang.idaily.entity.Story; import io.reactivex.Observable; import retrofit2.http.GET; import retrofit2.http.Path; package com.liuguangqiang.idaily.api.service; /** * Created by Eric on 16/3/21. */ public interface StoryService { @GET("story/{story_id}")
Observable<Story> getStory(@Path("story_id") int storyId);
liuguangqiang/Idaily
app/src/main/java/com/liuguangqiang/idaily/utils/databinding/DBRecyclerView.java
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/BaseEntity.java // public class BaseEntity implements MultiItemEntity { // // @Override // public int getItemType() { // return 0; // } // }
import androidx.databinding.BindingAdapter; import com.liuguangqiang.idaily.R; import com.liuguangqiang.idaily.entity.BaseEntity; import com.liuguangqiang.support.widgets.recyclerview.SuperRecyclerView; import com.liuguangqiang.support.widgets.recyclerview.adapter.AbsRVAdapter; import java.util.List;
package com.liuguangqiang.idaily.utils.databinding; /** * Custom binding for RecyclerView. * <p> * Created by Eric on 15/6/23. */ public class DBRecyclerView { public static int SHOW_FOOTER = 0; public static int HIDE_FOOTER = 1; @BindingAdapter({"adapter"}) public static void bindAdapter(SuperRecyclerView recyclerView, AbsRVAdapter adapter) { recyclerView.setAdapter(adapter); recyclerView.setPageFooter(R.layout.layout_loading_footer); } @BindingAdapter({"data"})
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/BaseEntity.java // public class BaseEntity implements MultiItemEntity { // // @Override // public int getItemType() { // return 0; // } // } // Path: app/src/main/java/com/liuguangqiang/idaily/utils/databinding/DBRecyclerView.java import androidx.databinding.BindingAdapter; import com.liuguangqiang.idaily.R; import com.liuguangqiang.idaily.entity.BaseEntity; import com.liuguangqiang.support.widgets.recyclerview.SuperRecyclerView; import com.liuguangqiang.support.widgets.recyclerview.adapter.AbsRVAdapter; import java.util.List; package com.liuguangqiang.idaily.utils.databinding; /** * Custom binding for RecyclerView. * <p> * Created by Eric on 15/6/23. */ public class DBRecyclerView { public static int SHOW_FOOTER = 0; public static int HIDE_FOOTER = 1; @BindingAdapter({"adapter"}) public static void bindAdapter(SuperRecyclerView recyclerView, AbsRVAdapter adapter) { recyclerView.setAdapter(adapter); recyclerView.setPageFooter(R.layout.layout_loading_footer); } @BindingAdapter({"data"})
public static void bindData(SuperRecyclerView recyclerView, List<BaseEntity> data) {
liuguangqiang/Idaily
app/src/main/java/com/liuguangqiang/idaily/feature/main/TopStoryFragment.java
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/Story.java // public class Story extends BaseEntity implements Parcelable { // // public int id; // // public String title; // // public int type = 0; // // public List<String> images = new ArrayList<>(); // // public String image; // // public String body; // // public List<String> css; // // public String share_url; // // public String hint; // // public List<String> getCss() { // return css; // } // // public void setCss(List<String> css) { // this.css = css; // } // // public String getBody() { // return body; // } // // public void setBody(String body) { // this.body = body; // } // // public String getImage() { // return image; // } // // public void setImage(String image) { // this.image = image; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // // public List<String> getImages() { // return images; // } // // public void setImages(List<String> images) { // this.images = images; // } // // public int getType() { // return type; // } // // public void setType(int type) { // this.type = type; // } // // public Story() { // } // // public int getId() { // return id; // } // // public void setId(int id) { // this.id = id; // } // // @Override // public String toString() { // return "Story{" + // "id=" + id + // ", title='" + title + '\'' + // ", type=" + type + // ", images=" + images + // ", image='" + image + '\'' + // ", body='" + body + '\'' + // ", css=" + css + // '}'; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(this.id); // dest.writeString(this.title); // dest.writeInt(this.type); // dest.writeStringList(this.images); // dest.writeString(this.image); // dest.writeString(this.body); // dest.writeStringList(this.css); // dest.writeString(this.share_url); // } // // protected Story(Parcel in) { // this.id = in.readInt(); // this.title = in.readString(); // this.type = in.readInt(); // this.images = in.createStringArrayList(); // this.image = in.readString(); // this.body = in.readString(); // this.css = in.createStringArrayList(); // this.share_url = in.readString(); // } // // public static final Creator<Story> CREATOR = new Creator<Story>() { // public Story createFromParcel(Parcel source) { // return new Story(source); // } // // public Story[] newArray(int size) { // return new Story[size]; // } // }; // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_STORY; // } // }
import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.fragment.app.Fragment; import com.liuguangqiang.idaily.databinding.FragmentTopStoryBinding; import com.liuguangqiang.idaily.entity.Story;
package com.liuguangqiang.idaily.feature.main; public class TopStoryFragment extends Fragment { public static final String ARG_STORY = "ARG_STORY";
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/Story.java // public class Story extends BaseEntity implements Parcelable { // // public int id; // // public String title; // // public int type = 0; // // public List<String> images = new ArrayList<>(); // // public String image; // // public String body; // // public List<String> css; // // public String share_url; // // public String hint; // // public List<String> getCss() { // return css; // } // // public void setCss(List<String> css) { // this.css = css; // } // // public String getBody() { // return body; // } // // public void setBody(String body) { // this.body = body; // } // // public String getImage() { // return image; // } // // public void setImage(String image) { // this.image = image; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // // public List<String> getImages() { // return images; // } // // public void setImages(List<String> images) { // this.images = images; // } // // public int getType() { // return type; // } // // public void setType(int type) { // this.type = type; // } // // public Story() { // } // // public int getId() { // return id; // } // // public void setId(int id) { // this.id = id; // } // // @Override // public String toString() { // return "Story{" + // "id=" + id + // ", title='" + title + '\'' + // ", type=" + type + // ", images=" + images + // ", image='" + image + '\'' + // ", body='" + body + '\'' + // ", css=" + css + // '}'; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(this.id); // dest.writeString(this.title); // dest.writeInt(this.type); // dest.writeStringList(this.images); // dest.writeString(this.image); // dest.writeString(this.body); // dest.writeStringList(this.css); // dest.writeString(this.share_url); // } // // protected Story(Parcel in) { // this.id = in.readInt(); // this.title = in.readString(); // this.type = in.readInt(); // this.images = in.createStringArrayList(); // this.image = in.readString(); // this.body = in.readString(); // this.css = in.createStringArrayList(); // this.share_url = in.readString(); // } // // public static final Creator<Story> CREATOR = new Creator<Story>() { // public Story createFromParcel(Parcel source) { // return new Story(source); // } // // public Story[] newArray(int size) { // return new Story[size]; // } // }; // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_STORY; // } // } // Path: app/src/main/java/com/liuguangqiang/idaily/feature/main/TopStoryFragment.java import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import androidx.fragment.app.Fragment; import com.liuguangqiang.idaily.databinding.FragmentTopStoryBinding; import com.liuguangqiang.idaily.entity.Story; package com.liuguangqiang.idaily.feature.main; public class TopStoryFragment extends Fragment { public static final String ARG_STORY = "ARG_STORY";
private Story story;
liuguangqiang/Idaily
app/src/main/java/com/liuguangqiang/idaily/adapter/page/TopStoryAdapter.java
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/Story.java // public class Story extends BaseEntity implements Parcelable { // // public int id; // // public String title; // // public int type = 0; // // public List<String> images = new ArrayList<>(); // // public String image; // // public String body; // // public List<String> css; // // public String share_url; // // public String hint; // // public List<String> getCss() { // return css; // } // // public void setCss(List<String> css) { // this.css = css; // } // // public String getBody() { // return body; // } // // public void setBody(String body) { // this.body = body; // } // // public String getImage() { // return image; // } // // public void setImage(String image) { // this.image = image; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // // public List<String> getImages() { // return images; // } // // public void setImages(List<String> images) { // this.images = images; // } // // public int getType() { // return type; // } // // public void setType(int type) { // this.type = type; // } // // public Story() { // } // // public int getId() { // return id; // } // // public void setId(int id) { // this.id = id; // } // // @Override // public String toString() { // return "Story{" + // "id=" + id + // ", title='" + title + '\'' + // ", type=" + type + // ", images=" + images + // ", image='" + image + '\'' + // ", body='" + body + '\'' + // ", css=" + css + // '}'; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(this.id); // dest.writeString(this.title); // dest.writeInt(this.type); // dest.writeStringList(this.images); // dest.writeString(this.image); // dest.writeString(this.body); // dest.writeStringList(this.css); // dest.writeString(this.share_url); // } // // protected Story(Parcel in) { // this.id = in.readInt(); // this.title = in.readString(); // this.type = in.readInt(); // this.images = in.createStringArrayList(); // this.image = in.readString(); // this.body = in.readString(); // this.css = in.createStringArrayList(); // this.share_url = in.readString(); // } // // public static final Creator<Story> CREATOR = new Creator<Story>() { // public Story createFromParcel(Parcel source) { // return new Story(source); // } // // public Story[] newArray(int size) { // return new Story[size]; // } // }; // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_STORY; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/feature/main/TopStoryFragment.java // public class TopStoryFragment extends Fragment { // // public static final String ARG_STORY = "ARG_STORY"; // // private Story story; // // private TopStoryViewModel viewModel; // // public static TopStoryFragment newInstance(Story story) { // TopStoryFragment fragment = new TopStoryFragment(); // Bundle args = new Bundle(); // args.putParcelable(ARG_STORY, story); // fragment.setArguments(args); // return fragment; // } // // @Override // public void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // Bundle bundle = getArguments(); // if (bundle != null && bundle.containsKey(ARG_STORY)) { // story = bundle.getParcelable(ARG_STORY); // } // } // // @Override // public View onCreateView(LayoutInflater inflater, ViewGroup container, // Bundle savedInstanceState) { // FragmentTopStoryBinding binding = FragmentTopStoryBinding.inflate(inflater); // viewModel = new TopStoryViewModel(); // viewModel.setStory(story); // binding.setViewModel(viewModel); // return binding.getRoot(); // // } // // }
import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentStatePagerAdapter; import com.liuguangqiang.idaily.entity.Story; import com.liuguangqiang.idaily.feature.main.TopStoryFragment; import java.util.ArrayList; import java.util.List;
package com.liuguangqiang.idaily.adapter.page; /** * Created by Eric on 15/7/8. */ public class TopStoryAdapter extends FragmentStatePagerAdapter { public List<Story> stories = new ArrayList<>(); public TopStoryAdapter(androidx.fragment.app.FragmentManager fm, List<Story> stories) { super(fm); this.stories = stories; } @Override public Fragment getItem(int position) {
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/Story.java // public class Story extends BaseEntity implements Parcelable { // // public int id; // // public String title; // // public int type = 0; // // public List<String> images = new ArrayList<>(); // // public String image; // // public String body; // // public List<String> css; // // public String share_url; // // public String hint; // // public List<String> getCss() { // return css; // } // // public void setCss(List<String> css) { // this.css = css; // } // // public String getBody() { // return body; // } // // public void setBody(String body) { // this.body = body; // } // // public String getImage() { // return image; // } // // public void setImage(String image) { // this.image = image; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // // public List<String> getImages() { // return images; // } // // public void setImages(List<String> images) { // this.images = images; // } // // public int getType() { // return type; // } // // public void setType(int type) { // this.type = type; // } // // public Story() { // } // // public int getId() { // return id; // } // // public void setId(int id) { // this.id = id; // } // // @Override // public String toString() { // return "Story{" + // "id=" + id + // ", title='" + title + '\'' + // ", type=" + type + // ", images=" + images + // ", image='" + image + '\'' + // ", body='" + body + '\'' + // ", css=" + css + // '}'; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(this.id); // dest.writeString(this.title); // dest.writeInt(this.type); // dest.writeStringList(this.images); // dest.writeString(this.image); // dest.writeString(this.body); // dest.writeStringList(this.css); // dest.writeString(this.share_url); // } // // protected Story(Parcel in) { // this.id = in.readInt(); // this.title = in.readString(); // this.type = in.readInt(); // this.images = in.createStringArrayList(); // this.image = in.readString(); // this.body = in.readString(); // this.css = in.createStringArrayList(); // this.share_url = in.readString(); // } // // public static final Creator<Story> CREATOR = new Creator<Story>() { // public Story createFromParcel(Parcel source) { // return new Story(source); // } // // public Story[] newArray(int size) { // return new Story[size]; // } // }; // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_STORY; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/feature/main/TopStoryFragment.java // public class TopStoryFragment extends Fragment { // // public static final String ARG_STORY = "ARG_STORY"; // // private Story story; // // private TopStoryViewModel viewModel; // // public static TopStoryFragment newInstance(Story story) { // TopStoryFragment fragment = new TopStoryFragment(); // Bundle args = new Bundle(); // args.putParcelable(ARG_STORY, story); // fragment.setArguments(args); // return fragment; // } // // @Override // public void onCreate(Bundle savedInstanceState) { // super.onCreate(savedInstanceState); // Bundle bundle = getArguments(); // if (bundle != null && bundle.containsKey(ARG_STORY)) { // story = bundle.getParcelable(ARG_STORY); // } // } // // @Override // public View onCreateView(LayoutInflater inflater, ViewGroup container, // Bundle savedInstanceState) { // FragmentTopStoryBinding binding = FragmentTopStoryBinding.inflate(inflater); // viewModel = new TopStoryViewModel(); // viewModel.setStory(story); // binding.setViewModel(viewModel); // return binding.getRoot(); // // } // // } // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/page/TopStoryAdapter.java import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentStatePagerAdapter; import com.liuguangqiang.idaily.entity.Story; import com.liuguangqiang.idaily.feature.main.TopStoryFragment; import java.util.ArrayList; import java.util.List; package com.liuguangqiang.idaily.adapter.page; /** * Created by Eric on 15/7/8. */ public class TopStoryAdapter extends FragmentStatePagerAdapter { public List<Story> stories = new ArrayList<>(); public TopStoryAdapter(androidx.fragment.app.FragmentManager fm, List<Story> stories) { super(fm); this.stories = stories; } @Override public Fragment getItem(int position) {
return TopStoryFragment.newInstance(stories.get(position));
liuguangqiang/Idaily
app/src/main/java/com/liuguangqiang/idaily/adapter/ItemProvider/SectionItemProvider.java
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/StorySection.java // public class StorySection extends BaseEntity { // // public int datetime; // // public StorySection(int datetime) { // this.datetime = datetime; // } // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_SECTION; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/StoriesAdapter.java // public class StoriesAdapter extends BaseProviderMultiAdapter<BaseEntity> implements LoadMoreModule { // // public static final int ITEM_STORY = 0; // // public static final int ITEM_SECTION = 1; // // public StoriesAdapter(@Nullable List<BaseEntity> data) { // super(data); // addItemProvider(new StoryItemProvider()); // addItemProvider(new SectionItemProvider()); // } // // @Override // protected int getItemType(List<? extends BaseEntity> list, int i) { // if (getItem(i) instanceof StorySection) { // return ITEM_SECTION; // } // return ITEM_STORY; // } // }
import androidx.databinding.DataBindingUtil; import com.chad.library.adapter.base.provider.BaseItemProvider; import com.chad.library.adapter.base.viewholder.BaseViewHolder; import com.liuguangqiang.idaily.R; import com.liuguangqiang.idaily.databinding.ItemStoryHeaderBinding; import com.liuguangqiang.idaily.entity.StorySection; import com.liuguangqiang.idaily.adapter.StoriesAdapter; import org.jetbrains.annotations.NotNull;
package com.liuguangqiang.idaily.adapter.ItemProvider; /** * Created by Eric at 2021/8/2 */ public class SectionItemProvider<T> extends BaseItemProvider<StorySection> { @Override public int getItemViewType() {
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/StorySection.java // public class StorySection extends BaseEntity { // // public int datetime; // // public StorySection(int datetime) { // this.datetime = datetime; // } // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_SECTION; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/StoriesAdapter.java // public class StoriesAdapter extends BaseProviderMultiAdapter<BaseEntity> implements LoadMoreModule { // // public static final int ITEM_STORY = 0; // // public static final int ITEM_SECTION = 1; // // public StoriesAdapter(@Nullable List<BaseEntity> data) { // super(data); // addItemProvider(new StoryItemProvider()); // addItemProvider(new SectionItemProvider()); // } // // @Override // protected int getItemType(List<? extends BaseEntity> list, int i) { // if (getItem(i) instanceof StorySection) { // return ITEM_SECTION; // } // return ITEM_STORY; // } // } // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/ItemProvider/SectionItemProvider.java import androidx.databinding.DataBindingUtil; import com.chad.library.adapter.base.provider.BaseItemProvider; import com.chad.library.adapter.base.viewholder.BaseViewHolder; import com.liuguangqiang.idaily.R; import com.liuguangqiang.idaily.databinding.ItemStoryHeaderBinding; import com.liuguangqiang.idaily.entity.StorySection; import com.liuguangqiang.idaily.adapter.StoriesAdapter; import org.jetbrains.annotations.NotNull; package com.liuguangqiang.idaily.adapter.ItemProvider; /** * Created by Eric at 2021/8/2 */ public class SectionItemProvider<T> extends BaseItemProvider<StorySection> { @Override public int getItemViewType() {
return StoriesAdapter.ITEM_SECTION;
liuguangqiang/Idaily
app/src/main/java/com/liuguangqiang/idaily/feature/main/TopStoryViewModel.java
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/Story.java // public class Story extends BaseEntity implements Parcelable { // // public int id; // // public String title; // // public int type = 0; // // public List<String> images = new ArrayList<>(); // // public String image; // // public String body; // // public List<String> css; // // public String share_url; // // public String hint; // // public List<String> getCss() { // return css; // } // // public void setCss(List<String> css) { // this.css = css; // } // // public String getBody() { // return body; // } // // public void setBody(String body) { // this.body = body; // } // // public String getImage() { // return image; // } // // public void setImage(String image) { // this.image = image; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // // public List<String> getImages() { // return images; // } // // public void setImages(List<String> images) { // this.images = images; // } // // public int getType() { // return type; // } // // public void setType(int type) { // this.type = type; // } // // public Story() { // } // // public int getId() { // return id; // } // // public void setId(int id) { // this.id = id; // } // // @Override // public String toString() { // return "Story{" + // "id=" + id + // ", title='" + title + '\'' + // ", type=" + type + // ", images=" + images + // ", image='" + image + '\'' + // ", body='" + body + '\'' + // ", css=" + css + // '}'; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(this.id); // dest.writeString(this.title); // dest.writeInt(this.type); // dest.writeStringList(this.images); // dest.writeString(this.image); // dest.writeString(this.body); // dest.writeStringList(this.css); // dest.writeString(this.share_url); // } // // protected Story(Parcel in) { // this.id = in.readInt(); // this.title = in.readString(); // this.type = in.readInt(); // this.images = in.createStringArrayList(); // this.image = in.readString(); // this.body = in.readString(); // this.css = in.createStringArrayList(); // this.share_url = in.readString(); // } // // public static final Creator<Story> CREATOR = new Creator<Story>() { // public Story createFromParcel(Parcel source) { // return new Story(source); // } // // public Story[] newArray(int size) { // return new Story[size]; // } // }; // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_STORY; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/utils/navigator/Navigator.java // public class Navigator extends BaseNavigator { // // private static Navigator instance = new Navigator(); // // private Navigator() { // } // // public static Navigator getInstance() { // return instance; // } // // public void openStory(Context context, Story story) { // Bundle bundle = new Bundle(); // bundle.putParcelable(StoryActivity.ARG_STORY, story); // start(context, StoryActivity.class, bundle); // } // // }
import androidx.databinding.BaseObservable; import android.view.View; import com.liuguangqiang.idaily.entity.Story; import com.liuguangqiang.idaily.utils.navigator.Navigator;
package com.liuguangqiang.idaily.feature.main; /** * Created by Eric on 15/10/11. */ public class TopStoryViewModel extends BaseObservable { private Story story; public void setStory(Story s) { this.story = s; } public View.OnClickListener getPicClickListener() { return new View.OnClickListener() { @Override public void onClick(View v) {
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/Story.java // public class Story extends BaseEntity implements Parcelable { // // public int id; // // public String title; // // public int type = 0; // // public List<String> images = new ArrayList<>(); // // public String image; // // public String body; // // public List<String> css; // // public String share_url; // // public String hint; // // public List<String> getCss() { // return css; // } // // public void setCss(List<String> css) { // this.css = css; // } // // public String getBody() { // return body; // } // // public void setBody(String body) { // this.body = body; // } // // public String getImage() { // return image; // } // // public void setImage(String image) { // this.image = image; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // // public List<String> getImages() { // return images; // } // // public void setImages(List<String> images) { // this.images = images; // } // // public int getType() { // return type; // } // // public void setType(int type) { // this.type = type; // } // // public Story() { // } // // public int getId() { // return id; // } // // public void setId(int id) { // this.id = id; // } // // @Override // public String toString() { // return "Story{" + // "id=" + id + // ", title='" + title + '\'' + // ", type=" + type + // ", images=" + images + // ", image='" + image + '\'' + // ", body='" + body + '\'' + // ", css=" + css + // '}'; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(this.id); // dest.writeString(this.title); // dest.writeInt(this.type); // dest.writeStringList(this.images); // dest.writeString(this.image); // dest.writeString(this.body); // dest.writeStringList(this.css); // dest.writeString(this.share_url); // } // // protected Story(Parcel in) { // this.id = in.readInt(); // this.title = in.readString(); // this.type = in.readInt(); // this.images = in.createStringArrayList(); // this.image = in.readString(); // this.body = in.readString(); // this.css = in.createStringArrayList(); // this.share_url = in.readString(); // } // // public static final Creator<Story> CREATOR = new Creator<Story>() { // public Story createFromParcel(Parcel source) { // return new Story(source); // } // // public Story[] newArray(int size) { // return new Story[size]; // } // }; // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_STORY; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/utils/navigator/Navigator.java // public class Navigator extends BaseNavigator { // // private static Navigator instance = new Navigator(); // // private Navigator() { // } // // public static Navigator getInstance() { // return instance; // } // // public void openStory(Context context, Story story) { // Bundle bundle = new Bundle(); // bundle.putParcelable(StoryActivity.ARG_STORY, story); // start(context, StoryActivity.class, bundle); // } // // } // Path: app/src/main/java/com/liuguangqiang/idaily/feature/main/TopStoryViewModel.java import androidx.databinding.BaseObservable; import android.view.View; import com.liuguangqiang.idaily.entity.Story; import com.liuguangqiang.idaily.utils.navigator.Navigator; package com.liuguangqiang.idaily.feature.main; /** * Created by Eric on 15/10/11. */ public class TopStoryViewModel extends BaseObservable { private Story story; public void setStory(Story s) { this.story = s; } public View.OnClickListener getPicClickListener() { return new View.OnClickListener() { @Override public void onClick(View v) {
Navigator.getInstance().openStory(v.getContext(), story);
liuguangqiang/Idaily
app/src/main/java/com/liuguangqiang/idaily/adapter/StoriesAdapter.java
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/BaseEntity.java // public class BaseEntity implements MultiItemEntity { // // @Override // public int getItemType() { // return 0; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/entity/StorySection.java // public class StorySection extends BaseEntity { // // public int datetime; // // public StorySection(int datetime) { // this.datetime = datetime; // } // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_SECTION; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/ItemProvider/SectionItemProvider.java // public class SectionItemProvider<T> extends BaseItemProvider<StorySection> { // // @Override // public int getItemViewType() { // return StoriesAdapter.ITEM_SECTION; // } // // @Override // public int getLayoutId() { // return R.layout.item_story_header; // } // // @Override // public void onViewHolderCreated(BaseViewHolder viewHolder, int viewType) { // DataBindingUtil.bind(viewHolder.itemView); // } // // @Override // public void convert(@NotNull BaseViewHolder helper, @NotNull StorySection data) { // ItemStoryHeaderBinding binding =DataBindingUtil.getBinding(helper.itemView); // if (binding != null) { // binding.setSection(data); // binding.executePendingBindings(); // } // } // // } // // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/ItemProvider/StoryItemProvider.java // public class StoryItemProvider<T> extends BaseItemProvider<Story> { // // @Override // public int getItemViewType() { // return StoriesAdapter.ITEM_STORY; // } // // @Override // public int getLayoutId() { // return R.layout.item_story; // } // // @Override // public void onViewHolderCreated(BaseViewHolder viewHolder, int viewType) { // DataBindingUtil.bind(viewHolder.itemView); // } // // @Override // public void convert(@NotNull BaseViewHolder helper, @NotNull Story data) { // Timber.d("StoryItemProvider convert"); // ItemStoryBinding binding = DataBindingUtil.getBinding(helper.itemView); // if (binding != null) { // Timber.d("StoryItemProvider binding"); // binding.setStory(data); // binding.executePendingBindings(); // } // } // // }
import com.chad.library.adapter.base.BaseProviderMultiAdapter; import com.chad.library.adapter.base.module.LoadMoreModule; import com.liuguangqiang.idaily.entity.BaseEntity; import com.liuguangqiang.idaily.entity.StorySection; import com.liuguangqiang.idaily.adapter.ItemProvider.SectionItemProvider; import com.liuguangqiang.idaily.adapter.ItemProvider.StoryItemProvider; import org.jetbrains.annotations.Nullable; import java.util.List;
package com.liuguangqiang.idaily.adapter; /** * 首页列表adapter * * Created by Eric at 2021/7/31 */ public class StoriesAdapter extends BaseProviderMultiAdapter<BaseEntity> implements LoadMoreModule { public static final int ITEM_STORY = 0; public static final int ITEM_SECTION = 1; public StoriesAdapter(@Nullable List<BaseEntity> data) { super(data);
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/BaseEntity.java // public class BaseEntity implements MultiItemEntity { // // @Override // public int getItemType() { // return 0; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/entity/StorySection.java // public class StorySection extends BaseEntity { // // public int datetime; // // public StorySection(int datetime) { // this.datetime = datetime; // } // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_SECTION; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/ItemProvider/SectionItemProvider.java // public class SectionItemProvider<T> extends BaseItemProvider<StorySection> { // // @Override // public int getItemViewType() { // return StoriesAdapter.ITEM_SECTION; // } // // @Override // public int getLayoutId() { // return R.layout.item_story_header; // } // // @Override // public void onViewHolderCreated(BaseViewHolder viewHolder, int viewType) { // DataBindingUtil.bind(viewHolder.itemView); // } // // @Override // public void convert(@NotNull BaseViewHolder helper, @NotNull StorySection data) { // ItemStoryHeaderBinding binding =DataBindingUtil.getBinding(helper.itemView); // if (binding != null) { // binding.setSection(data); // binding.executePendingBindings(); // } // } // // } // // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/ItemProvider/StoryItemProvider.java // public class StoryItemProvider<T> extends BaseItemProvider<Story> { // // @Override // public int getItemViewType() { // return StoriesAdapter.ITEM_STORY; // } // // @Override // public int getLayoutId() { // return R.layout.item_story; // } // // @Override // public void onViewHolderCreated(BaseViewHolder viewHolder, int viewType) { // DataBindingUtil.bind(viewHolder.itemView); // } // // @Override // public void convert(@NotNull BaseViewHolder helper, @NotNull Story data) { // Timber.d("StoryItemProvider convert"); // ItemStoryBinding binding = DataBindingUtil.getBinding(helper.itemView); // if (binding != null) { // Timber.d("StoryItemProvider binding"); // binding.setStory(data); // binding.executePendingBindings(); // } // } // // } // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/StoriesAdapter.java import com.chad.library.adapter.base.BaseProviderMultiAdapter; import com.chad.library.adapter.base.module.LoadMoreModule; import com.liuguangqiang.idaily.entity.BaseEntity; import com.liuguangqiang.idaily.entity.StorySection; import com.liuguangqiang.idaily.adapter.ItemProvider.SectionItemProvider; import com.liuguangqiang.idaily.adapter.ItemProvider.StoryItemProvider; import org.jetbrains.annotations.Nullable; import java.util.List; package com.liuguangqiang.idaily.adapter; /** * 首页列表adapter * * Created by Eric at 2021/7/31 */ public class StoriesAdapter extends BaseProviderMultiAdapter<BaseEntity> implements LoadMoreModule { public static final int ITEM_STORY = 0; public static final int ITEM_SECTION = 1; public StoriesAdapter(@Nullable List<BaseEntity> data) { super(data);
addItemProvider(new StoryItemProvider());
liuguangqiang/Idaily
app/src/main/java/com/liuguangqiang/idaily/adapter/StoriesAdapter.java
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/BaseEntity.java // public class BaseEntity implements MultiItemEntity { // // @Override // public int getItemType() { // return 0; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/entity/StorySection.java // public class StorySection extends BaseEntity { // // public int datetime; // // public StorySection(int datetime) { // this.datetime = datetime; // } // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_SECTION; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/ItemProvider/SectionItemProvider.java // public class SectionItemProvider<T> extends BaseItemProvider<StorySection> { // // @Override // public int getItemViewType() { // return StoriesAdapter.ITEM_SECTION; // } // // @Override // public int getLayoutId() { // return R.layout.item_story_header; // } // // @Override // public void onViewHolderCreated(BaseViewHolder viewHolder, int viewType) { // DataBindingUtil.bind(viewHolder.itemView); // } // // @Override // public void convert(@NotNull BaseViewHolder helper, @NotNull StorySection data) { // ItemStoryHeaderBinding binding =DataBindingUtil.getBinding(helper.itemView); // if (binding != null) { // binding.setSection(data); // binding.executePendingBindings(); // } // } // // } // // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/ItemProvider/StoryItemProvider.java // public class StoryItemProvider<T> extends BaseItemProvider<Story> { // // @Override // public int getItemViewType() { // return StoriesAdapter.ITEM_STORY; // } // // @Override // public int getLayoutId() { // return R.layout.item_story; // } // // @Override // public void onViewHolderCreated(BaseViewHolder viewHolder, int viewType) { // DataBindingUtil.bind(viewHolder.itemView); // } // // @Override // public void convert(@NotNull BaseViewHolder helper, @NotNull Story data) { // Timber.d("StoryItemProvider convert"); // ItemStoryBinding binding = DataBindingUtil.getBinding(helper.itemView); // if (binding != null) { // Timber.d("StoryItemProvider binding"); // binding.setStory(data); // binding.executePendingBindings(); // } // } // // }
import com.chad.library.adapter.base.BaseProviderMultiAdapter; import com.chad.library.adapter.base.module.LoadMoreModule; import com.liuguangqiang.idaily.entity.BaseEntity; import com.liuguangqiang.idaily.entity.StorySection; import com.liuguangqiang.idaily.adapter.ItemProvider.SectionItemProvider; import com.liuguangqiang.idaily.adapter.ItemProvider.StoryItemProvider; import org.jetbrains.annotations.Nullable; import java.util.List;
package com.liuguangqiang.idaily.adapter; /** * 首页列表adapter * * Created by Eric at 2021/7/31 */ public class StoriesAdapter extends BaseProviderMultiAdapter<BaseEntity> implements LoadMoreModule { public static final int ITEM_STORY = 0; public static final int ITEM_SECTION = 1; public StoriesAdapter(@Nullable List<BaseEntity> data) { super(data); addItemProvider(new StoryItemProvider());
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/BaseEntity.java // public class BaseEntity implements MultiItemEntity { // // @Override // public int getItemType() { // return 0; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/entity/StorySection.java // public class StorySection extends BaseEntity { // // public int datetime; // // public StorySection(int datetime) { // this.datetime = datetime; // } // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_SECTION; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/ItemProvider/SectionItemProvider.java // public class SectionItemProvider<T> extends BaseItemProvider<StorySection> { // // @Override // public int getItemViewType() { // return StoriesAdapter.ITEM_SECTION; // } // // @Override // public int getLayoutId() { // return R.layout.item_story_header; // } // // @Override // public void onViewHolderCreated(BaseViewHolder viewHolder, int viewType) { // DataBindingUtil.bind(viewHolder.itemView); // } // // @Override // public void convert(@NotNull BaseViewHolder helper, @NotNull StorySection data) { // ItemStoryHeaderBinding binding =DataBindingUtil.getBinding(helper.itemView); // if (binding != null) { // binding.setSection(data); // binding.executePendingBindings(); // } // } // // } // // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/ItemProvider/StoryItemProvider.java // public class StoryItemProvider<T> extends BaseItemProvider<Story> { // // @Override // public int getItemViewType() { // return StoriesAdapter.ITEM_STORY; // } // // @Override // public int getLayoutId() { // return R.layout.item_story; // } // // @Override // public void onViewHolderCreated(BaseViewHolder viewHolder, int viewType) { // DataBindingUtil.bind(viewHolder.itemView); // } // // @Override // public void convert(@NotNull BaseViewHolder helper, @NotNull Story data) { // Timber.d("StoryItemProvider convert"); // ItemStoryBinding binding = DataBindingUtil.getBinding(helper.itemView); // if (binding != null) { // Timber.d("StoryItemProvider binding"); // binding.setStory(data); // binding.executePendingBindings(); // } // } // // } // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/StoriesAdapter.java import com.chad.library.adapter.base.BaseProviderMultiAdapter; import com.chad.library.adapter.base.module.LoadMoreModule; import com.liuguangqiang.idaily.entity.BaseEntity; import com.liuguangqiang.idaily.entity.StorySection; import com.liuguangqiang.idaily.adapter.ItemProvider.SectionItemProvider; import com.liuguangqiang.idaily.adapter.ItemProvider.StoryItemProvider; import org.jetbrains.annotations.Nullable; import java.util.List; package com.liuguangqiang.idaily.adapter; /** * 首页列表adapter * * Created by Eric at 2021/7/31 */ public class StoriesAdapter extends BaseProviderMultiAdapter<BaseEntity> implements LoadMoreModule { public static final int ITEM_STORY = 0; public static final int ITEM_SECTION = 1; public StoriesAdapter(@Nullable List<BaseEntity> data) { super(data); addItemProvider(new StoryItemProvider());
addItemProvider(new SectionItemProvider());
liuguangqiang/Idaily
app/src/main/java/com/liuguangqiang/idaily/adapter/StoriesAdapter.java
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/BaseEntity.java // public class BaseEntity implements MultiItemEntity { // // @Override // public int getItemType() { // return 0; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/entity/StorySection.java // public class StorySection extends BaseEntity { // // public int datetime; // // public StorySection(int datetime) { // this.datetime = datetime; // } // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_SECTION; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/ItemProvider/SectionItemProvider.java // public class SectionItemProvider<T> extends BaseItemProvider<StorySection> { // // @Override // public int getItemViewType() { // return StoriesAdapter.ITEM_SECTION; // } // // @Override // public int getLayoutId() { // return R.layout.item_story_header; // } // // @Override // public void onViewHolderCreated(BaseViewHolder viewHolder, int viewType) { // DataBindingUtil.bind(viewHolder.itemView); // } // // @Override // public void convert(@NotNull BaseViewHolder helper, @NotNull StorySection data) { // ItemStoryHeaderBinding binding =DataBindingUtil.getBinding(helper.itemView); // if (binding != null) { // binding.setSection(data); // binding.executePendingBindings(); // } // } // // } // // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/ItemProvider/StoryItemProvider.java // public class StoryItemProvider<T> extends BaseItemProvider<Story> { // // @Override // public int getItemViewType() { // return StoriesAdapter.ITEM_STORY; // } // // @Override // public int getLayoutId() { // return R.layout.item_story; // } // // @Override // public void onViewHolderCreated(BaseViewHolder viewHolder, int viewType) { // DataBindingUtil.bind(viewHolder.itemView); // } // // @Override // public void convert(@NotNull BaseViewHolder helper, @NotNull Story data) { // Timber.d("StoryItemProvider convert"); // ItemStoryBinding binding = DataBindingUtil.getBinding(helper.itemView); // if (binding != null) { // Timber.d("StoryItemProvider binding"); // binding.setStory(data); // binding.executePendingBindings(); // } // } // // }
import com.chad.library.adapter.base.BaseProviderMultiAdapter; import com.chad.library.adapter.base.module.LoadMoreModule; import com.liuguangqiang.idaily.entity.BaseEntity; import com.liuguangqiang.idaily.entity.StorySection; import com.liuguangqiang.idaily.adapter.ItemProvider.SectionItemProvider; import com.liuguangqiang.idaily.adapter.ItemProvider.StoryItemProvider; import org.jetbrains.annotations.Nullable; import java.util.List;
package com.liuguangqiang.idaily.adapter; /** * 首页列表adapter * * Created by Eric at 2021/7/31 */ public class StoriesAdapter extends BaseProviderMultiAdapter<BaseEntity> implements LoadMoreModule { public static final int ITEM_STORY = 0; public static final int ITEM_SECTION = 1; public StoriesAdapter(@Nullable List<BaseEntity> data) { super(data); addItemProvider(new StoryItemProvider()); addItemProvider(new SectionItemProvider()); } @Override protected int getItemType(List<? extends BaseEntity> list, int i) {
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/BaseEntity.java // public class BaseEntity implements MultiItemEntity { // // @Override // public int getItemType() { // return 0; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/entity/StorySection.java // public class StorySection extends BaseEntity { // // public int datetime; // // public StorySection(int datetime) { // this.datetime = datetime; // } // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_SECTION; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/ItemProvider/SectionItemProvider.java // public class SectionItemProvider<T> extends BaseItemProvider<StorySection> { // // @Override // public int getItemViewType() { // return StoriesAdapter.ITEM_SECTION; // } // // @Override // public int getLayoutId() { // return R.layout.item_story_header; // } // // @Override // public void onViewHolderCreated(BaseViewHolder viewHolder, int viewType) { // DataBindingUtil.bind(viewHolder.itemView); // } // // @Override // public void convert(@NotNull BaseViewHolder helper, @NotNull StorySection data) { // ItemStoryHeaderBinding binding =DataBindingUtil.getBinding(helper.itemView); // if (binding != null) { // binding.setSection(data); // binding.executePendingBindings(); // } // } // // } // // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/ItemProvider/StoryItemProvider.java // public class StoryItemProvider<T> extends BaseItemProvider<Story> { // // @Override // public int getItemViewType() { // return StoriesAdapter.ITEM_STORY; // } // // @Override // public int getLayoutId() { // return R.layout.item_story; // } // // @Override // public void onViewHolderCreated(BaseViewHolder viewHolder, int viewType) { // DataBindingUtil.bind(viewHolder.itemView); // } // // @Override // public void convert(@NotNull BaseViewHolder helper, @NotNull Story data) { // Timber.d("StoryItemProvider convert"); // ItemStoryBinding binding = DataBindingUtil.getBinding(helper.itemView); // if (binding != null) { // Timber.d("StoryItemProvider binding"); // binding.setStory(data); // binding.executePendingBindings(); // } // } // // } // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/StoriesAdapter.java import com.chad.library.adapter.base.BaseProviderMultiAdapter; import com.chad.library.adapter.base.module.LoadMoreModule; import com.liuguangqiang.idaily.entity.BaseEntity; import com.liuguangqiang.idaily.entity.StorySection; import com.liuguangqiang.idaily.adapter.ItemProvider.SectionItemProvider; import com.liuguangqiang.idaily.adapter.ItemProvider.StoryItemProvider; import org.jetbrains.annotations.Nullable; import java.util.List; package com.liuguangqiang.idaily.adapter; /** * 首页列表adapter * * Created by Eric at 2021/7/31 */ public class StoriesAdapter extends BaseProviderMultiAdapter<BaseEntity> implements LoadMoreModule { public static final int ITEM_STORY = 0; public static final int ITEM_SECTION = 1; public StoriesAdapter(@Nullable List<BaseEntity> data) { super(data); addItemProvider(new StoryItemProvider()); addItemProvider(new SectionItemProvider()); } @Override protected int getItemType(List<? extends BaseEntity> list, int i) {
if (getItem(i) instanceof StorySection) {
liuguangqiang/Idaily
app/src/main/java/com/liuguangqiang/idaily/adapter/ItemProvider/StoryItemProvider.java
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/Story.java // public class Story extends BaseEntity implements Parcelable { // // public int id; // // public String title; // // public int type = 0; // // public List<String> images = new ArrayList<>(); // // public String image; // // public String body; // // public List<String> css; // // public String share_url; // // public String hint; // // public List<String> getCss() { // return css; // } // // public void setCss(List<String> css) { // this.css = css; // } // // public String getBody() { // return body; // } // // public void setBody(String body) { // this.body = body; // } // // public String getImage() { // return image; // } // // public void setImage(String image) { // this.image = image; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // // public List<String> getImages() { // return images; // } // // public void setImages(List<String> images) { // this.images = images; // } // // public int getType() { // return type; // } // // public void setType(int type) { // this.type = type; // } // // public Story() { // } // // public int getId() { // return id; // } // // public void setId(int id) { // this.id = id; // } // // @Override // public String toString() { // return "Story{" + // "id=" + id + // ", title='" + title + '\'' + // ", type=" + type + // ", images=" + images + // ", image='" + image + '\'' + // ", body='" + body + '\'' + // ", css=" + css + // '}'; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(this.id); // dest.writeString(this.title); // dest.writeInt(this.type); // dest.writeStringList(this.images); // dest.writeString(this.image); // dest.writeString(this.body); // dest.writeStringList(this.css); // dest.writeString(this.share_url); // } // // protected Story(Parcel in) { // this.id = in.readInt(); // this.title = in.readString(); // this.type = in.readInt(); // this.images = in.createStringArrayList(); // this.image = in.readString(); // this.body = in.readString(); // this.css = in.createStringArrayList(); // this.share_url = in.readString(); // } // // public static final Creator<Story> CREATOR = new Creator<Story>() { // public Story createFromParcel(Parcel source) { // return new Story(source); // } // // public Story[] newArray(int size) { // return new Story[size]; // } // }; // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_STORY; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/StoriesAdapter.java // public class StoriesAdapter extends BaseProviderMultiAdapter<BaseEntity> implements LoadMoreModule { // // public static final int ITEM_STORY = 0; // // public static final int ITEM_SECTION = 1; // // public StoriesAdapter(@Nullable List<BaseEntity> data) { // super(data); // addItemProvider(new StoryItemProvider()); // addItemProvider(new SectionItemProvider()); // } // // @Override // protected int getItemType(List<? extends BaseEntity> list, int i) { // if (getItem(i) instanceof StorySection) { // return ITEM_SECTION; // } // return ITEM_STORY; // } // }
import androidx.databinding.DataBindingUtil; import com.chad.library.adapter.base.provider.BaseItemProvider; import com.chad.library.adapter.base.viewholder.BaseViewHolder; import com.liuguangqiang.idaily.R; import com.liuguangqiang.idaily.databinding.ItemStoryBinding; import com.liuguangqiang.idaily.entity.Story; import com.liuguangqiang.idaily.adapter.StoriesAdapter; import org.jetbrains.annotations.NotNull; import timber.log.Timber;
package com.liuguangqiang.idaily.adapter.ItemProvider; /** * Created by Eric at 2021/8/2 */ public class StoryItemProvider<T> extends BaseItemProvider<Story> { @Override public int getItemViewType() {
// Path: app/src/main/java/com/liuguangqiang/idaily/entity/Story.java // public class Story extends BaseEntity implements Parcelable { // // public int id; // // public String title; // // public int type = 0; // // public List<String> images = new ArrayList<>(); // // public String image; // // public String body; // // public List<String> css; // // public String share_url; // // public String hint; // // public List<String> getCss() { // return css; // } // // public void setCss(List<String> css) { // this.css = css; // } // // public String getBody() { // return body; // } // // public void setBody(String body) { // this.body = body; // } // // public String getImage() { // return image; // } // // public void setImage(String image) { // this.image = image; // } // // public String getTitle() { // return title; // } // // public void setTitle(String title) { // this.title = title; // } // // public List<String> getImages() { // return images; // } // // public void setImages(List<String> images) { // this.images = images; // } // // public int getType() { // return type; // } // // public void setType(int type) { // this.type = type; // } // // public Story() { // } // // public int getId() { // return id; // } // // public void setId(int id) { // this.id = id; // } // // @Override // public String toString() { // return "Story{" + // "id=" + id + // ", title='" + title + '\'' + // ", type=" + type + // ", images=" + images + // ", image='" + image + '\'' + // ", body='" + body + '\'' + // ", css=" + css + // '}'; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeInt(this.id); // dest.writeString(this.title); // dest.writeInt(this.type); // dest.writeStringList(this.images); // dest.writeString(this.image); // dest.writeString(this.body); // dest.writeStringList(this.css); // dest.writeString(this.share_url); // } // // protected Story(Parcel in) { // this.id = in.readInt(); // this.title = in.readString(); // this.type = in.readInt(); // this.images = in.createStringArrayList(); // this.image = in.readString(); // this.body = in.readString(); // this.css = in.createStringArrayList(); // this.share_url = in.readString(); // } // // public static final Creator<Story> CREATOR = new Creator<Story>() { // public Story createFromParcel(Parcel source) { // return new Story(source); // } // // public Story[] newArray(int size) { // return new Story[size]; // } // }; // // @Override // public int getItemType() { // return StoriesAdapter.ITEM_STORY; // } // } // // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/StoriesAdapter.java // public class StoriesAdapter extends BaseProviderMultiAdapter<BaseEntity> implements LoadMoreModule { // // public static final int ITEM_STORY = 0; // // public static final int ITEM_SECTION = 1; // // public StoriesAdapter(@Nullable List<BaseEntity> data) { // super(data); // addItemProvider(new StoryItemProvider()); // addItemProvider(new SectionItemProvider()); // } // // @Override // protected int getItemType(List<? extends BaseEntity> list, int i) { // if (getItem(i) instanceof StorySection) { // return ITEM_SECTION; // } // return ITEM_STORY; // } // } // Path: app/src/main/java/com/liuguangqiang/idaily/adapter/ItemProvider/StoryItemProvider.java import androidx.databinding.DataBindingUtil; import com.chad.library.adapter.base.provider.BaseItemProvider; import com.chad.library.adapter.base.viewholder.BaseViewHolder; import com.liuguangqiang.idaily.R; import com.liuguangqiang.idaily.databinding.ItemStoryBinding; import com.liuguangqiang.idaily.entity.Story; import com.liuguangqiang.idaily.adapter.StoriesAdapter; import org.jetbrains.annotations.NotNull; import timber.log.Timber; package com.liuguangqiang.idaily.adapter.ItemProvider; /** * Created by Eric at 2021/8/2 */ public class StoryItemProvider<T> extends BaseItemProvider<Story> { @Override public int getItemViewType() {
return StoriesAdapter.ITEM_STORY;
liuguangqiang/Idaily
app/src/main/java/com/liuguangqiang/idaily/entity/Story.java
// Path: app/src/main/java/com/liuguangqiang/idaily/adapter/StoriesAdapter.java // public class StoriesAdapter extends BaseProviderMultiAdapter<BaseEntity> implements LoadMoreModule { // // public static final int ITEM_STORY = 0; // // public static final int ITEM_SECTION = 1; // // public StoriesAdapter(@Nullable List<BaseEntity> data) { // super(data); // addItemProvider(new StoryItemProvider()); // addItemProvider(new SectionItemProvider()); // } // // @Override // protected int getItemType(List<? extends BaseEntity> list, int i) { // if (getItem(i) instanceof StorySection) { // return ITEM_SECTION; // } // return ITEM_STORY; // } // }
import android.os.Parcel; import android.os.Parcelable; import com.liuguangqiang.idaily.adapter.StoriesAdapter; import java.util.ArrayList; import java.util.List;
dest.writeStringList(this.images); dest.writeString(this.image); dest.writeString(this.body); dest.writeStringList(this.css); dest.writeString(this.share_url); } protected Story(Parcel in) { this.id = in.readInt(); this.title = in.readString(); this.type = in.readInt(); this.images = in.createStringArrayList(); this.image = in.readString(); this.body = in.readString(); this.css = in.createStringArrayList(); this.share_url = in.readString(); } public static final Creator<Story> CREATOR = new Creator<Story>() { public Story createFromParcel(Parcel source) { return new Story(source); } public Story[] newArray(int size) { return new Story[size]; } }; @Override public int getItemType() {
// Path: app/src/main/java/com/liuguangqiang/idaily/adapter/StoriesAdapter.java // public class StoriesAdapter extends BaseProviderMultiAdapter<BaseEntity> implements LoadMoreModule { // // public static final int ITEM_STORY = 0; // // public static final int ITEM_SECTION = 1; // // public StoriesAdapter(@Nullable List<BaseEntity> data) { // super(data); // addItemProvider(new StoryItemProvider()); // addItemProvider(new SectionItemProvider()); // } // // @Override // protected int getItemType(List<? extends BaseEntity> list, int i) { // if (getItem(i) instanceof StorySection) { // return ITEM_SECTION; // } // return ITEM_STORY; // } // } // Path: app/src/main/java/com/liuguangqiang/idaily/entity/Story.java import android.os.Parcel; import android.os.Parcelable; import com.liuguangqiang.idaily.adapter.StoriesAdapter; import java.util.ArrayList; import java.util.List; dest.writeStringList(this.images); dest.writeString(this.image); dest.writeString(this.body); dest.writeStringList(this.css); dest.writeString(this.share_url); } protected Story(Parcel in) { this.id = in.readInt(); this.title = in.readString(); this.type = in.readInt(); this.images = in.createStringArrayList(); this.image = in.readString(); this.body = in.readString(); this.css = in.createStringArrayList(); this.share_url = in.readString(); } public static final Creator<Story> CREATOR = new Creator<Story>() { public Story createFromParcel(Parcel source) { return new Story(source); } public Story[] newArray(int size) { return new Story[size]; } }; @Override public int getItemType() {
return StoriesAdapter.ITEM_STORY;