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 |
|---|---|---|---|---|---|---|
pac4j/jax-rs-pac4j | jersey/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
| import org.glassfish.jersey.internal.inject.AbstractBinder;
import org.glassfish.jersey.internal.inject.InjectionResolver;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.ContainerRequest;
import org.glassfish.jersey.server.internal.inject.AbstractValueParamProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueParamProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.ext.Providers;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier; |
if(manager == null){
bind(DefaultProfileManagerFactoryBuilder.class)
.to(ProfileManagerFactoryBuilder.class).in(Singleton.class);
} else {
bind(manager).to(ProfileManagerFactoryBuilder.class);
}
bindAsContract(Pac4JProfileValueFactoryProvider.class).to(ValueParamProvider.class).in(Singleton.class);
bindAsContract(ProfileInjectionResolver.class)
.to(new GenericType<InjectionResolver<Pac4JProfile>>(){})
.in(Singleton.class);
bindAsContract(ProfileManagerInjectionResolver.class)
.to(new GenericType<InjectionResolver<Pac4JProfileManager>>(){})
.in(Singleton.class);
}
}
static class ProfileManagerValueFactory implements ProfileManagerFactory{
@Context
private final Providers providers;
ProfileManagerValueFactory(Providers providers) {
this.providers = providers;
}
@Override
public ProfileManager<CommonProfile> apply(ContainerRequest containerRequest) { | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
// Path: jersey/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java
import org.glassfish.jersey.internal.inject.AbstractBinder;
import org.glassfish.jersey.internal.inject.InjectionResolver;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.ContainerRequest;
import org.glassfish.jersey.server.internal.inject.AbstractValueParamProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueParamProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.ext.Providers;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
if(manager == null){
bind(DefaultProfileManagerFactoryBuilder.class)
.to(ProfileManagerFactoryBuilder.class).in(Singleton.class);
} else {
bind(manager).to(ProfileManagerFactoryBuilder.class);
}
bindAsContract(Pac4JProfileValueFactoryProvider.class).to(ValueParamProvider.class).in(Singleton.class);
bindAsContract(ProfileInjectionResolver.class)
.to(new GenericType<InjectionResolver<Pac4JProfile>>(){})
.in(Singleton.class);
bindAsContract(ProfileManagerInjectionResolver.class)
.to(new GenericType<InjectionResolver<Pac4JProfileManager>>(){})
.in(Singleton.class);
}
}
static class ProfileManagerValueFactory implements ProfileManagerFactory{
@Context
private final Providers providers;
ProfileManagerValueFactory(Providers providers) {
this.providers = providers;
}
@Override
public ProfileManager<CommonProfile> apply(ContainerRequest containerRequest) { | return new RequestProfileManager(new RequestJaxRsContext(providers, containerRequest)) |
pac4j/jax-rs-pac4j | jersey/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
| import org.glassfish.jersey.internal.inject.AbstractBinder;
import org.glassfish.jersey.internal.inject.InjectionResolver;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.ContainerRequest;
import org.glassfish.jersey.server.internal.inject.AbstractValueParamProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueParamProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.ext.Providers;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier; | ProfileManagerValueFactory(Providers providers) {
this.providers = providers;
}
@Override
public ProfileManager<CommonProfile> apply(ContainerRequest containerRequest) {
return new RequestProfileManager(new RequestJaxRsContext(providers, containerRequest))
.profileManager();
}
}
static class ProfileValueFactory implements ProfileFactory {
@Override
public UserProfile apply(ContainerRequest containerRequest) {
return optionalProfile(containerRequest)
.orElseThrow(() -> {
LOG.debug("Cannot inject a Pac4j profile into an unauthenticated request, responding with 401");
return new WebApplicationException(401);
});
}
}
static class OptionalProfileValueFactory implements OptionalProfileFactory {
@Override
public Optional<UserProfile> apply(ContainerRequest containerRequest) {
return optionalProfile(containerRequest);
}
}
private static Optional<UserProfile> optionalProfile(ContainerRequest containerRequest) { | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
// Path: jersey/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java
import org.glassfish.jersey.internal.inject.AbstractBinder;
import org.glassfish.jersey.internal.inject.InjectionResolver;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.ContainerRequest;
import org.glassfish.jersey.server.internal.inject.AbstractValueParamProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueParamProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.ext.Providers;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
ProfileManagerValueFactory(Providers providers) {
this.providers = providers;
}
@Override
public ProfileManager<CommonProfile> apply(ContainerRequest containerRequest) {
return new RequestProfileManager(new RequestJaxRsContext(providers, containerRequest))
.profileManager();
}
}
static class ProfileValueFactory implements ProfileFactory {
@Override
public UserProfile apply(ContainerRequest containerRequest) {
return optionalProfile(containerRequest)
.orElseThrow(() -> {
LOG.debug("Cannot inject a Pac4j profile into an unauthenticated request, responding with 401");
return new WebApplicationException(401);
});
}
}
static class OptionalProfileValueFactory implements OptionalProfileFactory {
@Override
public Optional<UserProfile> apply(ContainerRequest containerRequest) {
return optionalProfile(containerRequest);
}
}
private static Optional<UserProfile> optionalProfile(ContainerRequest containerRequest) { | RequestPac4JSecurityContext securityContext = new RequestPac4JSecurityContext(containerRequest); |
pac4j/jax-rs-pac4j | jersey/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
| import org.glassfish.jersey.internal.inject.AbstractBinder;
import org.glassfish.jersey.internal.inject.InjectionResolver;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.ContainerRequest;
import org.glassfish.jersey.server.internal.inject.AbstractValueParamProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueParamProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.ext.Providers;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier; | this.providers = providers;
}
@Override
public ProfileManager<CommonProfile> apply(ContainerRequest containerRequest) {
return new RequestProfileManager(new RequestJaxRsContext(providers, containerRequest))
.profileManager();
}
}
static class ProfileValueFactory implements ProfileFactory {
@Override
public UserProfile apply(ContainerRequest containerRequest) {
return optionalProfile(containerRequest)
.orElseThrow(() -> {
LOG.debug("Cannot inject a Pac4j profile into an unauthenticated request, responding with 401");
return new WebApplicationException(401);
});
}
}
static class OptionalProfileValueFactory implements OptionalProfileFactory {
@Override
public Optional<UserProfile> apply(ContainerRequest containerRequest) {
return optionalProfile(containerRequest);
}
}
private static Optional<UserProfile> optionalProfile(ContainerRequest containerRequest) {
RequestPac4JSecurityContext securityContext = new RequestPac4JSecurityContext(containerRequest); | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
// Path: jersey/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java
import org.glassfish.jersey.internal.inject.AbstractBinder;
import org.glassfish.jersey.internal.inject.InjectionResolver;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.ContainerRequest;
import org.glassfish.jersey.server.internal.inject.AbstractValueParamProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueParamProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.ext.Providers;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
this.providers = providers;
}
@Override
public ProfileManager<CommonProfile> apply(ContainerRequest containerRequest) {
return new RequestProfileManager(new RequestJaxRsContext(providers, containerRequest))
.profileManager();
}
}
static class ProfileValueFactory implements ProfileFactory {
@Override
public UserProfile apply(ContainerRequest containerRequest) {
return optionalProfile(containerRequest)
.orElseThrow(() -> {
LOG.debug("Cannot inject a Pac4j profile into an unauthenticated request, responding with 401");
return new WebApplicationException(401);
});
}
}
static class OptionalProfileValueFactory implements OptionalProfileFactory {
@Override
public Optional<UserProfile> apply(ContainerRequest containerRequest) {
return optionalProfile(containerRequest);
}
}
private static Optional<UserProfile> optionalProfile(ContainerRequest containerRequest) {
RequestPac4JSecurityContext securityContext = new RequestPac4JSecurityContext(containerRequest); | return new RequestUserProfile(securityContext).profile(); |
pac4j/jax-rs-pac4j | core/src/main/java/org/pac4j/jax/rs/features/Pac4JSecurityFilterFeature.java | // Path: core/src/main/java/org/pac4j/jax/rs/filters/SecurityFilter.java
// @Priority(Priorities.AUTHENTICATION)
// public class SecurityFilter extends AbstractFilter {
//
// private SecurityLogic<Object, JaxRsContext> securityLogic;
//
// private String clients;
//
// private String authorizers;
//
// private String matchers;
//
// private Boolean multiProfile;
//
// public SecurityFilter(Providers providers) {
// super(providers);
// }
//
// @Override
// protected void filter(JaxRsContext context) throws IOException {
//
// Config config = getConfig();
//
// // Note: basically, there is two possible outcomes:
// // either the access is granted or there was an error or a redirect!
// // For the former, we do nothing (see SecurityGrantedAccessOutcome comments)
// // For the later, we interpret the error and abort the request using jax-rs abstractions
// buildLogic(config).perform(context, config, new SecurityGrantedAccessOutcome(), adapter(config), clients,
// authorizers, matchers, multiProfile);
// }
//
// protected SecurityLogic<Object, JaxRsContext> buildLogic(Config config) {
// if (securityLogic != null) {
// return securityLogic;
// } else if (config.getSecurityLogic() != null) {
// return config.getSecurityLogic();
// } else {
// DefaultSecurityLogic<Object, JaxRsContext> logic = new DefaultSecurityLogic<>();
// logic.setProfileManagerFactory(ctx -> new JaxRsProfileManager((JaxRsContext) ctx));
// return logic;
// }
// }
//
// public String getClients() {
// return clients;
// }
//
// public void setClients(String clients) {
// this.clients = clients;
// }
//
// public String getAuthorizers() {
// return authorizers;
// }
//
// public void setAuthorizers(String authorizers) {
// this.authorizers = authorizers;
// }
//
// public String getMatchers() {
// return matchers;
// }
//
// public void setMatchers(String matchers) {
// this.matchers = matchers;
// }
//
// public boolean getMultiProfile() {
// return multiProfile;
// }
//
// public void setMultiProfile(Boolean multiProfile) {
// this.multiProfile = multiProfile;
// }
//
// public SecurityLogic<Object, JaxRsContext> getSecurityLogic() {
// return securityLogic;
// }
//
// public void setSecurityLogic(SecurityLogic<Object, JaxRsContext> securityLogic) {
// this.securityLogic = securityLogic;
// }
//
// private static class SecurityGrantedAccessOutcome implements SecurityGrantedAccessAdapter<Object, JaxRsContext> {
// @Override
// public Object adapt(JaxRsContext context, Collection<UserProfile> profiles, Object... parameters) {
// SecurityContext original = context.getRequestContext().getSecurityContext();
// context.getRequestContext().setSecurityContext(new Pac4JSecurityContext(original, context, profiles));
// return null;
// }
// }
// }
| import javax.ws.rs.core.Context;
import javax.ws.rs.core.Feature;
import javax.ws.rs.core.FeatureContext;
import javax.ws.rs.ext.Providers;
import org.pac4j.jax.rs.filters.SecurityFilter; | package org.pac4j.jax.rs.features;
/**
*
* Registers a global {@link SecurityFilter} to protect all the URLs served by the JAX-RS runtime.
*
* TODO Normally we would want to register directly {@link SecurityFilter} but because of
* https://java.net/jira/browse/JERSEY-3167, we can't make it implement {@link Feature}. This is why we need this
* {@link Feature} in order to handle the injection when we want to register a {@link SecurityFilter} as a global
* {@link Feature}.
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class Pac4JSecurityFilterFeature implements Feature {
@Context
private Providers providers;
private final Boolean skipResponse;
private final String authorizers;
private final String clients;
private final String matchers;
private final Boolean multiProfile;
public Pac4JSecurityFilterFeature() {
this(null, null, null, null, null);
}
public Pac4JSecurityFilterFeature(Boolean skipResponse, String authorizers, String clients, String matchers,
Boolean multiProfile) {
this.skipResponse = skipResponse;
this.authorizers = authorizers;
this.clients = clients;
this.matchers = matchers;
this.multiProfile = multiProfile;
}
@Override
public boolean configure(FeatureContext context) { | // Path: core/src/main/java/org/pac4j/jax/rs/filters/SecurityFilter.java
// @Priority(Priorities.AUTHENTICATION)
// public class SecurityFilter extends AbstractFilter {
//
// private SecurityLogic<Object, JaxRsContext> securityLogic;
//
// private String clients;
//
// private String authorizers;
//
// private String matchers;
//
// private Boolean multiProfile;
//
// public SecurityFilter(Providers providers) {
// super(providers);
// }
//
// @Override
// protected void filter(JaxRsContext context) throws IOException {
//
// Config config = getConfig();
//
// // Note: basically, there is two possible outcomes:
// // either the access is granted or there was an error or a redirect!
// // For the former, we do nothing (see SecurityGrantedAccessOutcome comments)
// // For the later, we interpret the error and abort the request using jax-rs abstractions
// buildLogic(config).perform(context, config, new SecurityGrantedAccessOutcome(), adapter(config), clients,
// authorizers, matchers, multiProfile);
// }
//
// protected SecurityLogic<Object, JaxRsContext> buildLogic(Config config) {
// if (securityLogic != null) {
// return securityLogic;
// } else if (config.getSecurityLogic() != null) {
// return config.getSecurityLogic();
// } else {
// DefaultSecurityLogic<Object, JaxRsContext> logic = new DefaultSecurityLogic<>();
// logic.setProfileManagerFactory(ctx -> new JaxRsProfileManager((JaxRsContext) ctx));
// return logic;
// }
// }
//
// public String getClients() {
// return clients;
// }
//
// public void setClients(String clients) {
// this.clients = clients;
// }
//
// public String getAuthorizers() {
// return authorizers;
// }
//
// public void setAuthorizers(String authorizers) {
// this.authorizers = authorizers;
// }
//
// public String getMatchers() {
// return matchers;
// }
//
// public void setMatchers(String matchers) {
// this.matchers = matchers;
// }
//
// public boolean getMultiProfile() {
// return multiProfile;
// }
//
// public void setMultiProfile(Boolean multiProfile) {
// this.multiProfile = multiProfile;
// }
//
// public SecurityLogic<Object, JaxRsContext> getSecurityLogic() {
// return securityLogic;
// }
//
// public void setSecurityLogic(SecurityLogic<Object, JaxRsContext> securityLogic) {
// this.securityLogic = securityLogic;
// }
//
// private static class SecurityGrantedAccessOutcome implements SecurityGrantedAccessAdapter<Object, JaxRsContext> {
// @Override
// public Object adapt(JaxRsContext context, Collection<UserProfile> profiles, Object... parameters) {
// SecurityContext original = context.getRequestContext().getSecurityContext();
// context.getRequestContext().setSecurityContext(new Pac4JSecurityContext(original, context, profiles));
// return null;
// }
// }
// }
// Path: core/src/main/java/org/pac4j/jax/rs/features/Pac4JSecurityFilterFeature.java
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Feature;
import javax.ws.rs.core.FeatureContext;
import javax.ws.rs.ext.Providers;
import org.pac4j.jax.rs.filters.SecurityFilter;
package org.pac4j.jax.rs.features;
/**
*
* Registers a global {@link SecurityFilter} to protect all the URLs served by the JAX-RS runtime.
*
* TODO Normally we would want to register directly {@link SecurityFilter} but because of
* https://java.net/jira/browse/JERSEY-3167, we can't make it implement {@link Feature}. This is why we need this
* {@link Feature} in order to handle the injection when we want to register a {@link SecurityFilter} as a global
* {@link Feature}.
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class Pac4JSecurityFilterFeature implements Feature {
@Context
private Providers providers;
private final Boolean skipResponse;
private final String authorizers;
private final String clients;
private final String matchers;
private final Boolean multiProfile;
public Pac4JSecurityFilterFeature() {
this(null, null, null, null, null);
}
public Pac4JSecurityFilterFeature(Boolean skipResponse, String authorizers, String clients, String matchers,
Boolean multiProfile) {
this.skipResponse = skipResponse;
this.authorizers = authorizers;
this.clients = clients;
this.matchers = matchers;
this.multiProfile = multiProfile;
}
@Override
public boolean configure(FeatureContext context) { | final SecurityFilter filter = new SecurityFilter(providers); |
pac4j/jax-rs-pac4j | resteasy/src/main/java/org/pac4j/jax/rs/resteasy/helpers/RestEasyRequestContext.java | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
| import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.ext.Providers;
import org.jboss.resteasy.core.interception.PreMatchContainerRequestContext;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext; | package org.pac4j.jax.rs.resteasy.helpers;
/**
* @author Victor Noel
* @since 2.2.0
*/
public class RestEasyRequestContext extends RequestJaxRsContext {
public RestEasyRequestContext(Providers providers) {
this(providers, ResteasyProviderFactory.getContextData(HttpRequest.class));
}
public RestEasyRequestContext(Providers providers, HttpRequest request) {
super(providers, | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
// Path: resteasy/src/main/java/org/pac4j/jax/rs/resteasy/helpers/RestEasyRequestContext.java
import javax.ws.rs.core.SecurityContext;
import javax.ws.rs.ext.Providers;
import org.jboss.resteasy.core.interception.PreMatchContainerRequestContext;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
package org.pac4j.jax.rs.resteasy.helpers;
/**
* @author Victor Noel
* @since 2.2.0
*/
public class RestEasyRequestContext extends RequestJaxRsContext {
public RestEasyRequestContext(Providers providers) {
this(providers, ResteasyProviderFactory.getContextData(HttpRequest.class));
}
public RestEasyRequestContext(Providers providers, HttpRequest request) {
super(providers, | new RequestPac4JSecurityContext(ResteasyProviderFactory.getContextData(SecurityContext.class)).context() |
pac4j/jax-rs-pac4j | jersey225/src/test/java/org/pac4j/jax/rs/rules/JerseyGrizzlyRule.java | // Path: jersey228/src/main/java/org/pac4j/jax/rs/grizzly/features/GrizzlyJaxRsContextFactoryProvider.java
// public class GrizzlyJaxRsContextFactoryProvider extends JaxRsContextFactoryProvider {
//
// @Inject
// protected Provider<Request> requestProvider;
//
// @Override
// public JaxRsContextFactory getContext(Class<?> type) {
// Request request = requestProvider.get();
// assert request != null;
// return context -> new GrizzlyJaxRsContext(getProviders(), context, getConfig().getSessionStore(), request);
// }
// }
//
// Path: jersey225/src/test/java/org/pac4j/jax/rs/resources/JerseyResource.java
// @Path("/containerSpecific")
// public class JerseyResource {
//
// @Context
// private Providers providers;
//
// @Inject
// private ContainerRequestContext requestContext;
//
// @POST
// @Path("/securitycontext")
// @Pac4JSecurity(clients = "DirectFormClient", authorizers = DefaultAuthorizers.IS_AUTHENTICATED)
// public String directSecurityContext() {
// // Note: SecurityContext injected via @Context can't be cast
// SecurityContext context = requestContext.getSecurityContext();
// if (context != null) {
// if (context instanceof Pac4JSecurityContext) {
// return "ok";
// } else {
// return "fail";
// }
// } else {
// return "error";
// }
// }
//
// @POST
// @Path("/context")
// @Pac4JSecurity(clients = "DirectFormClient", authorizers = DefaultAuthorizers.IS_AUTHENTICATED)
// public String directContext() {
// JaxRsContext context = new ProvidersContext(providers).resolveNotNull(JaxRsContextFactory.class)
// .provides(requestContext);
// if (context != null) {
// return "ok";
// } else {
// return "fail";
// }
// }
// }
| import java.util.Set;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.DeploymentContext;
import org.glassfish.jersey.test.grizzly.GrizzlyTestContainerFactory;
import org.glassfish.jersey.test.spi.TestContainerFactory;
import org.pac4j.jax.rs.grizzly.features.GrizzlyJaxRsContextFactoryProvider;
import org.pac4j.jax.rs.resources.JerseyResource; | package org.pac4j.jax.rs.rules;
public class JerseyGrizzlyRule extends JerseyRule implements SessionContainerRule {
@Override
public Set<Class<?>> getResources() {
Set<Class<?>> resources = SessionContainerRule.super.getResources(); | // Path: jersey228/src/main/java/org/pac4j/jax/rs/grizzly/features/GrizzlyJaxRsContextFactoryProvider.java
// public class GrizzlyJaxRsContextFactoryProvider extends JaxRsContextFactoryProvider {
//
// @Inject
// protected Provider<Request> requestProvider;
//
// @Override
// public JaxRsContextFactory getContext(Class<?> type) {
// Request request = requestProvider.get();
// assert request != null;
// return context -> new GrizzlyJaxRsContext(getProviders(), context, getConfig().getSessionStore(), request);
// }
// }
//
// Path: jersey225/src/test/java/org/pac4j/jax/rs/resources/JerseyResource.java
// @Path("/containerSpecific")
// public class JerseyResource {
//
// @Context
// private Providers providers;
//
// @Inject
// private ContainerRequestContext requestContext;
//
// @POST
// @Path("/securitycontext")
// @Pac4JSecurity(clients = "DirectFormClient", authorizers = DefaultAuthorizers.IS_AUTHENTICATED)
// public String directSecurityContext() {
// // Note: SecurityContext injected via @Context can't be cast
// SecurityContext context = requestContext.getSecurityContext();
// if (context != null) {
// if (context instanceof Pac4JSecurityContext) {
// return "ok";
// } else {
// return "fail";
// }
// } else {
// return "error";
// }
// }
//
// @POST
// @Path("/context")
// @Pac4JSecurity(clients = "DirectFormClient", authorizers = DefaultAuthorizers.IS_AUTHENTICATED)
// public String directContext() {
// JaxRsContext context = new ProvidersContext(providers).resolveNotNull(JaxRsContextFactory.class)
// .provides(requestContext);
// if (context != null) {
// return "ok";
// } else {
// return "fail";
// }
// }
// }
// Path: jersey225/src/test/java/org/pac4j/jax/rs/rules/JerseyGrizzlyRule.java
import java.util.Set;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.DeploymentContext;
import org.glassfish.jersey.test.grizzly.GrizzlyTestContainerFactory;
import org.glassfish.jersey.test.spi.TestContainerFactory;
import org.pac4j.jax.rs.grizzly.features.GrizzlyJaxRsContextFactoryProvider;
import org.pac4j.jax.rs.resources.JerseyResource;
package org.pac4j.jax.rs.rules;
public class JerseyGrizzlyRule extends JerseyRule implements SessionContainerRule {
@Override
public Set<Class<?>> getResources() {
Set<Class<?>> resources = SessionContainerRule.super.getResources(); | resources.add(JerseyResource.class); |
pac4j/jax-rs-pac4j | jersey225/src/test/java/org/pac4j/jax/rs/rules/JerseyGrizzlyRule.java | // Path: jersey228/src/main/java/org/pac4j/jax/rs/grizzly/features/GrizzlyJaxRsContextFactoryProvider.java
// public class GrizzlyJaxRsContextFactoryProvider extends JaxRsContextFactoryProvider {
//
// @Inject
// protected Provider<Request> requestProvider;
//
// @Override
// public JaxRsContextFactory getContext(Class<?> type) {
// Request request = requestProvider.get();
// assert request != null;
// return context -> new GrizzlyJaxRsContext(getProviders(), context, getConfig().getSessionStore(), request);
// }
// }
//
// Path: jersey225/src/test/java/org/pac4j/jax/rs/resources/JerseyResource.java
// @Path("/containerSpecific")
// public class JerseyResource {
//
// @Context
// private Providers providers;
//
// @Inject
// private ContainerRequestContext requestContext;
//
// @POST
// @Path("/securitycontext")
// @Pac4JSecurity(clients = "DirectFormClient", authorizers = DefaultAuthorizers.IS_AUTHENTICATED)
// public String directSecurityContext() {
// // Note: SecurityContext injected via @Context can't be cast
// SecurityContext context = requestContext.getSecurityContext();
// if (context != null) {
// if (context instanceof Pac4JSecurityContext) {
// return "ok";
// } else {
// return "fail";
// }
// } else {
// return "error";
// }
// }
//
// @POST
// @Path("/context")
// @Pac4JSecurity(clients = "DirectFormClient", authorizers = DefaultAuthorizers.IS_AUTHENTICATED)
// public String directContext() {
// JaxRsContext context = new ProvidersContext(providers).resolveNotNull(JaxRsContextFactory.class)
// .provides(requestContext);
// if (context != null) {
// return "ok";
// } else {
// return "fail";
// }
// }
// }
| import java.util.Set;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.DeploymentContext;
import org.glassfish.jersey.test.grizzly.GrizzlyTestContainerFactory;
import org.glassfish.jersey.test.spi.TestContainerFactory;
import org.pac4j.jax.rs.grizzly.features.GrizzlyJaxRsContextFactoryProvider;
import org.pac4j.jax.rs.resources.JerseyResource; | package org.pac4j.jax.rs.rules;
public class JerseyGrizzlyRule extends JerseyRule implements SessionContainerRule {
@Override
public Set<Class<?>> getResources() {
Set<Class<?>> resources = SessionContainerRule.super.getResources();
resources.add(JerseyResource.class);
return resources;
}
@Override
protected TestContainerFactory getTestContainerFactory() {
return new GrizzlyTestContainerFactory();
}
@Override
protected DeploymentContext configureDeployment(ResourceConfig config) {
return DeploymentContext.builder(config).build();
}
@Override
protected ResourceConfig configureResourceConfig(ResourceConfig config) {
return super
.configureResourceConfig(config) | // Path: jersey228/src/main/java/org/pac4j/jax/rs/grizzly/features/GrizzlyJaxRsContextFactoryProvider.java
// public class GrizzlyJaxRsContextFactoryProvider extends JaxRsContextFactoryProvider {
//
// @Inject
// protected Provider<Request> requestProvider;
//
// @Override
// public JaxRsContextFactory getContext(Class<?> type) {
// Request request = requestProvider.get();
// assert request != null;
// return context -> new GrizzlyJaxRsContext(getProviders(), context, getConfig().getSessionStore(), request);
// }
// }
//
// Path: jersey225/src/test/java/org/pac4j/jax/rs/resources/JerseyResource.java
// @Path("/containerSpecific")
// public class JerseyResource {
//
// @Context
// private Providers providers;
//
// @Inject
// private ContainerRequestContext requestContext;
//
// @POST
// @Path("/securitycontext")
// @Pac4JSecurity(clients = "DirectFormClient", authorizers = DefaultAuthorizers.IS_AUTHENTICATED)
// public String directSecurityContext() {
// // Note: SecurityContext injected via @Context can't be cast
// SecurityContext context = requestContext.getSecurityContext();
// if (context != null) {
// if (context instanceof Pac4JSecurityContext) {
// return "ok";
// } else {
// return "fail";
// }
// } else {
// return "error";
// }
// }
//
// @POST
// @Path("/context")
// @Pac4JSecurity(clients = "DirectFormClient", authorizers = DefaultAuthorizers.IS_AUTHENTICATED)
// public String directContext() {
// JaxRsContext context = new ProvidersContext(providers).resolveNotNull(JaxRsContextFactory.class)
// .provides(requestContext);
// if (context != null) {
// return "ok";
// } else {
// return "fail";
// }
// }
// }
// Path: jersey225/src/test/java/org/pac4j/jax/rs/rules/JerseyGrizzlyRule.java
import java.util.Set;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.DeploymentContext;
import org.glassfish.jersey.test.grizzly.GrizzlyTestContainerFactory;
import org.glassfish.jersey.test.spi.TestContainerFactory;
import org.pac4j.jax.rs.grizzly.features.GrizzlyJaxRsContextFactoryProvider;
import org.pac4j.jax.rs.resources.JerseyResource;
package org.pac4j.jax.rs.rules;
public class JerseyGrizzlyRule extends JerseyRule implements SessionContainerRule {
@Override
public Set<Class<?>> getResources() {
Set<Class<?>> resources = SessionContainerRule.super.getResources();
resources.add(JerseyResource.class);
return resources;
}
@Override
protected TestContainerFactory getTestContainerFactory() {
return new GrizzlyTestContainerFactory();
}
@Override
protected DeploymentContext configureDeployment(ResourceConfig config) {
return DeploymentContext.builder(config).build();
}
@Override
protected ResourceConfig configureResourceConfig(ResourceConfig config) {
return super
.configureResourceConfig(config) | .register(new GrizzlyJaxRsContextFactoryProvider()); |
pac4j/jax-rs-pac4j | jersey228/src/main/java/org/pac4j/jax/rs/grizzly/features/GrizzlyJaxRsContextFactoryProvider.java | // Path: core/src/main/java/org/pac4j/jax/rs/features/JaxRsContextFactoryProvider.java
// public class JaxRsContextFactoryProvider implements ContextResolver<JaxRsContextFactory> {
//
// @Context
// private Providers providers;
//
// @Override
// public JaxRsContextFactory getContext(Class<?> type) {
// return context -> new JaxRsContext(getProviders(), context, getConfig().getSessionStore());
// }
//
// protected Providers getProviders() {
// assert providers != null;
// return providers;
// }
//
// protected Config getConfig() {
// return new ProvidersContext(providers).resolveNotNull(Config.class);
// }
//
// /**
// * We need to provide a factory because it is not possible to get the {@link ContainerRequestContext} injected
// * directly here...
// */
// @FunctionalInterface
// public interface JaxRsContextFactory {
// JaxRsContext provides(ContainerRequestContext context);
// }
// }
//
// Path: jersey228/src/main/java/org/pac4j/jax/rs/grizzly/pac4j/GrizzlyJaxRsContext.java
// public class GrizzlyJaxRsContext extends JaxRsContext {
//
// private final Request request;
//
// public GrizzlyJaxRsContext(Providers providers, ContainerRequestContext requestContext,
// SessionStore sessionStore, Request request) {
// super(providers, requestContext, sessionStore != null ? sessionStore : new GrizzlySessionStore());
// this.request = request;
// }
//
// public Request getRequest() {
// return request;
// }
//
// @Override
// public String getRemoteAddr() {
// return request.getRemoteAddr();
// }
// }
| import org.glassfish.grizzly.http.server.Request;
import org.pac4j.jax.rs.features.JaxRsContextFactoryProvider;
import org.pac4j.jax.rs.grizzly.pac4j.GrizzlyJaxRsContext;
import javax.inject.Inject;
import javax.inject.Provider; | package org.pac4j.jax.rs.grizzly.features;
/**
*
* Extends {@link JaxRsContextFactoryProvider} to support the Grizzly container (without the need for servlet support)
* and its session manager (i.e., pac4j indirect clients will work, contrary than with
* {@link JaxRsContextFactoryProvider}).
*
* @see JaxRsContextFactoryProvider
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class GrizzlyJaxRsContextFactoryProvider extends JaxRsContextFactoryProvider {
@Inject
protected Provider<Request> requestProvider;
@Override
public JaxRsContextFactory getContext(Class<?> type) {
Request request = requestProvider.get();
assert request != null; | // Path: core/src/main/java/org/pac4j/jax/rs/features/JaxRsContextFactoryProvider.java
// public class JaxRsContextFactoryProvider implements ContextResolver<JaxRsContextFactory> {
//
// @Context
// private Providers providers;
//
// @Override
// public JaxRsContextFactory getContext(Class<?> type) {
// return context -> new JaxRsContext(getProviders(), context, getConfig().getSessionStore());
// }
//
// protected Providers getProviders() {
// assert providers != null;
// return providers;
// }
//
// protected Config getConfig() {
// return new ProvidersContext(providers).resolveNotNull(Config.class);
// }
//
// /**
// * We need to provide a factory because it is not possible to get the {@link ContainerRequestContext} injected
// * directly here...
// */
// @FunctionalInterface
// public interface JaxRsContextFactory {
// JaxRsContext provides(ContainerRequestContext context);
// }
// }
//
// Path: jersey228/src/main/java/org/pac4j/jax/rs/grizzly/pac4j/GrizzlyJaxRsContext.java
// public class GrizzlyJaxRsContext extends JaxRsContext {
//
// private final Request request;
//
// public GrizzlyJaxRsContext(Providers providers, ContainerRequestContext requestContext,
// SessionStore sessionStore, Request request) {
// super(providers, requestContext, sessionStore != null ? sessionStore : new GrizzlySessionStore());
// this.request = request;
// }
//
// public Request getRequest() {
// return request;
// }
//
// @Override
// public String getRemoteAddr() {
// return request.getRemoteAddr();
// }
// }
// Path: jersey228/src/main/java/org/pac4j/jax/rs/grizzly/features/GrizzlyJaxRsContextFactoryProvider.java
import org.glassfish.grizzly.http.server.Request;
import org.pac4j.jax.rs.features.JaxRsContextFactoryProvider;
import org.pac4j.jax.rs.grizzly.pac4j.GrizzlyJaxRsContext;
import javax.inject.Inject;
import javax.inject.Provider;
package org.pac4j.jax.rs.grizzly.features;
/**
*
* Extends {@link JaxRsContextFactoryProvider} to support the Grizzly container (without the need for servlet support)
* and its session manager (i.e., pac4j indirect clients will work, contrary than with
* {@link JaxRsContextFactoryProvider}).
*
* @see JaxRsContextFactoryProvider
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class GrizzlyJaxRsContextFactoryProvider extends JaxRsContextFactoryProvider {
@Inject
protected Provider<Request> requestProvider;
@Override
public JaxRsContextFactory getContext(Class<?> type) {
Request request = requestProvider.get();
assert request != null; | return context -> new GrizzlyJaxRsContext(getProviders(), context, getConfig().getSessionStore(), request); |
pac4j/jax-rs-pac4j | jersey225/src/main/java/org/pac4j/jax/rs/grizzly/features/GrizzlyJaxRsContextFactoryProvider.java | // Path: core/src/main/java/org/pac4j/jax/rs/features/JaxRsContextFactoryProvider.java
// public class JaxRsContextFactoryProvider implements ContextResolver<JaxRsContextFactory> {
//
// @Context
// private Providers providers;
//
// @Override
// public JaxRsContextFactory getContext(Class<?> type) {
// return context -> new JaxRsContext(getProviders(), context, getConfig().getSessionStore());
// }
//
// protected Providers getProviders() {
// assert providers != null;
// return providers;
// }
//
// protected Config getConfig() {
// return new ProvidersContext(providers).resolveNotNull(Config.class);
// }
//
// /**
// * We need to provide a factory because it is not possible to get the {@link ContainerRequestContext} injected
// * directly here...
// */
// @FunctionalInterface
// public interface JaxRsContextFactory {
// JaxRsContext provides(ContainerRequestContext context);
// }
// }
//
// Path: jersey228/src/main/java/org/pac4j/jax/rs/grizzly/pac4j/GrizzlyJaxRsContext.java
// public class GrizzlyJaxRsContext extends JaxRsContext {
//
// private final Request request;
//
// public GrizzlyJaxRsContext(Providers providers, ContainerRequestContext requestContext,
// SessionStore sessionStore, Request request) {
// super(providers, requestContext, sessionStore != null ? sessionStore : new GrizzlySessionStore());
// this.request = request;
// }
//
// public Request getRequest() {
// return request;
// }
//
// @Override
// public String getRemoteAddr() {
// return request.getRemoteAddr();
// }
// }
| import javax.inject.Inject;
import javax.inject.Provider;
import org.glassfish.grizzly.http.server.Request;
import org.pac4j.jax.rs.features.JaxRsContextFactoryProvider;
import org.pac4j.jax.rs.grizzly.pac4j.GrizzlyJaxRsContext; | package org.pac4j.jax.rs.grizzly.features;
/**
*
* Extends {@link JaxRsContextFactoryProvider} to support the Grizzly container (without the need for servlet support)
* and its session manager (i.e., pac4j indirect clients will work, contrary than with
* {@link JaxRsContextFactoryProvider}).
*
* @see JaxRsContextFactoryProvider
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class GrizzlyJaxRsContextFactoryProvider extends JaxRsContextFactoryProvider {
@Inject
protected Provider<Request> requestProvider;
@Override
public JaxRsContextFactory getContext(Class<?> type) {
Request request = requestProvider.get();
assert request != null; | // Path: core/src/main/java/org/pac4j/jax/rs/features/JaxRsContextFactoryProvider.java
// public class JaxRsContextFactoryProvider implements ContextResolver<JaxRsContextFactory> {
//
// @Context
// private Providers providers;
//
// @Override
// public JaxRsContextFactory getContext(Class<?> type) {
// return context -> new JaxRsContext(getProviders(), context, getConfig().getSessionStore());
// }
//
// protected Providers getProviders() {
// assert providers != null;
// return providers;
// }
//
// protected Config getConfig() {
// return new ProvidersContext(providers).resolveNotNull(Config.class);
// }
//
// /**
// * We need to provide a factory because it is not possible to get the {@link ContainerRequestContext} injected
// * directly here...
// */
// @FunctionalInterface
// public interface JaxRsContextFactory {
// JaxRsContext provides(ContainerRequestContext context);
// }
// }
//
// Path: jersey228/src/main/java/org/pac4j/jax/rs/grizzly/pac4j/GrizzlyJaxRsContext.java
// public class GrizzlyJaxRsContext extends JaxRsContext {
//
// private final Request request;
//
// public GrizzlyJaxRsContext(Providers providers, ContainerRequestContext requestContext,
// SessionStore sessionStore, Request request) {
// super(providers, requestContext, sessionStore != null ? sessionStore : new GrizzlySessionStore());
// this.request = request;
// }
//
// public Request getRequest() {
// return request;
// }
//
// @Override
// public String getRemoteAddr() {
// return request.getRemoteAddr();
// }
// }
// Path: jersey225/src/main/java/org/pac4j/jax/rs/grizzly/features/GrizzlyJaxRsContextFactoryProvider.java
import javax.inject.Inject;
import javax.inject.Provider;
import org.glassfish.grizzly.http.server.Request;
import org.pac4j.jax.rs.features.JaxRsContextFactoryProvider;
import org.pac4j.jax.rs.grizzly.pac4j.GrizzlyJaxRsContext;
package org.pac4j.jax.rs.grizzly.features;
/**
*
* Extends {@link JaxRsContextFactoryProvider} to support the Grizzly container (without the need for servlet support)
* and its session manager (i.e., pac4j indirect clients will work, contrary than with
* {@link JaxRsContextFactoryProvider}).
*
* @see JaxRsContextFactoryProvider
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class GrizzlyJaxRsContextFactoryProvider extends JaxRsContextFactoryProvider {
@Inject
protected Provider<Request> requestProvider;
@Override
public JaxRsContextFactory getContext(Class<?> type) {
Request request = requestProvider.get();
assert request != null; | return context -> new GrizzlyJaxRsContext(getProviders(), context, getConfig().getSessionStore(), request); |
pac4j/jax-rs-pac4j | resteasy/src/main/java/org/pac4j/jax/rs/resteasy/features/Pac4JProfileInjectorFactory.java | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
//
// Path: resteasy/src/main/java/org/pac4j/jax/rs/resteasy/helpers/RestEasyRequestContext.java
// public class RestEasyRequestContext extends RequestJaxRsContext {
//
// public RestEasyRequestContext(Providers providers) {
// this(providers, ResteasyProviderFactory.getContextData(HttpRequest.class));
// }
//
// public RestEasyRequestContext(Providers providers, HttpRequest request) {
// super(providers,
// new RequestPac4JSecurityContext(ResteasyProviderFactory.getContextData(SecurityContext.class)).context()
// // if we went through a pac4j security filter
// .map(sc -> sc.getContext().getRequestContext())
// // if not, we create a new ContainerRequestContext
// .orElse(new PreMatchContainerRequestContext(request)));
// }
// }
| import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Type;
import java.util.Optional;
import java.util.function.Function;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.ext.Provider;
import org.jboss.resteasy.core.InjectorFactoryImpl;
import org.jboss.resteasy.core.ValueInjector;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.HttpResponse;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.spi.metadata.Parameter;
import org.jboss.resteasy.util.FindAnnotation;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.pac4j.jax.rs.resteasy.helpers.RestEasyRequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package org.pac4j.jax.rs.resteasy.features;
/**
* @author Yegor Gemba
* @since 2.1.0
*/
@Provider
public class Pac4JProfileInjectorFactory extends InjectorFactoryImpl {
private static Logger LOG = LoggerFactory.getLogger(Pac4JProfileInjectorFactory.class);
@Override
public ValueInjector createParameterExtractor(Class injectTargetClass, AccessibleObject injectTarget, Class type,
Type genericType, Annotation[] annotations, ResteasyProviderFactory factory) {
final ValueInjector injector = getValueInjector(type, annotations, factory);
if (injector != null)
return injector;
return super.createParameterExtractor(injectTargetClass, injectTarget, type, genericType, annotations, factory);
}
@Override
public ValueInjector createParameterExtractor(Parameter parameter, ResteasyProviderFactory providerFactory) {
final ValueInjector injector = getValueInjector(parameter.getType(), parameter.getAnnotations(),
providerFactory);
if (injector != null)
return injector;
return super.createParameterExtractor(parameter, providerFactory);
}
private ValueInjector getValueInjector(Class type, Annotation[] annotations,
ResteasyProviderFactory providerFactory) {
if (FindAnnotation.findAnnotation(annotations, Pac4JProfile.class) != null) {
if (type.equals(Optional.class)) {
return new Pac4JValueInjector(providerFactory, rc -> rc.context() | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
//
// Path: resteasy/src/main/java/org/pac4j/jax/rs/resteasy/helpers/RestEasyRequestContext.java
// public class RestEasyRequestContext extends RequestJaxRsContext {
//
// public RestEasyRequestContext(Providers providers) {
// this(providers, ResteasyProviderFactory.getContextData(HttpRequest.class));
// }
//
// public RestEasyRequestContext(Providers providers, HttpRequest request) {
// super(providers,
// new RequestPac4JSecurityContext(ResteasyProviderFactory.getContextData(SecurityContext.class)).context()
// // if we went through a pac4j security filter
// .map(sc -> sc.getContext().getRequestContext())
// // if not, we create a new ContainerRequestContext
// .orElse(new PreMatchContainerRequestContext(request)));
// }
// }
// Path: resteasy/src/main/java/org/pac4j/jax/rs/resteasy/features/Pac4JProfileInjectorFactory.java
import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Type;
import java.util.Optional;
import java.util.function.Function;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.ext.Provider;
import org.jboss.resteasy.core.InjectorFactoryImpl;
import org.jboss.resteasy.core.ValueInjector;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.HttpResponse;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.spi.metadata.Parameter;
import org.jboss.resteasy.util.FindAnnotation;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.pac4j.jax.rs.resteasy.helpers.RestEasyRequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package org.pac4j.jax.rs.resteasy.features;
/**
* @author Yegor Gemba
* @since 2.1.0
*/
@Provider
public class Pac4JProfileInjectorFactory extends InjectorFactoryImpl {
private static Logger LOG = LoggerFactory.getLogger(Pac4JProfileInjectorFactory.class);
@Override
public ValueInjector createParameterExtractor(Class injectTargetClass, AccessibleObject injectTarget, Class type,
Type genericType, Annotation[] annotations, ResteasyProviderFactory factory) {
final ValueInjector injector = getValueInjector(type, annotations, factory);
if (injector != null)
return injector;
return super.createParameterExtractor(injectTargetClass, injectTarget, type, genericType, annotations, factory);
}
@Override
public ValueInjector createParameterExtractor(Parameter parameter, ResteasyProviderFactory providerFactory) {
final ValueInjector injector = getValueInjector(parameter.getType(), parameter.getAnnotations(),
providerFactory);
if (injector != null)
return injector;
return super.createParameterExtractor(parameter, providerFactory);
}
private ValueInjector getValueInjector(Class type, Annotation[] annotations,
ResteasyProviderFactory providerFactory) {
if (FindAnnotation.findAnnotation(annotations, Pac4JProfile.class) != null) {
if (type.equals(Optional.class)) {
return new Pac4JValueInjector(providerFactory, rc -> rc.context() | .flatMap(c -> new RequestUserProfile(new RequestPac4JSecurityContext(c)).profile())); |
pac4j/jax-rs-pac4j | resteasy/src/main/java/org/pac4j/jax/rs/resteasy/features/Pac4JProfileInjectorFactory.java | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
//
// Path: resteasy/src/main/java/org/pac4j/jax/rs/resteasy/helpers/RestEasyRequestContext.java
// public class RestEasyRequestContext extends RequestJaxRsContext {
//
// public RestEasyRequestContext(Providers providers) {
// this(providers, ResteasyProviderFactory.getContextData(HttpRequest.class));
// }
//
// public RestEasyRequestContext(Providers providers, HttpRequest request) {
// super(providers,
// new RequestPac4JSecurityContext(ResteasyProviderFactory.getContextData(SecurityContext.class)).context()
// // if we went through a pac4j security filter
// .map(sc -> sc.getContext().getRequestContext())
// // if not, we create a new ContainerRequestContext
// .orElse(new PreMatchContainerRequestContext(request)));
// }
// }
| import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Type;
import java.util.Optional;
import java.util.function.Function;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.ext.Provider;
import org.jboss.resteasy.core.InjectorFactoryImpl;
import org.jboss.resteasy.core.ValueInjector;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.HttpResponse;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.spi.metadata.Parameter;
import org.jboss.resteasy.util.FindAnnotation;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.pac4j.jax.rs.resteasy.helpers.RestEasyRequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | package org.pac4j.jax.rs.resteasy.features;
/**
* @author Yegor Gemba
* @since 2.1.0
*/
@Provider
public class Pac4JProfileInjectorFactory extends InjectorFactoryImpl {
private static Logger LOG = LoggerFactory.getLogger(Pac4JProfileInjectorFactory.class);
@Override
public ValueInjector createParameterExtractor(Class injectTargetClass, AccessibleObject injectTarget, Class type,
Type genericType, Annotation[] annotations, ResteasyProviderFactory factory) {
final ValueInjector injector = getValueInjector(type, annotations, factory);
if (injector != null)
return injector;
return super.createParameterExtractor(injectTargetClass, injectTarget, type, genericType, annotations, factory);
}
@Override
public ValueInjector createParameterExtractor(Parameter parameter, ResteasyProviderFactory providerFactory) {
final ValueInjector injector = getValueInjector(parameter.getType(), parameter.getAnnotations(),
providerFactory);
if (injector != null)
return injector;
return super.createParameterExtractor(parameter, providerFactory);
}
private ValueInjector getValueInjector(Class type, Annotation[] annotations,
ResteasyProviderFactory providerFactory) {
if (FindAnnotation.findAnnotation(annotations, Pac4JProfile.class) != null) {
if (type.equals(Optional.class)) {
return new Pac4JValueInjector(providerFactory, rc -> rc.context() | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
//
// Path: resteasy/src/main/java/org/pac4j/jax/rs/resteasy/helpers/RestEasyRequestContext.java
// public class RestEasyRequestContext extends RequestJaxRsContext {
//
// public RestEasyRequestContext(Providers providers) {
// this(providers, ResteasyProviderFactory.getContextData(HttpRequest.class));
// }
//
// public RestEasyRequestContext(Providers providers, HttpRequest request) {
// super(providers,
// new RequestPac4JSecurityContext(ResteasyProviderFactory.getContextData(SecurityContext.class)).context()
// // if we went through a pac4j security filter
// .map(sc -> sc.getContext().getRequestContext())
// // if not, we create a new ContainerRequestContext
// .orElse(new PreMatchContainerRequestContext(request)));
// }
// }
// Path: resteasy/src/main/java/org/pac4j/jax/rs/resteasy/features/Pac4JProfileInjectorFactory.java
import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Type;
import java.util.Optional;
import java.util.function.Function;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.ext.Provider;
import org.jboss.resteasy.core.InjectorFactoryImpl;
import org.jboss.resteasy.core.ValueInjector;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.HttpResponse;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.spi.metadata.Parameter;
import org.jboss.resteasy.util.FindAnnotation;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.pac4j.jax.rs.resteasy.helpers.RestEasyRequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
package org.pac4j.jax.rs.resteasy.features;
/**
* @author Yegor Gemba
* @since 2.1.0
*/
@Provider
public class Pac4JProfileInjectorFactory extends InjectorFactoryImpl {
private static Logger LOG = LoggerFactory.getLogger(Pac4JProfileInjectorFactory.class);
@Override
public ValueInjector createParameterExtractor(Class injectTargetClass, AccessibleObject injectTarget, Class type,
Type genericType, Annotation[] annotations, ResteasyProviderFactory factory) {
final ValueInjector injector = getValueInjector(type, annotations, factory);
if (injector != null)
return injector;
return super.createParameterExtractor(injectTargetClass, injectTarget, type, genericType, annotations, factory);
}
@Override
public ValueInjector createParameterExtractor(Parameter parameter, ResteasyProviderFactory providerFactory) {
final ValueInjector injector = getValueInjector(parameter.getType(), parameter.getAnnotations(),
providerFactory);
if (injector != null)
return injector;
return super.createParameterExtractor(parameter, providerFactory);
}
private ValueInjector getValueInjector(Class type, Annotation[] annotations,
ResteasyProviderFactory providerFactory) {
if (FindAnnotation.findAnnotation(annotations, Pac4JProfile.class) != null) {
if (type.equals(Optional.class)) {
return new Pac4JValueInjector(providerFactory, rc -> rc.context() | .flatMap(c -> new RequestUserProfile(new RequestPac4JSecurityContext(c)).profile())); |
pac4j/jax-rs-pac4j | resteasy/src/main/java/org/pac4j/jax/rs/resteasy/features/Pac4JProfileInjectorFactory.java | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
//
// Path: resteasy/src/main/java/org/pac4j/jax/rs/resteasy/helpers/RestEasyRequestContext.java
// public class RestEasyRequestContext extends RequestJaxRsContext {
//
// public RestEasyRequestContext(Providers providers) {
// this(providers, ResteasyProviderFactory.getContextData(HttpRequest.class));
// }
//
// public RestEasyRequestContext(Providers providers, HttpRequest request) {
// super(providers,
// new RequestPac4JSecurityContext(ResteasyProviderFactory.getContextData(SecurityContext.class)).context()
// // if we went through a pac4j security filter
// .map(sc -> sc.getContext().getRequestContext())
// // if not, we create a new ContainerRequestContext
// .orElse(new PreMatchContainerRequestContext(request)));
// }
// }
| import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Type;
import java.util.Optional;
import java.util.function.Function;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.ext.Provider;
import org.jboss.resteasy.core.InjectorFactoryImpl;
import org.jboss.resteasy.core.ValueInjector;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.HttpResponse;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.spi.metadata.Parameter;
import org.jboss.resteasy.util.FindAnnotation;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.pac4j.jax.rs.resteasy.helpers.RestEasyRequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | return injector;
return super.createParameterExtractor(injectTargetClass, injectTarget, type, genericType, annotations, factory);
}
@Override
public ValueInjector createParameterExtractor(Parameter parameter, ResteasyProviderFactory providerFactory) {
final ValueInjector injector = getValueInjector(parameter.getType(), parameter.getAnnotations(),
providerFactory);
if (injector != null)
return injector;
return super.createParameterExtractor(parameter, providerFactory);
}
private ValueInjector getValueInjector(Class type, Annotation[] annotations,
ResteasyProviderFactory providerFactory) {
if (FindAnnotation.findAnnotation(annotations, Pac4JProfile.class) != null) {
if (type.equals(Optional.class)) {
return new Pac4JValueInjector(providerFactory, rc -> rc.context()
.flatMap(c -> new RequestUserProfile(new RequestPac4JSecurityContext(c)).profile()));
} else {
return new Pac4JValueInjector(providerFactory,
rc -> rc.context()
.flatMap(c -> new RequestUserProfile(new RequestPac4JSecurityContext(c)).profile())
.orElseThrow(() -> {
LOG.debug(
"Cannot inject a Pac4j profile into an unauthenticated request, responding with 401");
return new WebApplicationException(401);
}));
}
} else if (FindAnnotation.findAnnotation(annotations, Pac4JProfileManager.class) != null) { | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
//
// Path: resteasy/src/main/java/org/pac4j/jax/rs/resteasy/helpers/RestEasyRequestContext.java
// public class RestEasyRequestContext extends RequestJaxRsContext {
//
// public RestEasyRequestContext(Providers providers) {
// this(providers, ResteasyProviderFactory.getContextData(HttpRequest.class));
// }
//
// public RestEasyRequestContext(Providers providers, HttpRequest request) {
// super(providers,
// new RequestPac4JSecurityContext(ResteasyProviderFactory.getContextData(SecurityContext.class)).context()
// // if we went through a pac4j security filter
// .map(sc -> sc.getContext().getRequestContext())
// // if not, we create a new ContainerRequestContext
// .orElse(new PreMatchContainerRequestContext(request)));
// }
// }
// Path: resteasy/src/main/java/org/pac4j/jax/rs/resteasy/features/Pac4JProfileInjectorFactory.java
import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Type;
import java.util.Optional;
import java.util.function.Function;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.ext.Provider;
import org.jboss.resteasy.core.InjectorFactoryImpl;
import org.jboss.resteasy.core.ValueInjector;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.HttpResponse;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.spi.metadata.Parameter;
import org.jboss.resteasy.util.FindAnnotation;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.pac4j.jax.rs.resteasy.helpers.RestEasyRequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
return injector;
return super.createParameterExtractor(injectTargetClass, injectTarget, type, genericType, annotations, factory);
}
@Override
public ValueInjector createParameterExtractor(Parameter parameter, ResteasyProviderFactory providerFactory) {
final ValueInjector injector = getValueInjector(parameter.getType(), parameter.getAnnotations(),
providerFactory);
if (injector != null)
return injector;
return super.createParameterExtractor(parameter, providerFactory);
}
private ValueInjector getValueInjector(Class type, Annotation[] annotations,
ResteasyProviderFactory providerFactory) {
if (FindAnnotation.findAnnotation(annotations, Pac4JProfile.class) != null) {
if (type.equals(Optional.class)) {
return new Pac4JValueInjector(providerFactory, rc -> rc.context()
.flatMap(c -> new RequestUserProfile(new RequestPac4JSecurityContext(c)).profile()));
} else {
return new Pac4JValueInjector(providerFactory,
rc -> rc.context()
.flatMap(c -> new RequestUserProfile(new RequestPac4JSecurityContext(c)).profile())
.orElseThrow(() -> {
LOG.debug(
"Cannot inject a Pac4j profile into an unauthenticated request, responding with 401");
return new WebApplicationException(401);
}));
}
} else if (FindAnnotation.findAnnotation(annotations, Pac4JProfileManager.class) != null) { | return new Pac4JValueInjector(providerFactory, c -> new RequestProfileManager(c).profileManager()); |
pac4j/jax-rs-pac4j | resteasy/src/main/java/org/pac4j/jax/rs/resteasy/features/Pac4JProfileInjectorFactory.java | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
//
// Path: resteasy/src/main/java/org/pac4j/jax/rs/resteasy/helpers/RestEasyRequestContext.java
// public class RestEasyRequestContext extends RequestJaxRsContext {
//
// public RestEasyRequestContext(Providers providers) {
// this(providers, ResteasyProviderFactory.getContextData(HttpRequest.class));
// }
//
// public RestEasyRequestContext(Providers providers, HttpRequest request) {
// super(providers,
// new RequestPac4JSecurityContext(ResteasyProviderFactory.getContextData(SecurityContext.class)).context()
// // if we went through a pac4j security filter
// .map(sc -> sc.getContext().getRequestContext())
// // if not, we create a new ContainerRequestContext
// .orElse(new PreMatchContainerRequestContext(request)));
// }
// }
| import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Type;
import java.util.Optional;
import java.util.function.Function;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.ext.Provider;
import org.jboss.resteasy.core.InjectorFactoryImpl;
import org.jboss.resteasy.core.ValueInjector;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.HttpResponse;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.spi.metadata.Parameter;
import org.jboss.resteasy.util.FindAnnotation;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.pac4j.jax.rs.resteasy.helpers.RestEasyRequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | providerFactory);
if (injector != null)
return injector;
return super.createParameterExtractor(parameter, providerFactory);
}
private ValueInjector getValueInjector(Class type, Annotation[] annotations,
ResteasyProviderFactory providerFactory) {
if (FindAnnotation.findAnnotation(annotations, Pac4JProfile.class) != null) {
if (type.equals(Optional.class)) {
return new Pac4JValueInjector(providerFactory, rc -> rc.context()
.flatMap(c -> new RequestUserProfile(new RequestPac4JSecurityContext(c)).profile()));
} else {
return new Pac4JValueInjector(providerFactory,
rc -> rc.context()
.flatMap(c -> new RequestUserProfile(new RequestPac4JSecurityContext(c)).profile())
.orElseThrow(() -> {
LOG.debug(
"Cannot inject a Pac4j profile into an unauthenticated request, responding with 401");
return new WebApplicationException(401);
}));
}
} else if (FindAnnotation.findAnnotation(annotations, Pac4JProfileManager.class) != null) {
return new Pac4JValueInjector(providerFactory, c -> new RequestProfileManager(c).profileManager());
} else {
return null;
}
}
public static class Pac4JValueInjector implements ValueInjector { | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
//
// Path: resteasy/src/main/java/org/pac4j/jax/rs/resteasy/helpers/RestEasyRequestContext.java
// public class RestEasyRequestContext extends RequestJaxRsContext {
//
// public RestEasyRequestContext(Providers providers) {
// this(providers, ResteasyProviderFactory.getContextData(HttpRequest.class));
// }
//
// public RestEasyRequestContext(Providers providers, HttpRequest request) {
// super(providers,
// new RequestPac4JSecurityContext(ResteasyProviderFactory.getContextData(SecurityContext.class)).context()
// // if we went through a pac4j security filter
// .map(sc -> sc.getContext().getRequestContext())
// // if not, we create a new ContainerRequestContext
// .orElse(new PreMatchContainerRequestContext(request)));
// }
// }
// Path: resteasy/src/main/java/org/pac4j/jax/rs/resteasy/features/Pac4JProfileInjectorFactory.java
import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Type;
import java.util.Optional;
import java.util.function.Function;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.ext.Provider;
import org.jboss.resteasy.core.InjectorFactoryImpl;
import org.jboss.resteasy.core.ValueInjector;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.HttpResponse;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.spi.metadata.Parameter;
import org.jboss.resteasy.util.FindAnnotation;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.pac4j.jax.rs.resteasy.helpers.RestEasyRequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
providerFactory);
if (injector != null)
return injector;
return super.createParameterExtractor(parameter, providerFactory);
}
private ValueInjector getValueInjector(Class type, Annotation[] annotations,
ResteasyProviderFactory providerFactory) {
if (FindAnnotation.findAnnotation(annotations, Pac4JProfile.class) != null) {
if (type.equals(Optional.class)) {
return new Pac4JValueInjector(providerFactory, rc -> rc.context()
.flatMap(c -> new RequestUserProfile(new RequestPac4JSecurityContext(c)).profile()));
} else {
return new Pac4JValueInjector(providerFactory,
rc -> rc.context()
.flatMap(c -> new RequestUserProfile(new RequestPac4JSecurityContext(c)).profile())
.orElseThrow(() -> {
LOG.debug(
"Cannot inject a Pac4j profile into an unauthenticated request, responding with 401");
return new WebApplicationException(401);
}));
}
} else if (FindAnnotation.findAnnotation(annotations, Pac4JProfileManager.class) != null) {
return new Pac4JValueInjector(providerFactory, c -> new RequestProfileManager(c).profileManager());
} else {
return null;
}
}
public static class Pac4JValueInjector implements ValueInjector { | private final Function<RequestJaxRsContext, Object> provider; |
pac4j/jax-rs-pac4j | resteasy/src/main/java/org/pac4j/jax/rs/resteasy/features/Pac4JProfileInjectorFactory.java | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
//
// Path: resteasy/src/main/java/org/pac4j/jax/rs/resteasy/helpers/RestEasyRequestContext.java
// public class RestEasyRequestContext extends RequestJaxRsContext {
//
// public RestEasyRequestContext(Providers providers) {
// this(providers, ResteasyProviderFactory.getContextData(HttpRequest.class));
// }
//
// public RestEasyRequestContext(Providers providers, HttpRequest request) {
// super(providers,
// new RequestPac4JSecurityContext(ResteasyProviderFactory.getContextData(SecurityContext.class)).context()
// // if we went through a pac4j security filter
// .map(sc -> sc.getContext().getRequestContext())
// // if not, we create a new ContainerRequestContext
// .orElse(new PreMatchContainerRequestContext(request)));
// }
// }
| import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Type;
import java.util.Optional;
import java.util.function.Function;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.ext.Provider;
import org.jboss.resteasy.core.InjectorFactoryImpl;
import org.jboss.resteasy.core.ValueInjector;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.HttpResponse;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.spi.metadata.Parameter;
import org.jboss.resteasy.util.FindAnnotation;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.pac4j.jax.rs.resteasy.helpers.RestEasyRequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | return new Pac4JValueInjector(providerFactory, rc -> rc.context()
.flatMap(c -> new RequestUserProfile(new RequestPac4JSecurityContext(c)).profile()));
} else {
return new Pac4JValueInjector(providerFactory,
rc -> rc.context()
.flatMap(c -> new RequestUserProfile(new RequestPac4JSecurityContext(c)).profile())
.orElseThrow(() -> {
LOG.debug(
"Cannot inject a Pac4j profile into an unauthenticated request, responding with 401");
return new WebApplicationException(401);
}));
}
} else if (FindAnnotation.findAnnotation(annotations, Pac4JProfileManager.class) != null) {
return new Pac4JValueInjector(providerFactory, c -> new RequestProfileManager(c).profileManager());
} else {
return null;
}
}
public static class Pac4JValueInjector implements ValueInjector {
private final Function<RequestJaxRsContext, Object> provider;
private final ResteasyProviderFactory providerFactory;
Pac4JValueInjector(ResteasyProviderFactory providerFactory, Function<RequestJaxRsContext, Object> provider) {
this.providerFactory = providerFactory;
this.provider = provider;
}
@Override
public Object inject(HttpRequest request, HttpResponse response) { | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
//
// Path: resteasy/src/main/java/org/pac4j/jax/rs/resteasy/helpers/RestEasyRequestContext.java
// public class RestEasyRequestContext extends RequestJaxRsContext {
//
// public RestEasyRequestContext(Providers providers) {
// this(providers, ResteasyProviderFactory.getContextData(HttpRequest.class));
// }
//
// public RestEasyRequestContext(Providers providers, HttpRequest request) {
// super(providers,
// new RequestPac4JSecurityContext(ResteasyProviderFactory.getContextData(SecurityContext.class)).context()
// // if we went through a pac4j security filter
// .map(sc -> sc.getContext().getRequestContext())
// // if not, we create a new ContainerRequestContext
// .orElse(new PreMatchContainerRequestContext(request)));
// }
// }
// Path: resteasy/src/main/java/org/pac4j/jax/rs/resteasy/features/Pac4JProfileInjectorFactory.java
import java.lang.annotation.Annotation;
import java.lang.reflect.AccessibleObject;
import java.lang.reflect.Type;
import java.util.Optional;
import java.util.function.Function;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.ext.Provider;
import org.jboss.resteasy.core.InjectorFactoryImpl;
import org.jboss.resteasy.core.ValueInjector;
import org.jboss.resteasy.spi.HttpRequest;
import org.jboss.resteasy.spi.HttpResponse;
import org.jboss.resteasy.spi.ResteasyProviderFactory;
import org.jboss.resteasy.spi.metadata.Parameter;
import org.jboss.resteasy.util.FindAnnotation;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.pac4j.jax.rs.resteasy.helpers.RestEasyRequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
return new Pac4JValueInjector(providerFactory, rc -> rc.context()
.flatMap(c -> new RequestUserProfile(new RequestPac4JSecurityContext(c)).profile()));
} else {
return new Pac4JValueInjector(providerFactory,
rc -> rc.context()
.flatMap(c -> new RequestUserProfile(new RequestPac4JSecurityContext(c)).profile())
.orElseThrow(() -> {
LOG.debug(
"Cannot inject a Pac4j profile into an unauthenticated request, responding with 401");
return new WebApplicationException(401);
}));
}
} else if (FindAnnotation.findAnnotation(annotations, Pac4JProfileManager.class) != null) {
return new Pac4JValueInjector(providerFactory, c -> new RequestProfileManager(c).profileManager());
} else {
return null;
}
}
public static class Pac4JValueInjector implements ValueInjector {
private final Function<RequestJaxRsContext, Object> provider;
private final ResteasyProviderFactory providerFactory;
Pac4JValueInjector(ResteasyProviderFactory providerFactory, Function<RequestJaxRsContext, Object> provider) {
this.providerFactory = providerFactory;
this.provider = provider;
}
@Override
public Object inject(HttpRequest request, HttpResponse response) { | return provider.apply(new RestEasyRequestContext(providerFactory, request)); |
pac4j/jax-rs-pac4j | jersey225/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
| import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.Providers;
import org.glassfish.hk2.api.Factory;
import org.glassfish.hk2.api.InjectionResolver;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.hk2.api.TypeLiteral;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.internal.inject.AbstractContainerRequestValueFactory;
import org.glassfish.jersey.server.internal.inject.AbstractValueFactoryProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueFactoryProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | * @param profile
* a profile supplier, can return <code>null</code>.
*/
public Binder(Supplier<CommonProfile> profile) {
this(() -> () -> profile.get(), () -> () -> Optional.ofNullable(profile.get()), null);
}
@Override
protected void configure() {
bind(profile).to(ProfileFactoryBuilder.class);
bind(optProfile).to(OptionalProfileFactoryBuilder.class);
bind(manager).to(ProfileManagerFactoryBuilder.class);
bind(Pac4JProfileValueFactoryProvider.class).to(ValueFactoryProvider.class).in(Singleton.class);
bind(ProfileInjectionResolver.class).to(new TypeLiteral<InjectionResolver<Pac4JProfile>>() {
}).in(Singleton.class);
bind(ProfileManagerInjectionResolver.class).to(new TypeLiteral<InjectionResolver<Pac4JProfileManager>>() {
}).in(Singleton.class);
}
}
static class ProfileManagerValueFactory extends AbstractContainerRequestValueFactory<ProfileManager<CommonProfile>>
implements ProfileManagerFactory {
@Context
Providers providers;
@Override
public ProfileManager<CommonProfile> provide() { | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
// Path: jersey225/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.Providers;
import org.glassfish.hk2.api.Factory;
import org.glassfish.hk2.api.InjectionResolver;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.hk2.api.TypeLiteral;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.internal.inject.AbstractContainerRequestValueFactory;
import org.glassfish.jersey.server.internal.inject.AbstractValueFactoryProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueFactoryProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @param profile
* a profile supplier, can return <code>null</code>.
*/
public Binder(Supplier<CommonProfile> profile) {
this(() -> () -> profile.get(), () -> () -> Optional.ofNullable(profile.get()), null);
}
@Override
protected void configure() {
bind(profile).to(ProfileFactoryBuilder.class);
bind(optProfile).to(OptionalProfileFactoryBuilder.class);
bind(manager).to(ProfileManagerFactoryBuilder.class);
bind(Pac4JProfileValueFactoryProvider.class).to(ValueFactoryProvider.class).in(Singleton.class);
bind(ProfileInjectionResolver.class).to(new TypeLiteral<InjectionResolver<Pac4JProfile>>() {
}).in(Singleton.class);
bind(ProfileManagerInjectionResolver.class).to(new TypeLiteral<InjectionResolver<Pac4JProfileManager>>() {
}).in(Singleton.class);
}
}
static class ProfileManagerValueFactory extends AbstractContainerRequestValueFactory<ProfileManager<CommonProfile>>
implements ProfileManagerFactory {
@Context
Providers providers;
@Override
public ProfileManager<CommonProfile> provide() { | return new RequestProfileManager(new RequestJaxRsContext(providers, getContainerRequest())) |
pac4j/jax-rs-pac4j | jersey225/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
| import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.Providers;
import org.glassfish.hk2.api.Factory;
import org.glassfish.hk2.api.InjectionResolver;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.hk2.api.TypeLiteral;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.internal.inject.AbstractContainerRequestValueFactory;
import org.glassfish.jersey.server.internal.inject.AbstractValueFactoryProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueFactoryProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | * @param profile
* a profile supplier, can return <code>null</code>.
*/
public Binder(Supplier<CommonProfile> profile) {
this(() -> () -> profile.get(), () -> () -> Optional.ofNullable(profile.get()), null);
}
@Override
protected void configure() {
bind(profile).to(ProfileFactoryBuilder.class);
bind(optProfile).to(OptionalProfileFactoryBuilder.class);
bind(manager).to(ProfileManagerFactoryBuilder.class);
bind(Pac4JProfileValueFactoryProvider.class).to(ValueFactoryProvider.class).in(Singleton.class);
bind(ProfileInjectionResolver.class).to(new TypeLiteral<InjectionResolver<Pac4JProfile>>() {
}).in(Singleton.class);
bind(ProfileManagerInjectionResolver.class).to(new TypeLiteral<InjectionResolver<Pac4JProfileManager>>() {
}).in(Singleton.class);
}
}
static class ProfileManagerValueFactory extends AbstractContainerRequestValueFactory<ProfileManager<CommonProfile>>
implements ProfileManagerFactory {
@Context
Providers providers;
@Override
public ProfileManager<CommonProfile> provide() { | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
// Path: jersey225/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.Providers;
import org.glassfish.hk2.api.Factory;
import org.glassfish.hk2.api.InjectionResolver;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.hk2.api.TypeLiteral;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.internal.inject.AbstractContainerRequestValueFactory;
import org.glassfish.jersey.server.internal.inject.AbstractValueFactoryProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueFactoryProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* @param profile
* a profile supplier, can return <code>null</code>.
*/
public Binder(Supplier<CommonProfile> profile) {
this(() -> () -> profile.get(), () -> () -> Optional.ofNullable(profile.get()), null);
}
@Override
protected void configure() {
bind(profile).to(ProfileFactoryBuilder.class);
bind(optProfile).to(OptionalProfileFactoryBuilder.class);
bind(manager).to(ProfileManagerFactoryBuilder.class);
bind(Pac4JProfileValueFactoryProvider.class).to(ValueFactoryProvider.class).in(Singleton.class);
bind(ProfileInjectionResolver.class).to(new TypeLiteral<InjectionResolver<Pac4JProfile>>() {
}).in(Singleton.class);
bind(ProfileManagerInjectionResolver.class).to(new TypeLiteral<InjectionResolver<Pac4JProfileManager>>() {
}).in(Singleton.class);
}
}
static class ProfileManagerValueFactory extends AbstractContainerRequestValueFactory<ProfileManager<CommonProfile>>
implements ProfileManagerFactory {
@Context
Providers providers;
@Override
public ProfileManager<CommonProfile> provide() { | return new RequestProfileManager(new RequestJaxRsContext(providers, getContainerRequest())) |
pac4j/jax-rs-pac4j | jersey225/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
| import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.Providers;
import org.glassfish.hk2.api.Factory;
import org.glassfish.hk2.api.InjectionResolver;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.hk2.api.TypeLiteral;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.internal.inject.AbstractContainerRequestValueFactory;
import org.glassfish.jersey.server.internal.inject.AbstractValueFactoryProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueFactoryProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | bind(profile).to(ProfileFactoryBuilder.class);
bind(optProfile).to(OptionalProfileFactoryBuilder.class);
bind(manager).to(ProfileManagerFactoryBuilder.class);
bind(Pac4JProfileValueFactoryProvider.class).to(ValueFactoryProvider.class).in(Singleton.class);
bind(ProfileInjectionResolver.class).to(new TypeLiteral<InjectionResolver<Pac4JProfile>>() {
}).in(Singleton.class);
bind(ProfileManagerInjectionResolver.class).to(new TypeLiteral<InjectionResolver<Pac4JProfileManager>>() {
}).in(Singleton.class);
}
}
static class ProfileManagerValueFactory extends AbstractContainerRequestValueFactory<ProfileManager<CommonProfile>>
implements ProfileManagerFactory {
@Context
Providers providers;
@Override
public ProfileManager<CommonProfile> provide() {
return new RequestProfileManager(new RequestJaxRsContext(providers, getContainerRequest()))
.profileManager();
}
}
static class ProfileValueFactory extends AbstractContainerRequestValueFactory<UserProfile>
implements ProfileFactory {
@Override
public UserProfile provide() { | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
// Path: jersey225/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.Providers;
import org.glassfish.hk2.api.Factory;
import org.glassfish.hk2.api.InjectionResolver;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.hk2.api.TypeLiteral;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.internal.inject.AbstractContainerRequestValueFactory;
import org.glassfish.jersey.server.internal.inject.AbstractValueFactoryProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueFactoryProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
bind(profile).to(ProfileFactoryBuilder.class);
bind(optProfile).to(OptionalProfileFactoryBuilder.class);
bind(manager).to(ProfileManagerFactoryBuilder.class);
bind(Pac4JProfileValueFactoryProvider.class).to(ValueFactoryProvider.class).in(Singleton.class);
bind(ProfileInjectionResolver.class).to(new TypeLiteral<InjectionResolver<Pac4JProfile>>() {
}).in(Singleton.class);
bind(ProfileManagerInjectionResolver.class).to(new TypeLiteral<InjectionResolver<Pac4JProfileManager>>() {
}).in(Singleton.class);
}
}
static class ProfileManagerValueFactory extends AbstractContainerRequestValueFactory<ProfileManager<CommonProfile>>
implements ProfileManagerFactory {
@Context
Providers providers;
@Override
public ProfileManager<CommonProfile> provide() {
return new RequestProfileManager(new RequestJaxRsContext(providers, getContainerRequest()))
.profileManager();
}
}
static class ProfileValueFactory extends AbstractContainerRequestValueFactory<UserProfile>
implements ProfileFactory {
@Override
public UserProfile provide() { | return new RequestUserProfile(new RequestPac4JSecurityContext(getContainerRequest())).profile() |
pac4j/jax-rs-pac4j | jersey225/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
| import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.Providers;
import org.glassfish.hk2.api.Factory;
import org.glassfish.hk2.api.InjectionResolver;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.hk2.api.TypeLiteral;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.internal.inject.AbstractContainerRequestValueFactory;
import org.glassfish.jersey.server.internal.inject.AbstractValueFactoryProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueFactoryProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory; | bind(profile).to(ProfileFactoryBuilder.class);
bind(optProfile).to(OptionalProfileFactoryBuilder.class);
bind(manager).to(ProfileManagerFactoryBuilder.class);
bind(Pac4JProfileValueFactoryProvider.class).to(ValueFactoryProvider.class).in(Singleton.class);
bind(ProfileInjectionResolver.class).to(new TypeLiteral<InjectionResolver<Pac4JProfile>>() {
}).in(Singleton.class);
bind(ProfileManagerInjectionResolver.class).to(new TypeLiteral<InjectionResolver<Pac4JProfileManager>>() {
}).in(Singleton.class);
}
}
static class ProfileManagerValueFactory extends AbstractContainerRequestValueFactory<ProfileManager<CommonProfile>>
implements ProfileManagerFactory {
@Context
Providers providers;
@Override
public ProfileManager<CommonProfile> provide() {
return new RequestProfileManager(new RequestJaxRsContext(providers, getContainerRequest()))
.profileManager();
}
}
static class ProfileValueFactory extends AbstractContainerRequestValueFactory<UserProfile>
implements ProfileFactory {
@Override
public UserProfile provide() { | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
// Path: jersey225/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java
import java.util.List;
import java.util.Optional;
import java.util.function.Supplier;
import javax.inject.Inject;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.Providers;
import org.glassfish.hk2.api.Factory;
import org.glassfish.hk2.api.InjectionResolver;
import org.glassfish.hk2.api.ServiceLocator;
import org.glassfish.hk2.api.TypeLiteral;
import org.glassfish.hk2.utilities.binding.AbstractBinder;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.internal.inject.AbstractContainerRequestValueFactory;
import org.glassfish.jersey.server.internal.inject.AbstractValueFactoryProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueFactoryProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
bind(profile).to(ProfileFactoryBuilder.class);
bind(optProfile).to(OptionalProfileFactoryBuilder.class);
bind(manager).to(ProfileManagerFactoryBuilder.class);
bind(Pac4JProfileValueFactoryProvider.class).to(ValueFactoryProvider.class).in(Singleton.class);
bind(ProfileInjectionResolver.class).to(new TypeLiteral<InjectionResolver<Pac4JProfile>>() {
}).in(Singleton.class);
bind(ProfileManagerInjectionResolver.class).to(new TypeLiteral<InjectionResolver<Pac4JProfileManager>>() {
}).in(Singleton.class);
}
}
static class ProfileManagerValueFactory extends AbstractContainerRequestValueFactory<ProfileManager<CommonProfile>>
implements ProfileManagerFactory {
@Context
Providers providers;
@Override
public ProfileManager<CommonProfile> provide() {
return new RequestProfileManager(new RequestJaxRsContext(providers, getContainerRequest()))
.profileManager();
}
}
static class ProfileValueFactory extends AbstractContainerRequestValueFactory<UserProfile>
implements ProfileFactory {
@Override
public UserProfile provide() { | return new RequestUserProfile(new RequestPac4JSecurityContext(getContainerRequest())).profile() |
pac4j/jax-rs-pac4j | jersey225/src/test/java/org/pac4j/jax/rs/JerseyGrizzlyTest.java | // Path: jersey225/src/test/java/org/pac4j/jax/rs/rules/JerseyGrizzlyRule.java
// public class JerseyGrizzlyRule extends JerseyRule implements SessionContainerRule {
//
// @Override
// public Set<Class<?>> getResources() {
// Set<Class<?>> resources = SessionContainerRule.super.getResources();
// resources.add(JerseyResource.class);
// return resources;
// }
//
// @Override
// protected TestContainerFactory getTestContainerFactory() {
// return new GrizzlyTestContainerFactory();
// }
//
// @Override
// protected DeploymentContext configureDeployment(ResourceConfig config) {
// return DeploymentContext.builder(config).build();
// }
//
// @Override
// protected ResourceConfig configureResourceConfig(ResourceConfig config) {
// return super
// .configureResourceConfig(config)
// .register(new GrizzlyJaxRsContextFactoryProvider());
// }
//
// }
//
// Path: testing/src/main/java/org/pac4j/jax/rs/rules/SessionContainerRule.java
// public interface SessionContainerRule extends ContainerRule {
//
// @Override
// default Set<Class<?>> getResources() {
// Set<Class<?>> resources = ContainerRule.super.getResources();
// resources.add(TestSessionResource.class);
// return resources;
// }
// }
| import org.pac4j.jax.rs.rules.JerseyGrizzlyRule;
import org.pac4j.jax.rs.rules.SessionContainerRule; | package org.pac4j.jax.rs;
/**
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class JerseyGrizzlyTest extends AbstractSessionTest {
@Override | // Path: jersey225/src/test/java/org/pac4j/jax/rs/rules/JerseyGrizzlyRule.java
// public class JerseyGrizzlyRule extends JerseyRule implements SessionContainerRule {
//
// @Override
// public Set<Class<?>> getResources() {
// Set<Class<?>> resources = SessionContainerRule.super.getResources();
// resources.add(JerseyResource.class);
// return resources;
// }
//
// @Override
// protected TestContainerFactory getTestContainerFactory() {
// return new GrizzlyTestContainerFactory();
// }
//
// @Override
// protected DeploymentContext configureDeployment(ResourceConfig config) {
// return DeploymentContext.builder(config).build();
// }
//
// @Override
// protected ResourceConfig configureResourceConfig(ResourceConfig config) {
// return super
// .configureResourceConfig(config)
// .register(new GrizzlyJaxRsContextFactoryProvider());
// }
//
// }
//
// Path: testing/src/main/java/org/pac4j/jax/rs/rules/SessionContainerRule.java
// public interface SessionContainerRule extends ContainerRule {
//
// @Override
// default Set<Class<?>> getResources() {
// Set<Class<?>> resources = ContainerRule.super.getResources();
// resources.add(TestSessionResource.class);
// return resources;
// }
// }
// Path: jersey225/src/test/java/org/pac4j/jax/rs/JerseyGrizzlyTest.java
import org.pac4j.jax.rs.rules.JerseyGrizzlyRule;
import org.pac4j.jax.rs.rules.SessionContainerRule;
package org.pac4j.jax.rs;
/**
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class JerseyGrizzlyTest extends AbstractSessionTest {
@Override | protected SessionContainerRule createContainer() { |
pac4j/jax-rs-pac4j | jersey225/src/test/java/org/pac4j/jax/rs/JerseyGrizzlyTest.java | // Path: jersey225/src/test/java/org/pac4j/jax/rs/rules/JerseyGrizzlyRule.java
// public class JerseyGrizzlyRule extends JerseyRule implements SessionContainerRule {
//
// @Override
// public Set<Class<?>> getResources() {
// Set<Class<?>> resources = SessionContainerRule.super.getResources();
// resources.add(JerseyResource.class);
// return resources;
// }
//
// @Override
// protected TestContainerFactory getTestContainerFactory() {
// return new GrizzlyTestContainerFactory();
// }
//
// @Override
// protected DeploymentContext configureDeployment(ResourceConfig config) {
// return DeploymentContext.builder(config).build();
// }
//
// @Override
// protected ResourceConfig configureResourceConfig(ResourceConfig config) {
// return super
// .configureResourceConfig(config)
// .register(new GrizzlyJaxRsContextFactoryProvider());
// }
//
// }
//
// Path: testing/src/main/java/org/pac4j/jax/rs/rules/SessionContainerRule.java
// public interface SessionContainerRule extends ContainerRule {
//
// @Override
// default Set<Class<?>> getResources() {
// Set<Class<?>> resources = ContainerRule.super.getResources();
// resources.add(TestSessionResource.class);
// return resources;
// }
// }
| import org.pac4j.jax.rs.rules.JerseyGrizzlyRule;
import org.pac4j.jax.rs.rules.SessionContainerRule; | package org.pac4j.jax.rs;
/**
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class JerseyGrizzlyTest extends AbstractSessionTest {
@Override
protected SessionContainerRule createContainer() { | // Path: jersey225/src/test/java/org/pac4j/jax/rs/rules/JerseyGrizzlyRule.java
// public class JerseyGrizzlyRule extends JerseyRule implements SessionContainerRule {
//
// @Override
// public Set<Class<?>> getResources() {
// Set<Class<?>> resources = SessionContainerRule.super.getResources();
// resources.add(JerseyResource.class);
// return resources;
// }
//
// @Override
// protected TestContainerFactory getTestContainerFactory() {
// return new GrizzlyTestContainerFactory();
// }
//
// @Override
// protected DeploymentContext configureDeployment(ResourceConfig config) {
// return DeploymentContext.builder(config).build();
// }
//
// @Override
// protected ResourceConfig configureResourceConfig(ResourceConfig config) {
// return super
// .configureResourceConfig(config)
// .register(new GrizzlyJaxRsContextFactoryProvider());
// }
//
// }
//
// Path: testing/src/main/java/org/pac4j/jax/rs/rules/SessionContainerRule.java
// public interface SessionContainerRule extends ContainerRule {
//
// @Override
// default Set<Class<?>> getResources() {
// Set<Class<?>> resources = ContainerRule.super.getResources();
// resources.add(TestSessionResource.class);
// return resources;
// }
// }
// Path: jersey225/src/test/java/org/pac4j/jax/rs/JerseyGrizzlyTest.java
import org.pac4j.jax.rs.rules.JerseyGrizzlyRule;
import org.pac4j.jax.rs.rules.SessionContainerRule;
package org.pac4j.jax.rs;
/**
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class JerseyGrizzlyTest extends AbstractSessionTest {
@Override
protected SessionContainerRule createContainer() { | return new JerseyGrizzlyRule(); |
pac4j/jax-rs-pac4j | jersey225/src/test/java/org/pac4j/jax/rs/JerseyGrizzlyServletTest.java | // Path: jersey225/src/test/java/org/pac4j/jax/rs/rules/JerseyGrizzlyServletRule.java
// public class JerseyGrizzlyServletRule extends JerseyRule implements SessionContainerRule {
//
// @Override
// public Set<Class<?>> getResources() {
// Set<Class<?>> resources = SessionContainerRule.super.getResources();
// resources.add(JerseyResource.class);
// return resources;
// }
//
// @Override
// protected TestContainerFactory getTestContainerFactory() {
// return new GrizzlyWebTestContainerFactory();
// }
//
// @Override
// protected DeploymentContext configureDeployment(ResourceConfig config) {
// return ServletDeploymentContext.forServlet(new ServletContainer(config)).build();
// }
//
// @Override
// protected ResourceConfig configureResourceConfig(ResourceConfig config) {
// return super
// .configureResourceConfig(config)
// .register(ServletJaxRsContextFactoryProvider.class);
// }
//
// }
//
// Path: testing/src/main/java/org/pac4j/jax/rs/rules/SessionContainerRule.java
// public interface SessionContainerRule extends ContainerRule {
//
// @Override
// default Set<Class<?>> getResources() {
// Set<Class<?>> resources = ContainerRule.super.getResources();
// resources.add(TestSessionResource.class);
// return resources;
// }
// }
| import org.pac4j.jax.rs.rules.JerseyGrizzlyServletRule;
import org.pac4j.jax.rs.rules.SessionContainerRule; | package org.pac4j.jax.rs;
/**
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class JerseyGrizzlyServletTest extends AbstractSessionTest {
@Override | // Path: jersey225/src/test/java/org/pac4j/jax/rs/rules/JerseyGrizzlyServletRule.java
// public class JerseyGrizzlyServletRule extends JerseyRule implements SessionContainerRule {
//
// @Override
// public Set<Class<?>> getResources() {
// Set<Class<?>> resources = SessionContainerRule.super.getResources();
// resources.add(JerseyResource.class);
// return resources;
// }
//
// @Override
// protected TestContainerFactory getTestContainerFactory() {
// return new GrizzlyWebTestContainerFactory();
// }
//
// @Override
// protected DeploymentContext configureDeployment(ResourceConfig config) {
// return ServletDeploymentContext.forServlet(new ServletContainer(config)).build();
// }
//
// @Override
// protected ResourceConfig configureResourceConfig(ResourceConfig config) {
// return super
// .configureResourceConfig(config)
// .register(ServletJaxRsContextFactoryProvider.class);
// }
//
// }
//
// Path: testing/src/main/java/org/pac4j/jax/rs/rules/SessionContainerRule.java
// public interface SessionContainerRule extends ContainerRule {
//
// @Override
// default Set<Class<?>> getResources() {
// Set<Class<?>> resources = ContainerRule.super.getResources();
// resources.add(TestSessionResource.class);
// return resources;
// }
// }
// Path: jersey225/src/test/java/org/pac4j/jax/rs/JerseyGrizzlyServletTest.java
import org.pac4j.jax.rs.rules.JerseyGrizzlyServletRule;
import org.pac4j.jax.rs.rules.SessionContainerRule;
package org.pac4j.jax.rs;
/**
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class JerseyGrizzlyServletTest extends AbstractSessionTest {
@Override | protected SessionContainerRule createContainer() { |
pac4j/jax-rs-pac4j | jersey225/src/test/java/org/pac4j/jax/rs/JerseyGrizzlyServletTest.java | // Path: jersey225/src/test/java/org/pac4j/jax/rs/rules/JerseyGrizzlyServletRule.java
// public class JerseyGrizzlyServletRule extends JerseyRule implements SessionContainerRule {
//
// @Override
// public Set<Class<?>> getResources() {
// Set<Class<?>> resources = SessionContainerRule.super.getResources();
// resources.add(JerseyResource.class);
// return resources;
// }
//
// @Override
// protected TestContainerFactory getTestContainerFactory() {
// return new GrizzlyWebTestContainerFactory();
// }
//
// @Override
// protected DeploymentContext configureDeployment(ResourceConfig config) {
// return ServletDeploymentContext.forServlet(new ServletContainer(config)).build();
// }
//
// @Override
// protected ResourceConfig configureResourceConfig(ResourceConfig config) {
// return super
// .configureResourceConfig(config)
// .register(ServletJaxRsContextFactoryProvider.class);
// }
//
// }
//
// Path: testing/src/main/java/org/pac4j/jax/rs/rules/SessionContainerRule.java
// public interface SessionContainerRule extends ContainerRule {
//
// @Override
// default Set<Class<?>> getResources() {
// Set<Class<?>> resources = ContainerRule.super.getResources();
// resources.add(TestSessionResource.class);
// return resources;
// }
// }
| import org.pac4j.jax.rs.rules.JerseyGrizzlyServletRule;
import org.pac4j.jax.rs.rules.SessionContainerRule; | package org.pac4j.jax.rs;
/**
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class JerseyGrizzlyServletTest extends AbstractSessionTest {
@Override
protected SessionContainerRule createContainer() { | // Path: jersey225/src/test/java/org/pac4j/jax/rs/rules/JerseyGrizzlyServletRule.java
// public class JerseyGrizzlyServletRule extends JerseyRule implements SessionContainerRule {
//
// @Override
// public Set<Class<?>> getResources() {
// Set<Class<?>> resources = SessionContainerRule.super.getResources();
// resources.add(JerseyResource.class);
// return resources;
// }
//
// @Override
// protected TestContainerFactory getTestContainerFactory() {
// return new GrizzlyWebTestContainerFactory();
// }
//
// @Override
// protected DeploymentContext configureDeployment(ResourceConfig config) {
// return ServletDeploymentContext.forServlet(new ServletContainer(config)).build();
// }
//
// @Override
// protected ResourceConfig configureResourceConfig(ResourceConfig config) {
// return super
// .configureResourceConfig(config)
// .register(ServletJaxRsContextFactoryProvider.class);
// }
//
// }
//
// Path: testing/src/main/java/org/pac4j/jax/rs/rules/SessionContainerRule.java
// public interface SessionContainerRule extends ContainerRule {
//
// @Override
// default Set<Class<?>> getResources() {
// Set<Class<?>> resources = ContainerRule.super.getResources();
// resources.add(TestSessionResource.class);
// return resources;
// }
// }
// Path: jersey225/src/test/java/org/pac4j/jax/rs/JerseyGrizzlyServletTest.java
import org.pac4j.jax.rs.rules.JerseyGrizzlyServletRule;
import org.pac4j.jax.rs.rules.SessionContainerRule;
package org.pac4j.jax.rs;
/**
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class JerseyGrizzlyServletTest extends AbstractSessionTest {
@Override
protected SessionContainerRule createContainer() { | return new JerseyGrizzlyServletRule(); |
pac4j/jax-rs-pac4j | resteasy/src/test/java/org/pac4j/jax/rs/RestEasyUndertowServletTest.java | // Path: resteasy/src/test/java/org/pac4j/jax/rs/rules/RestEasyUndertowServletRule.java
// public class RestEasyUndertowServletRule extends ExternalResource implements SessionContainerRule {
//
// private UndertowJaxrsServer server;
//
// private Client client;
//
// public class MyApp extends Application {
//
// @Override
// public Set<Class<?>> getClasses() {
// Set<Class<?>> classes = getResources();
// classes.add(ServletJaxRsContextFactoryProvider.class);
// classes.add(Pac4JProfileInjectorFactory.class);
// return classes;
// }
//
// @Override
// public Set<Object> getSingletons() {
// return Sets.newLinkedHashSet(
// new JaxRsConfigProvider(getConfig()),
// new Pac4JSecurityFeature());
// }
// }
//
// @Override
// public Set<Class<?>> getResources() {
// Set<Class<?>> resources = SessionContainerRule.super.getResources();
// resources.add(RestEasyResource.class);
// return resources;
// }
//
// @Override
// protected void before() throws Throwable {
// // Used by Jersey Client to store cookies
// CookieHandler.setDefault(new CookieManager());
//
// // we don't need a resteasy client, and the jersey one works better with redirect
// client = new JerseyClientBuilder().build();
//
// // TODO use an autogenerated port...
// System.setProperty("org.jboss.resteasy.port", "24257");
// server = new UndertowJaxrsServer().start();
//
// ResteasyDeployment deployment = new ResteasyDeployment();
// deployment.setInjectorFactoryClass(CdiInjectorFactory.class.getName());
// deployment.setApplication(new MyApp());
// DeploymentInfo di = server.undertowDeployment(deployment)
// .setContextPath("/")
// .setDeploymentName("DI")
// .setClassLoader(getClass().getClassLoader())
// .addListeners(Servlets.listener(Listener.class));
// server.deploy(di);
// }
//
// @Override
// protected void after() {
// server.stop();
// // server.stop is not instantaneous
// Awaitility.await().atMost(Duration.ofSeconds(5)).until(() -> {
// try {
// getTarget("/").request().get();
// } catch (ProcessingException e) {
// return true;
// }
// return false;
// });
// client.close();
// CookieHandler.setDefault(null);
// }
//
// @Override
// public WebTarget getTarget(String url) {
// return client.target(TestPortProvider.generateURL(url));
// }
//
// @Override
// public String cookieName() {
// return SessionCookieConfig.DEFAULT_SESSION_ID;
// }
// }
//
// Path: testing/src/main/java/org/pac4j/jax/rs/rules/SessionContainerRule.java
// public interface SessionContainerRule extends ContainerRule {
//
// @Override
// default Set<Class<?>> getResources() {
// Set<Class<?>> resources = ContainerRule.super.getResources();
// resources.add(TestSessionResource.class);
// return resources;
// }
// }
| import org.pac4j.jax.rs.rules.RestEasyUndertowServletRule;
import org.pac4j.jax.rs.rules.SessionContainerRule; | package org.pac4j.jax.rs;
/**
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class RestEasyUndertowServletTest extends AbstractSessionTest {
@Override | // Path: resteasy/src/test/java/org/pac4j/jax/rs/rules/RestEasyUndertowServletRule.java
// public class RestEasyUndertowServletRule extends ExternalResource implements SessionContainerRule {
//
// private UndertowJaxrsServer server;
//
// private Client client;
//
// public class MyApp extends Application {
//
// @Override
// public Set<Class<?>> getClasses() {
// Set<Class<?>> classes = getResources();
// classes.add(ServletJaxRsContextFactoryProvider.class);
// classes.add(Pac4JProfileInjectorFactory.class);
// return classes;
// }
//
// @Override
// public Set<Object> getSingletons() {
// return Sets.newLinkedHashSet(
// new JaxRsConfigProvider(getConfig()),
// new Pac4JSecurityFeature());
// }
// }
//
// @Override
// public Set<Class<?>> getResources() {
// Set<Class<?>> resources = SessionContainerRule.super.getResources();
// resources.add(RestEasyResource.class);
// return resources;
// }
//
// @Override
// protected void before() throws Throwable {
// // Used by Jersey Client to store cookies
// CookieHandler.setDefault(new CookieManager());
//
// // we don't need a resteasy client, and the jersey one works better with redirect
// client = new JerseyClientBuilder().build();
//
// // TODO use an autogenerated port...
// System.setProperty("org.jboss.resteasy.port", "24257");
// server = new UndertowJaxrsServer().start();
//
// ResteasyDeployment deployment = new ResteasyDeployment();
// deployment.setInjectorFactoryClass(CdiInjectorFactory.class.getName());
// deployment.setApplication(new MyApp());
// DeploymentInfo di = server.undertowDeployment(deployment)
// .setContextPath("/")
// .setDeploymentName("DI")
// .setClassLoader(getClass().getClassLoader())
// .addListeners(Servlets.listener(Listener.class));
// server.deploy(di);
// }
//
// @Override
// protected void after() {
// server.stop();
// // server.stop is not instantaneous
// Awaitility.await().atMost(Duration.ofSeconds(5)).until(() -> {
// try {
// getTarget("/").request().get();
// } catch (ProcessingException e) {
// return true;
// }
// return false;
// });
// client.close();
// CookieHandler.setDefault(null);
// }
//
// @Override
// public WebTarget getTarget(String url) {
// return client.target(TestPortProvider.generateURL(url));
// }
//
// @Override
// public String cookieName() {
// return SessionCookieConfig.DEFAULT_SESSION_ID;
// }
// }
//
// Path: testing/src/main/java/org/pac4j/jax/rs/rules/SessionContainerRule.java
// public interface SessionContainerRule extends ContainerRule {
//
// @Override
// default Set<Class<?>> getResources() {
// Set<Class<?>> resources = ContainerRule.super.getResources();
// resources.add(TestSessionResource.class);
// return resources;
// }
// }
// Path: resteasy/src/test/java/org/pac4j/jax/rs/RestEasyUndertowServletTest.java
import org.pac4j.jax.rs.rules.RestEasyUndertowServletRule;
import org.pac4j.jax.rs.rules.SessionContainerRule;
package org.pac4j.jax.rs;
/**
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class RestEasyUndertowServletTest extends AbstractSessionTest {
@Override | protected SessionContainerRule createContainer() { |
pac4j/jax-rs-pac4j | resteasy/src/test/java/org/pac4j/jax/rs/RestEasyUndertowServletTest.java | // Path: resteasy/src/test/java/org/pac4j/jax/rs/rules/RestEasyUndertowServletRule.java
// public class RestEasyUndertowServletRule extends ExternalResource implements SessionContainerRule {
//
// private UndertowJaxrsServer server;
//
// private Client client;
//
// public class MyApp extends Application {
//
// @Override
// public Set<Class<?>> getClasses() {
// Set<Class<?>> classes = getResources();
// classes.add(ServletJaxRsContextFactoryProvider.class);
// classes.add(Pac4JProfileInjectorFactory.class);
// return classes;
// }
//
// @Override
// public Set<Object> getSingletons() {
// return Sets.newLinkedHashSet(
// new JaxRsConfigProvider(getConfig()),
// new Pac4JSecurityFeature());
// }
// }
//
// @Override
// public Set<Class<?>> getResources() {
// Set<Class<?>> resources = SessionContainerRule.super.getResources();
// resources.add(RestEasyResource.class);
// return resources;
// }
//
// @Override
// protected void before() throws Throwable {
// // Used by Jersey Client to store cookies
// CookieHandler.setDefault(new CookieManager());
//
// // we don't need a resteasy client, and the jersey one works better with redirect
// client = new JerseyClientBuilder().build();
//
// // TODO use an autogenerated port...
// System.setProperty("org.jboss.resteasy.port", "24257");
// server = new UndertowJaxrsServer().start();
//
// ResteasyDeployment deployment = new ResteasyDeployment();
// deployment.setInjectorFactoryClass(CdiInjectorFactory.class.getName());
// deployment.setApplication(new MyApp());
// DeploymentInfo di = server.undertowDeployment(deployment)
// .setContextPath("/")
// .setDeploymentName("DI")
// .setClassLoader(getClass().getClassLoader())
// .addListeners(Servlets.listener(Listener.class));
// server.deploy(di);
// }
//
// @Override
// protected void after() {
// server.stop();
// // server.stop is not instantaneous
// Awaitility.await().atMost(Duration.ofSeconds(5)).until(() -> {
// try {
// getTarget("/").request().get();
// } catch (ProcessingException e) {
// return true;
// }
// return false;
// });
// client.close();
// CookieHandler.setDefault(null);
// }
//
// @Override
// public WebTarget getTarget(String url) {
// return client.target(TestPortProvider.generateURL(url));
// }
//
// @Override
// public String cookieName() {
// return SessionCookieConfig.DEFAULT_SESSION_ID;
// }
// }
//
// Path: testing/src/main/java/org/pac4j/jax/rs/rules/SessionContainerRule.java
// public interface SessionContainerRule extends ContainerRule {
//
// @Override
// default Set<Class<?>> getResources() {
// Set<Class<?>> resources = ContainerRule.super.getResources();
// resources.add(TestSessionResource.class);
// return resources;
// }
// }
| import org.pac4j.jax.rs.rules.RestEasyUndertowServletRule;
import org.pac4j.jax.rs.rules.SessionContainerRule; | package org.pac4j.jax.rs;
/**
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class RestEasyUndertowServletTest extends AbstractSessionTest {
@Override
protected SessionContainerRule createContainer() { | // Path: resteasy/src/test/java/org/pac4j/jax/rs/rules/RestEasyUndertowServletRule.java
// public class RestEasyUndertowServletRule extends ExternalResource implements SessionContainerRule {
//
// private UndertowJaxrsServer server;
//
// private Client client;
//
// public class MyApp extends Application {
//
// @Override
// public Set<Class<?>> getClasses() {
// Set<Class<?>> classes = getResources();
// classes.add(ServletJaxRsContextFactoryProvider.class);
// classes.add(Pac4JProfileInjectorFactory.class);
// return classes;
// }
//
// @Override
// public Set<Object> getSingletons() {
// return Sets.newLinkedHashSet(
// new JaxRsConfigProvider(getConfig()),
// new Pac4JSecurityFeature());
// }
// }
//
// @Override
// public Set<Class<?>> getResources() {
// Set<Class<?>> resources = SessionContainerRule.super.getResources();
// resources.add(RestEasyResource.class);
// return resources;
// }
//
// @Override
// protected void before() throws Throwable {
// // Used by Jersey Client to store cookies
// CookieHandler.setDefault(new CookieManager());
//
// // we don't need a resteasy client, and the jersey one works better with redirect
// client = new JerseyClientBuilder().build();
//
// // TODO use an autogenerated port...
// System.setProperty("org.jboss.resteasy.port", "24257");
// server = new UndertowJaxrsServer().start();
//
// ResteasyDeployment deployment = new ResteasyDeployment();
// deployment.setInjectorFactoryClass(CdiInjectorFactory.class.getName());
// deployment.setApplication(new MyApp());
// DeploymentInfo di = server.undertowDeployment(deployment)
// .setContextPath("/")
// .setDeploymentName("DI")
// .setClassLoader(getClass().getClassLoader())
// .addListeners(Servlets.listener(Listener.class));
// server.deploy(di);
// }
//
// @Override
// protected void after() {
// server.stop();
// // server.stop is not instantaneous
// Awaitility.await().atMost(Duration.ofSeconds(5)).until(() -> {
// try {
// getTarget("/").request().get();
// } catch (ProcessingException e) {
// return true;
// }
// return false;
// });
// client.close();
// CookieHandler.setDefault(null);
// }
//
// @Override
// public WebTarget getTarget(String url) {
// return client.target(TestPortProvider.generateURL(url));
// }
//
// @Override
// public String cookieName() {
// return SessionCookieConfig.DEFAULT_SESSION_ID;
// }
// }
//
// Path: testing/src/main/java/org/pac4j/jax/rs/rules/SessionContainerRule.java
// public interface SessionContainerRule extends ContainerRule {
//
// @Override
// default Set<Class<?>> getResources() {
// Set<Class<?>> resources = ContainerRule.super.getResources();
// resources.add(TestSessionResource.class);
// return resources;
// }
// }
// Path: resteasy/src/test/java/org/pac4j/jax/rs/RestEasyUndertowServletTest.java
import org.pac4j.jax.rs.rules.RestEasyUndertowServletRule;
import org.pac4j.jax.rs.rules.SessionContainerRule;
package org.pac4j.jax.rs;
/**
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class RestEasyUndertowServletTest extends AbstractSessionTest {
@Override
protected SessionContainerRule createContainer() { | return new RestEasyUndertowServletRule(); |
pac4j/jax-rs-pac4j | jersey228/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
| import org.glassfish.jersey.internal.inject.AbstractBinder;
import org.glassfish.jersey.internal.inject.InjectionResolver;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.ContainerRequest;
import org.glassfish.jersey.server.internal.inject.AbstractValueParamProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueParamProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.ext.Providers;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier; | if(manager == null){
bind(DefaultProfileManagerFactoryBuilder.class)
.to(ProfileManagerFactoryBuilder.class)
;
} else {
bind(manager).to(ProfileManagerFactoryBuilder.class);
}
bind(Pac4JProfileValueFactoryProvider.class).to(ValueParamProvider.class).in(Singleton.class);
bind(ProfileInjectionResolver.class)
.to(new GenericType<InjectionResolver<Pac4JProfile>>(){})
.in(Singleton.class);
bind(ProfileManagerInjectionResolver.class)
.to(new GenericType<InjectionResolver<Pac4JProfileManager>>(){})
.in(Singleton.class);
}
}
static class ProfileManagerValueFactory implements ProfileManagerFactory{
@Context
private final Providers providers;
ProfileManagerValueFactory(Providers providers) {
this.providers = providers;
}
@Override
public ProfileManager<CommonProfile> apply(ContainerRequest containerRequest) { | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
// Path: jersey228/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java
import org.glassfish.jersey.internal.inject.AbstractBinder;
import org.glassfish.jersey.internal.inject.InjectionResolver;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.ContainerRequest;
import org.glassfish.jersey.server.internal.inject.AbstractValueParamProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueParamProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.ext.Providers;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
if(manager == null){
bind(DefaultProfileManagerFactoryBuilder.class)
.to(ProfileManagerFactoryBuilder.class)
;
} else {
bind(manager).to(ProfileManagerFactoryBuilder.class);
}
bind(Pac4JProfileValueFactoryProvider.class).to(ValueParamProvider.class).in(Singleton.class);
bind(ProfileInjectionResolver.class)
.to(new GenericType<InjectionResolver<Pac4JProfile>>(){})
.in(Singleton.class);
bind(ProfileManagerInjectionResolver.class)
.to(new GenericType<InjectionResolver<Pac4JProfileManager>>(){})
.in(Singleton.class);
}
}
static class ProfileManagerValueFactory implements ProfileManagerFactory{
@Context
private final Providers providers;
ProfileManagerValueFactory(Providers providers) {
this.providers = providers;
}
@Override
public ProfileManager<CommonProfile> apply(ContainerRequest containerRequest) { | return new RequestProfileManager(new RequestJaxRsContext(providers, containerRequest)) |
pac4j/jax-rs-pac4j | jersey228/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
| import org.glassfish.jersey.internal.inject.AbstractBinder;
import org.glassfish.jersey.internal.inject.InjectionResolver;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.ContainerRequest;
import org.glassfish.jersey.server.internal.inject.AbstractValueParamProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueParamProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.ext.Providers;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier; | if(manager == null){
bind(DefaultProfileManagerFactoryBuilder.class)
.to(ProfileManagerFactoryBuilder.class)
;
} else {
bind(manager).to(ProfileManagerFactoryBuilder.class);
}
bind(Pac4JProfileValueFactoryProvider.class).to(ValueParamProvider.class).in(Singleton.class);
bind(ProfileInjectionResolver.class)
.to(new GenericType<InjectionResolver<Pac4JProfile>>(){})
.in(Singleton.class);
bind(ProfileManagerInjectionResolver.class)
.to(new GenericType<InjectionResolver<Pac4JProfileManager>>(){})
.in(Singleton.class);
}
}
static class ProfileManagerValueFactory implements ProfileManagerFactory{
@Context
private final Providers providers;
ProfileManagerValueFactory(Providers providers) {
this.providers = providers;
}
@Override
public ProfileManager<CommonProfile> apply(ContainerRequest containerRequest) { | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
// Path: jersey228/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java
import org.glassfish.jersey.internal.inject.AbstractBinder;
import org.glassfish.jersey.internal.inject.InjectionResolver;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.ContainerRequest;
import org.glassfish.jersey.server.internal.inject.AbstractValueParamProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueParamProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.ext.Providers;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
if(manager == null){
bind(DefaultProfileManagerFactoryBuilder.class)
.to(ProfileManagerFactoryBuilder.class)
;
} else {
bind(manager).to(ProfileManagerFactoryBuilder.class);
}
bind(Pac4JProfileValueFactoryProvider.class).to(ValueParamProvider.class).in(Singleton.class);
bind(ProfileInjectionResolver.class)
.to(new GenericType<InjectionResolver<Pac4JProfile>>(){})
.in(Singleton.class);
bind(ProfileManagerInjectionResolver.class)
.to(new GenericType<InjectionResolver<Pac4JProfileManager>>(){})
.in(Singleton.class);
}
}
static class ProfileManagerValueFactory implements ProfileManagerFactory{
@Context
private final Providers providers;
ProfileManagerValueFactory(Providers providers) {
this.providers = providers;
}
@Override
public ProfileManager<CommonProfile> apply(ContainerRequest containerRequest) { | return new RequestProfileManager(new RequestJaxRsContext(providers, containerRequest)) |
pac4j/jax-rs-pac4j | jersey228/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
| import org.glassfish.jersey.internal.inject.AbstractBinder;
import org.glassfish.jersey.internal.inject.InjectionResolver;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.ContainerRequest;
import org.glassfish.jersey.server.internal.inject.AbstractValueParamProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueParamProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.ext.Providers;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier; | ProfileManagerValueFactory(Providers providers) {
this.providers = providers;
}
@Override
public ProfileManager<CommonProfile> apply(ContainerRequest containerRequest) {
return new RequestProfileManager(new RequestJaxRsContext(providers, containerRequest))
.profileManager();
}
}
static class ProfileValueFactory implements ProfileFactory {
@Override
public UserProfile apply(ContainerRequest containerRequest) {
return optionalProfile(containerRequest)
.orElseThrow(() -> {
LOG.debug("Cannot inject a Pac4j profile into an unauthenticated request, responding with 401");
return new WebApplicationException(401);
});
}
}
static class OptionalProfileValueFactory implements OptionalProfileFactory {
@Override
public Optional<UserProfile> apply(ContainerRequest containerRequest) {
return optionalProfile(containerRequest);
}
}
private static Optional<UserProfile> optionalProfile(ContainerRequest containerRequest) { | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
// Path: jersey228/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java
import org.glassfish.jersey.internal.inject.AbstractBinder;
import org.glassfish.jersey.internal.inject.InjectionResolver;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.ContainerRequest;
import org.glassfish.jersey.server.internal.inject.AbstractValueParamProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueParamProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.ext.Providers;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
ProfileManagerValueFactory(Providers providers) {
this.providers = providers;
}
@Override
public ProfileManager<CommonProfile> apply(ContainerRequest containerRequest) {
return new RequestProfileManager(new RequestJaxRsContext(providers, containerRequest))
.profileManager();
}
}
static class ProfileValueFactory implements ProfileFactory {
@Override
public UserProfile apply(ContainerRequest containerRequest) {
return optionalProfile(containerRequest)
.orElseThrow(() -> {
LOG.debug("Cannot inject a Pac4j profile into an unauthenticated request, responding with 401");
return new WebApplicationException(401);
});
}
}
static class OptionalProfileValueFactory implements OptionalProfileFactory {
@Override
public Optional<UserProfile> apply(ContainerRequest containerRequest) {
return optionalProfile(containerRequest);
}
}
private static Optional<UserProfile> optionalProfile(ContainerRequest containerRequest) { | RequestPac4JSecurityContext securityContext = new RequestPac4JSecurityContext(containerRequest); |
pac4j/jax-rs-pac4j | jersey228/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
| import org.glassfish.jersey.internal.inject.AbstractBinder;
import org.glassfish.jersey.internal.inject.InjectionResolver;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.ContainerRequest;
import org.glassfish.jersey.server.internal.inject.AbstractValueParamProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueParamProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.ext.Providers;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier; | this.providers = providers;
}
@Override
public ProfileManager<CommonProfile> apply(ContainerRequest containerRequest) {
return new RequestProfileManager(new RequestJaxRsContext(providers, containerRequest))
.profileManager();
}
}
static class ProfileValueFactory implements ProfileFactory {
@Override
public UserProfile apply(ContainerRequest containerRequest) {
return optionalProfile(containerRequest)
.orElseThrow(() -> {
LOG.debug("Cannot inject a Pac4j profile into an unauthenticated request, responding with 401");
return new WebApplicationException(401);
});
}
}
static class OptionalProfileValueFactory implements OptionalProfileFactory {
@Override
public Optional<UserProfile> apply(ContainerRequest containerRequest) {
return optionalProfile(containerRequest);
}
}
private static Optional<UserProfile> optionalProfile(ContainerRequest containerRequest) {
RequestPac4JSecurityContext securityContext = new RequestPac4JSecurityContext(containerRequest); | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
// public class RequestUserProfile {
//
// private final RequestPac4JSecurityContext context;
//
// public RequestUserProfile(RequestPac4JSecurityContext context) {
// this.context = context;
// }
//
// public Optional<UserProfile> profile() {
// return context.context()
// .flatMap(Pac4JSecurityContext::getProfiles)
// .flatMap(ps -> ProfileHelper.flatIntoOneProfile(ps));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestJaxRsContext.java
// public class RequestJaxRsContext {
//
// private final ProvidersContext providers;
// private final ContainerRequestContext context;
//
// public RequestJaxRsContext(Providers providers, ContainerRequestContext context) {
// this.providers = new ProvidersContext(providers);
// this.context = context;
// }
//
// public Optional<JaxRsContext> context() {
// return new RequestPac4JSecurityContext(context).context().map(Pac4JSecurityContext::getContext);
// }
//
// public JaxRsContext contextOrNew() {
// return context().orElse(providers.resolveNotNull(JaxRsContextFactory.class).provides(context));
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
// public class RequestProfileManager {
//
// private final RequestJaxRsContext context;
//
// public RequestProfileManager(RequestJaxRsContext context) {
// this.context = context;
// }
//
// public JaxRsProfileManager profileManager() {
// return new JaxRsProfileManager(context.contextOrNew());
// }
// }
// Path: jersey228/src/main/java/org/pac4j/jax/rs/jersey/features/Pac4JValueFactoryProvider.java
import org.glassfish.jersey.internal.inject.AbstractBinder;
import org.glassfish.jersey.internal.inject.InjectionResolver;
import org.glassfish.jersey.internal.util.ReflectionHelper;
import org.glassfish.jersey.internal.util.collection.ClassTypePair;
import org.glassfish.jersey.server.ContainerRequest;
import org.glassfish.jersey.server.internal.inject.AbstractValueParamProvider;
import org.glassfish.jersey.server.internal.inject.MultivaluedParameterExtractorProvider;
import org.glassfish.jersey.server.internal.inject.ParamInjectionResolver;
import org.glassfish.jersey.server.model.Parameter;
import org.glassfish.jersey.server.spi.internal.ValueParamProvider;
import org.pac4j.core.profile.CommonProfile;
import org.pac4j.core.profile.ProfileManager;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfile;
import org.pac4j.jax.rs.annotations.Pac4JProfileManager;
import org.pac4j.jax.rs.helpers.RequestUserProfile;
import org.pac4j.jax.rs.helpers.RequestJaxRsContext;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
import org.pac4j.jax.rs.helpers.RequestProfileManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.ext.Providers;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.function.Supplier;
this.providers = providers;
}
@Override
public ProfileManager<CommonProfile> apply(ContainerRequest containerRequest) {
return new RequestProfileManager(new RequestJaxRsContext(providers, containerRequest))
.profileManager();
}
}
static class ProfileValueFactory implements ProfileFactory {
@Override
public UserProfile apply(ContainerRequest containerRequest) {
return optionalProfile(containerRequest)
.orElseThrow(() -> {
LOG.debug("Cannot inject a Pac4j profile into an unauthenticated request, responding with 401");
return new WebApplicationException(401);
});
}
}
static class OptionalProfileValueFactory implements OptionalProfileFactory {
@Override
public Optional<UserProfile> apply(ContainerRequest containerRequest) {
return optionalProfile(containerRequest);
}
}
private static Optional<UserProfile> optionalProfile(ContainerRequest containerRequest) {
RequestPac4JSecurityContext securityContext = new RequestPac4JSecurityContext(containerRequest); | return new RequestUserProfile(securityContext).profile(); |
pac4j/jax-rs-pac4j | jersey225/src/test/java/org/pac4j/jax/rs/JerseyInMemoryTest.java | // Path: testing/src/main/java/org/pac4j/jax/rs/rules/ContainerRule.java
// public interface ContainerRule extends TestRule, TestConfig {
//
// WebTarget getTarget(String url);
//
// String cookieName();
//
// default Set<Class<?>> getResources() {
// return Sets.newLinkedHashSet(TestResource.class, TestClassLevelResource.class, TestProxyResource.class);
// }
// }
//
// Path: jersey225/src/test/java/org/pac4j/jax/rs/rules/JerseyInMemoryRule.java
// public class JerseyInMemoryRule extends JerseyRule {
//
// @Override
// public Set<Class<?>> getResources() {
// Set<Class<?>> resources = super.getResources();
// resources.add(JerseyResource.class);
// return resources;
// }
//
// @Override
// protected TestContainerFactory getTestContainerFactory() {
// return new InMemoryTestContainerFactory();
// }
//
// @Override
// protected DeploymentContext configureDeployment(ResourceConfig config) {
// return DeploymentContext.builder(config).build();
// }
//
// protected ResourceConfig configureResourceConfig(ResourceConfig config) {
// final Config pac4jConfig = getConfig();
// // we create a fake session to make tests pass. Otherwise we would need: matchers="none"
// // or pac4j should be able to handle no session store.
// pac4jConfig.setSessionStore(Mockito.mock(SessionStore.class));
// return config
// .register(new JaxRsConfigProvider(pac4jConfig))
// .register(new Pac4JSecurityFeature())
// .register(new Pac4JValueFactoryProvider.Binder())
// .register(JaxRsContextFactoryProvider.class);
// }
// }
| import org.pac4j.jax.rs.rules.ContainerRule;
import org.pac4j.jax.rs.rules.JerseyInMemoryRule; | package org.pac4j.jax.rs;
/**
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class JerseyInMemoryTest extends AbstractTest {
@Override | // Path: testing/src/main/java/org/pac4j/jax/rs/rules/ContainerRule.java
// public interface ContainerRule extends TestRule, TestConfig {
//
// WebTarget getTarget(String url);
//
// String cookieName();
//
// default Set<Class<?>> getResources() {
// return Sets.newLinkedHashSet(TestResource.class, TestClassLevelResource.class, TestProxyResource.class);
// }
// }
//
// Path: jersey225/src/test/java/org/pac4j/jax/rs/rules/JerseyInMemoryRule.java
// public class JerseyInMemoryRule extends JerseyRule {
//
// @Override
// public Set<Class<?>> getResources() {
// Set<Class<?>> resources = super.getResources();
// resources.add(JerseyResource.class);
// return resources;
// }
//
// @Override
// protected TestContainerFactory getTestContainerFactory() {
// return new InMemoryTestContainerFactory();
// }
//
// @Override
// protected DeploymentContext configureDeployment(ResourceConfig config) {
// return DeploymentContext.builder(config).build();
// }
//
// protected ResourceConfig configureResourceConfig(ResourceConfig config) {
// final Config pac4jConfig = getConfig();
// // we create a fake session to make tests pass. Otherwise we would need: matchers="none"
// // or pac4j should be able to handle no session store.
// pac4jConfig.setSessionStore(Mockito.mock(SessionStore.class));
// return config
// .register(new JaxRsConfigProvider(pac4jConfig))
// .register(new Pac4JSecurityFeature())
// .register(new Pac4JValueFactoryProvider.Binder())
// .register(JaxRsContextFactoryProvider.class);
// }
// }
// Path: jersey225/src/test/java/org/pac4j/jax/rs/JerseyInMemoryTest.java
import org.pac4j.jax.rs.rules.ContainerRule;
import org.pac4j.jax.rs.rules.JerseyInMemoryRule;
package org.pac4j.jax.rs;
/**
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class JerseyInMemoryTest extends AbstractTest {
@Override | protected ContainerRule createContainer() { |
pac4j/jax-rs-pac4j | jersey225/src/test/java/org/pac4j/jax/rs/JerseyInMemoryTest.java | // Path: testing/src/main/java/org/pac4j/jax/rs/rules/ContainerRule.java
// public interface ContainerRule extends TestRule, TestConfig {
//
// WebTarget getTarget(String url);
//
// String cookieName();
//
// default Set<Class<?>> getResources() {
// return Sets.newLinkedHashSet(TestResource.class, TestClassLevelResource.class, TestProxyResource.class);
// }
// }
//
// Path: jersey225/src/test/java/org/pac4j/jax/rs/rules/JerseyInMemoryRule.java
// public class JerseyInMemoryRule extends JerseyRule {
//
// @Override
// public Set<Class<?>> getResources() {
// Set<Class<?>> resources = super.getResources();
// resources.add(JerseyResource.class);
// return resources;
// }
//
// @Override
// protected TestContainerFactory getTestContainerFactory() {
// return new InMemoryTestContainerFactory();
// }
//
// @Override
// protected DeploymentContext configureDeployment(ResourceConfig config) {
// return DeploymentContext.builder(config).build();
// }
//
// protected ResourceConfig configureResourceConfig(ResourceConfig config) {
// final Config pac4jConfig = getConfig();
// // we create a fake session to make tests pass. Otherwise we would need: matchers="none"
// // or pac4j should be able to handle no session store.
// pac4jConfig.setSessionStore(Mockito.mock(SessionStore.class));
// return config
// .register(new JaxRsConfigProvider(pac4jConfig))
// .register(new Pac4JSecurityFeature())
// .register(new Pac4JValueFactoryProvider.Binder())
// .register(JaxRsContextFactoryProvider.class);
// }
// }
| import org.pac4j.jax.rs.rules.ContainerRule;
import org.pac4j.jax.rs.rules.JerseyInMemoryRule; | package org.pac4j.jax.rs;
/**
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class JerseyInMemoryTest extends AbstractTest {
@Override
protected ContainerRule createContainer() { | // Path: testing/src/main/java/org/pac4j/jax/rs/rules/ContainerRule.java
// public interface ContainerRule extends TestRule, TestConfig {
//
// WebTarget getTarget(String url);
//
// String cookieName();
//
// default Set<Class<?>> getResources() {
// return Sets.newLinkedHashSet(TestResource.class, TestClassLevelResource.class, TestProxyResource.class);
// }
// }
//
// Path: jersey225/src/test/java/org/pac4j/jax/rs/rules/JerseyInMemoryRule.java
// public class JerseyInMemoryRule extends JerseyRule {
//
// @Override
// public Set<Class<?>> getResources() {
// Set<Class<?>> resources = super.getResources();
// resources.add(JerseyResource.class);
// return resources;
// }
//
// @Override
// protected TestContainerFactory getTestContainerFactory() {
// return new InMemoryTestContainerFactory();
// }
//
// @Override
// protected DeploymentContext configureDeployment(ResourceConfig config) {
// return DeploymentContext.builder(config).build();
// }
//
// protected ResourceConfig configureResourceConfig(ResourceConfig config) {
// final Config pac4jConfig = getConfig();
// // we create a fake session to make tests pass. Otherwise we would need: matchers="none"
// // or pac4j should be able to handle no session store.
// pac4jConfig.setSessionStore(Mockito.mock(SessionStore.class));
// return config
// .register(new JaxRsConfigProvider(pac4jConfig))
// .register(new Pac4JSecurityFeature())
// .register(new Pac4JValueFactoryProvider.Binder())
// .register(JaxRsContextFactoryProvider.class);
// }
// }
// Path: jersey225/src/test/java/org/pac4j/jax/rs/JerseyInMemoryTest.java
import org.pac4j.jax.rs.rules.ContainerRule;
import org.pac4j.jax.rs.rules.JerseyInMemoryRule;
package org.pac4j.jax.rs;
/**
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class JerseyInMemoryTest extends AbstractTest {
@Override
protected ContainerRule createContainer() { | return new JerseyInMemoryRule(); |
pac4j/jax-rs-pac4j | core/src/main/java/org/pac4j/jax/rs/servlet/features/ServletJaxRsContextFactoryProvider.java | // Path: core/src/main/java/org/pac4j/jax/rs/features/JaxRsContextFactoryProvider.java
// public class JaxRsContextFactoryProvider implements ContextResolver<JaxRsContextFactory> {
//
// @Context
// private Providers providers;
//
// @Override
// public JaxRsContextFactory getContext(Class<?> type) {
// return context -> new JaxRsContext(getProviders(), context, getConfig().getSessionStore());
// }
//
// protected Providers getProviders() {
// assert providers != null;
// return providers;
// }
//
// protected Config getConfig() {
// return new ProvidersContext(providers).resolveNotNull(Config.class);
// }
//
// /**
// * We need to provide a factory because it is not possible to get the {@link ContainerRequestContext} injected
// * directly here...
// */
// @FunctionalInterface
// public interface JaxRsContextFactory {
// JaxRsContext provides(ContainerRequestContext context);
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/servlet/pac4j/ServletJaxRsContext.java
// public class ServletJaxRsContext extends JaxRsContext {
//
// private final HttpServletRequest request;
//
// public ServletJaxRsContext(Providers providers, ContainerRequestContext requestContext,
// SessionStore sessionStore, HttpServletRequest request) {
// super(providers, requestContext, sessionStore != null ? sessionStore : new ServletSessionStore());
// CommonHelper.assertNotNull("request", request);
// this.request = request;
// }
//
// public HttpServletRequest getRequest() {
// return request;
// }
//
// @Override
// public String getRemoteAddr() {
// return request.getRemoteAddr();
// }
// }
| import javax.inject.Inject;
import javax.inject.Provider;
import javax.servlet.http.HttpServletRequest;
import org.pac4j.jax.rs.features.JaxRsContextFactoryProvider;
import org.pac4j.jax.rs.servlet.pac4j.ServletJaxRsContext; | package org.pac4j.jax.rs.servlet.features;
/**
* Extends {@link JaxRsContextFactoryProvider} to support any servlet-based container and its session manager (i.e.,
* pac4j indirect clients will work, contrary than with {@link JaxRsContextFactoryProvider}).
*
* @see JaxRsContextFactoryProvider
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class ServletJaxRsContextFactoryProvider extends JaxRsContextFactoryProvider {
@Inject
private Provider<HttpServletRequest> requestProvider;
@Override
public JaxRsContextFactory getContext(Class<?> type) { | // Path: core/src/main/java/org/pac4j/jax/rs/features/JaxRsContextFactoryProvider.java
// public class JaxRsContextFactoryProvider implements ContextResolver<JaxRsContextFactory> {
//
// @Context
// private Providers providers;
//
// @Override
// public JaxRsContextFactory getContext(Class<?> type) {
// return context -> new JaxRsContext(getProviders(), context, getConfig().getSessionStore());
// }
//
// protected Providers getProviders() {
// assert providers != null;
// return providers;
// }
//
// protected Config getConfig() {
// return new ProvidersContext(providers).resolveNotNull(Config.class);
// }
//
// /**
// * We need to provide a factory because it is not possible to get the {@link ContainerRequestContext} injected
// * directly here...
// */
// @FunctionalInterface
// public interface JaxRsContextFactory {
// JaxRsContext provides(ContainerRequestContext context);
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/servlet/pac4j/ServletJaxRsContext.java
// public class ServletJaxRsContext extends JaxRsContext {
//
// private final HttpServletRequest request;
//
// public ServletJaxRsContext(Providers providers, ContainerRequestContext requestContext,
// SessionStore sessionStore, HttpServletRequest request) {
// super(providers, requestContext, sessionStore != null ? sessionStore : new ServletSessionStore());
// CommonHelper.assertNotNull("request", request);
// this.request = request;
// }
//
// public HttpServletRequest getRequest() {
// return request;
// }
//
// @Override
// public String getRemoteAddr() {
// return request.getRemoteAddr();
// }
// }
// Path: core/src/main/java/org/pac4j/jax/rs/servlet/features/ServletJaxRsContextFactoryProvider.java
import javax.inject.Inject;
import javax.inject.Provider;
import javax.servlet.http.HttpServletRequest;
import org.pac4j.jax.rs.features.JaxRsContextFactoryProvider;
import org.pac4j.jax.rs.servlet.pac4j.ServletJaxRsContext;
package org.pac4j.jax.rs.servlet.features;
/**
* Extends {@link JaxRsContextFactoryProvider} to support any servlet-based container and its session manager (i.e.,
* pac4j indirect clients will work, contrary than with {@link JaxRsContextFactoryProvider}).
*
* @see JaxRsContextFactoryProvider
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class ServletJaxRsContextFactoryProvider extends JaxRsContextFactoryProvider {
@Inject
private Provider<HttpServletRequest> requestProvider;
@Override
public JaxRsContextFactory getContext(Class<?> type) { | return context -> new ServletJaxRsContext(getProviders(), context, getConfig().getSessionStore(), requestProvider.get()); |
pac4j/jax-rs-pac4j | testing/src/main/java/org/pac4j/jax/rs/rules/SessionContainerRule.java | // Path: testing/src/main/java/org/pac4j/jax/rs/resources/TestSessionResource.java
// @Path("/session")
// public class TestSessionResource extends TestResource {
//
// @GET
// @Path("/logged")
// @Pac4JSecurity(clients = "FormClient", authorizers = DefaultAuthorizers.IS_AUTHENTICATED)
// public String logged() {
// return "ok";
// }
//
// @GET
// @Path("/inject")
// @Pac4JSecurity(clients = "FormClient", authorizers = DefaultAuthorizers.IS_AUTHENTICATED)
// public String inject(@Pac4JProfile CommonProfile profile) {
// if (profile != null) {
// return "ok";
// } else {
// return "error";
// }
// }
//
// @POST
// @Path("/login")
// // TODO apparently we need to disable session renewal because grizzly
// // send 2 JSESSIONID if not...
// @Pac4JCallback(defaultUrl = "/session/logged", renewSession = false)
// public void login() {
// // nothing
// }
// }
| import java.util.Set;
import org.pac4j.jax.rs.resources.TestSessionResource; | package org.pac4j.jax.rs.rules;
public interface SessionContainerRule extends ContainerRule {
@Override
default Set<Class<?>> getResources() {
Set<Class<?>> resources = ContainerRule.super.getResources(); | // Path: testing/src/main/java/org/pac4j/jax/rs/resources/TestSessionResource.java
// @Path("/session")
// public class TestSessionResource extends TestResource {
//
// @GET
// @Path("/logged")
// @Pac4JSecurity(clients = "FormClient", authorizers = DefaultAuthorizers.IS_AUTHENTICATED)
// public String logged() {
// return "ok";
// }
//
// @GET
// @Path("/inject")
// @Pac4JSecurity(clients = "FormClient", authorizers = DefaultAuthorizers.IS_AUTHENTICATED)
// public String inject(@Pac4JProfile CommonProfile profile) {
// if (profile != null) {
// return "ok";
// } else {
// return "error";
// }
// }
//
// @POST
// @Path("/login")
// // TODO apparently we need to disable session renewal because grizzly
// // send 2 JSESSIONID if not...
// @Pac4JCallback(defaultUrl = "/session/logged", renewSession = false)
// public void login() {
// // nothing
// }
// }
// Path: testing/src/main/java/org/pac4j/jax/rs/rules/SessionContainerRule.java
import java.util.Set;
import org.pac4j.jax.rs.resources.TestSessionResource;
package org.pac4j.jax.rs.rules;
public interface SessionContainerRule extends ContainerRule {
@Override
default Set<Class<?>> getResources() {
Set<Class<?>> resources = ContainerRule.super.getResources(); | resources.add(TestSessionResource.class); |
pac4j/jax-rs-pac4j | testing/src/main/java/org/pac4j/jax/rs/TestConfig.java | // Path: core/src/main/java/org/pac4j/jax/rs/pac4j/JaxRsAjaxRequestResolver.java
// public class JaxRsAjaxRequestResolver extends DefaultAjaxRequestResolver {
// @Override
// public boolean isAjax(WebContext context) {
// return true;
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/pac4j/JaxRsUrlResolver.java
// public class JaxRsUrlResolver implements UrlResolver {
//
// @Override
// public String compute(String url, WebContext context) {
// if (context instanceof JaxRsContext && url != null) {
// return ((JaxRsContext) context).getAbsolutePath(url, true);
// }
// return url;
// }
//
// }
| import org.pac4j.core.client.Clients;
import org.pac4j.core.config.Config;
import org.pac4j.core.credentials.UsernamePasswordCredentials;
import org.pac4j.core.credentials.authenticator.Authenticator;
import org.pac4j.http.client.direct.DirectFormClient;
import org.pac4j.http.client.indirect.FormClient;
import org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator;
import org.pac4j.jax.rs.pac4j.JaxRsAjaxRequestResolver;
import org.pac4j.jax.rs.pac4j.JaxRsUrlResolver; | package org.pac4j.jax.rs;
public interface TestConfig {
String DEFAULT_CLIENT = "default-form";
default Config getConfig() {
// login not used because the ajax resolver always answer true
Authenticator<UsernamePasswordCredentials> auth = new SimpleTestUsernamePasswordAuthenticator();
FormClient client = new FormClient("notUsedLoginUrl", auth);
DirectFormClient client2 = new DirectFormClient(auth);
DirectFormClient client3 = new DirectFormClient(auth);
client3.setName(DEFAULT_CLIENT);
Clients clients = new Clients("notUsedCallbackUrl", client, client2, client3);
// in case of invalid credentials, we simply want the error, not a redirect to the login url | // Path: core/src/main/java/org/pac4j/jax/rs/pac4j/JaxRsAjaxRequestResolver.java
// public class JaxRsAjaxRequestResolver extends DefaultAjaxRequestResolver {
// @Override
// public boolean isAjax(WebContext context) {
// return true;
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/pac4j/JaxRsUrlResolver.java
// public class JaxRsUrlResolver implements UrlResolver {
//
// @Override
// public String compute(String url, WebContext context) {
// if (context instanceof JaxRsContext && url != null) {
// return ((JaxRsContext) context).getAbsolutePath(url, true);
// }
// return url;
// }
//
// }
// Path: testing/src/main/java/org/pac4j/jax/rs/TestConfig.java
import org.pac4j.core.client.Clients;
import org.pac4j.core.config.Config;
import org.pac4j.core.credentials.UsernamePasswordCredentials;
import org.pac4j.core.credentials.authenticator.Authenticator;
import org.pac4j.http.client.direct.DirectFormClient;
import org.pac4j.http.client.indirect.FormClient;
import org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator;
import org.pac4j.jax.rs.pac4j.JaxRsAjaxRequestResolver;
import org.pac4j.jax.rs.pac4j.JaxRsUrlResolver;
package org.pac4j.jax.rs;
public interface TestConfig {
String DEFAULT_CLIENT = "default-form";
default Config getConfig() {
// login not used because the ajax resolver always answer true
Authenticator<UsernamePasswordCredentials> auth = new SimpleTestUsernamePasswordAuthenticator();
FormClient client = new FormClient("notUsedLoginUrl", auth);
DirectFormClient client2 = new DirectFormClient(auth);
DirectFormClient client3 = new DirectFormClient(auth);
client3.setName(DEFAULT_CLIENT);
Clients clients = new Clients("notUsedCallbackUrl", client, client2, client3);
// in case of invalid credentials, we simply want the error, not a redirect to the login url | clients.setAjaxRequestResolver(new JaxRsAjaxRequestResolver()); |
pac4j/jax-rs-pac4j | testing/src/main/java/org/pac4j/jax/rs/TestConfig.java | // Path: core/src/main/java/org/pac4j/jax/rs/pac4j/JaxRsAjaxRequestResolver.java
// public class JaxRsAjaxRequestResolver extends DefaultAjaxRequestResolver {
// @Override
// public boolean isAjax(WebContext context) {
// return true;
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/pac4j/JaxRsUrlResolver.java
// public class JaxRsUrlResolver implements UrlResolver {
//
// @Override
// public String compute(String url, WebContext context) {
// if (context instanceof JaxRsContext && url != null) {
// return ((JaxRsContext) context).getAbsolutePath(url, true);
// }
// return url;
// }
//
// }
| import org.pac4j.core.client.Clients;
import org.pac4j.core.config.Config;
import org.pac4j.core.credentials.UsernamePasswordCredentials;
import org.pac4j.core.credentials.authenticator.Authenticator;
import org.pac4j.http.client.direct.DirectFormClient;
import org.pac4j.http.client.indirect.FormClient;
import org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator;
import org.pac4j.jax.rs.pac4j.JaxRsAjaxRequestResolver;
import org.pac4j.jax.rs.pac4j.JaxRsUrlResolver; | package org.pac4j.jax.rs;
public interface TestConfig {
String DEFAULT_CLIENT = "default-form";
default Config getConfig() {
// login not used because the ajax resolver always answer true
Authenticator<UsernamePasswordCredentials> auth = new SimpleTestUsernamePasswordAuthenticator();
FormClient client = new FormClient("notUsedLoginUrl", auth);
DirectFormClient client2 = new DirectFormClient(auth);
DirectFormClient client3 = new DirectFormClient(auth);
client3.setName(DEFAULT_CLIENT);
Clients clients = new Clients("notUsedCallbackUrl", client, client2, client3);
// in case of invalid credentials, we simply want the error, not a redirect to the login url
clients.setAjaxRequestResolver(new JaxRsAjaxRequestResolver());
// so that callback url have the correct prefix w.r.t. the container's context | // Path: core/src/main/java/org/pac4j/jax/rs/pac4j/JaxRsAjaxRequestResolver.java
// public class JaxRsAjaxRequestResolver extends DefaultAjaxRequestResolver {
// @Override
// public boolean isAjax(WebContext context) {
// return true;
// }
// }
//
// Path: core/src/main/java/org/pac4j/jax/rs/pac4j/JaxRsUrlResolver.java
// public class JaxRsUrlResolver implements UrlResolver {
//
// @Override
// public String compute(String url, WebContext context) {
// if (context instanceof JaxRsContext && url != null) {
// return ((JaxRsContext) context).getAbsolutePath(url, true);
// }
// return url;
// }
//
// }
// Path: testing/src/main/java/org/pac4j/jax/rs/TestConfig.java
import org.pac4j.core.client.Clients;
import org.pac4j.core.config.Config;
import org.pac4j.core.credentials.UsernamePasswordCredentials;
import org.pac4j.core.credentials.authenticator.Authenticator;
import org.pac4j.http.client.direct.DirectFormClient;
import org.pac4j.http.client.indirect.FormClient;
import org.pac4j.http.credentials.authenticator.test.SimpleTestUsernamePasswordAuthenticator;
import org.pac4j.jax.rs.pac4j.JaxRsAjaxRequestResolver;
import org.pac4j.jax.rs.pac4j.JaxRsUrlResolver;
package org.pac4j.jax.rs;
public interface TestConfig {
String DEFAULT_CLIENT = "default-form";
default Config getConfig() {
// login not used because the ajax resolver always answer true
Authenticator<UsernamePasswordCredentials> auth = new SimpleTestUsernamePasswordAuthenticator();
FormClient client = new FormClient("notUsedLoginUrl", auth);
DirectFormClient client2 = new DirectFormClient(auth);
DirectFormClient client3 = new DirectFormClient(auth);
client3.setName(DEFAULT_CLIENT);
Clients clients = new Clients("notUsedCallbackUrl", client, client2, client3);
// in case of invalid credentials, we simply want the error, not a redirect to the login url
clients.setAjaxRequestResolver(new JaxRsAjaxRequestResolver());
// so that callback url have the correct prefix w.r.t. the container's context | clients.setUrlResolver(new JaxRsUrlResolver()); |
pac4j/jax-rs-pac4j | core/src/main/java/org/pac4j/jax/rs/pac4j/JaxRsProfileManager.java | // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
| import java.security.Principal;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import javax.ws.rs.core.SecurityContext;
import org.pac4j.core.profile.*;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext; | package org.pac4j.jax.rs.pac4j;
/**
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class JaxRsProfileManager extends ProfileManager<CommonProfile> {
public JaxRsProfileManager(JaxRsContext context) {
super(context);
}
@Override
public void logout() {
super.logout();
| // Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestPac4JSecurityContext.java
// public class RequestPac4JSecurityContext {
//
// private final SecurityContext securityContext;
//
// public RequestPac4JSecurityContext(JaxRsContext context) {
// this(context.getRequestContext());
// }
//
// public RequestPac4JSecurityContext(ContainerRequestContext request) {
// this(request.getSecurityContext());
// }
//
// public RequestPac4JSecurityContext(SecurityContext securityContext) {
// this.securityContext = securityContext;
// }
//
// public Optional<Pac4JSecurityContext> context() {
// if (securityContext instanceof Pac4JSecurityContext) {
// return Optional.of((Pac4JSecurityContext) securityContext);
// } else {
// return Optional.empty();
// }
// }
// }
// Path: core/src/main/java/org/pac4j/jax/rs/pac4j/JaxRsProfileManager.java
import java.security.Principal;
import java.util.Collection;
import java.util.Collections;
import java.util.Optional;
import javax.ws.rs.core.SecurityContext;
import org.pac4j.core.profile.*;
import org.pac4j.jax.rs.helpers.RequestPac4JSecurityContext;
package org.pac4j.jax.rs.pac4j;
/**
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public class JaxRsProfileManager extends ProfileManager<CommonProfile> {
public JaxRsProfileManager(JaxRsContext context) {
super(context);
}
@Override
public void logout() {
super.logout();
| new RequestPac4JSecurityContext((JaxRsContext) this.context).context().ifPresent(c -> c.principal = null); |
pac4j/jax-rs-pac4j | core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java | // Path: core/src/main/java/org/pac4j/jax/rs/pac4j/JaxRsProfileManager.java
// public class JaxRsProfileManager extends ProfileManager<CommonProfile> {
//
// public JaxRsProfileManager(JaxRsContext context) {
// super(context);
// }
//
// @Override
// public void logout() {
// super.logout();
//
// new RequestPac4JSecurityContext((JaxRsContext) this.context).context().ifPresent(c -> c.principal = null);
// }
//
// public static class Pac4JSecurityContext implements SecurityContext {
//
// private final SecurityContext original;
//
// /**
// * If this is null, it means we are not logged in!
// */
// private Principal principal;
//
// private final Collection<UserProfile> profiles;
//
// private final JaxRsContext context;
//
// public Pac4JSecurityContext(SecurityContext original, JaxRsContext context,
// Collection<UserProfile> profiles) {
// this.original = original;
// this.context = context;
// this.profiles = profiles;
// this.principal = ProfileHelper.flatIntoOneProfile(profiles).map(Pac4JPrincipal::new).orElse(null);
// }
//
// public Optional<Collection<UserProfile>> getProfiles() {
// if (principal != null) {
// return Optional.of(Collections.unmodifiableCollection(profiles));
// } else if (original instanceof Pac4JSecurityContext) {
// return ((Pac4JSecurityContext) original).getProfiles();
// } else {
// return Optional.empty();
// }
// }
//
// public JaxRsContext getContext() {
// // even after logout we can access the context
// return this.context;
// }
//
// @Override
// public Principal getUserPrincipal() {
// if (principal != null) {
// return principal;
// } else {
// return original != null ? original.getUserPrincipal() : null;
// }
// }
//
// @Override
// public boolean isUserInRole(String role) {
// if (principal != null) {
// return profiles.stream().anyMatch(p -> p.getRoles().contains(role));
// } else {
// return original != null && original.isUserInRole(role);
// }
// }
//
// @Override
// public boolean isSecure() {
// return original != null && original.isSecure();
// }
//
// @Override
// public String getAuthenticationScheme() {
// if (principal != null) {
// return "PAC4J";
// } else {
// return original != null ? original.getAuthenticationScheme() : null;
// }
// }
// }
// }
| import org.pac4j.jax.rs.pac4j.JaxRsProfileManager; | package org.pac4j.jax.rs.helpers;
/**
* @author Victor Noel
* @since 2.2.0
*/
public class RequestProfileManager {
private final RequestJaxRsContext context;
public RequestProfileManager(RequestJaxRsContext context) {
this.context = context;
}
| // Path: core/src/main/java/org/pac4j/jax/rs/pac4j/JaxRsProfileManager.java
// public class JaxRsProfileManager extends ProfileManager<CommonProfile> {
//
// public JaxRsProfileManager(JaxRsContext context) {
// super(context);
// }
//
// @Override
// public void logout() {
// super.logout();
//
// new RequestPac4JSecurityContext((JaxRsContext) this.context).context().ifPresent(c -> c.principal = null);
// }
//
// public static class Pac4JSecurityContext implements SecurityContext {
//
// private final SecurityContext original;
//
// /**
// * If this is null, it means we are not logged in!
// */
// private Principal principal;
//
// private final Collection<UserProfile> profiles;
//
// private final JaxRsContext context;
//
// public Pac4JSecurityContext(SecurityContext original, JaxRsContext context,
// Collection<UserProfile> profiles) {
// this.original = original;
// this.context = context;
// this.profiles = profiles;
// this.principal = ProfileHelper.flatIntoOneProfile(profiles).map(Pac4JPrincipal::new).orElse(null);
// }
//
// public Optional<Collection<UserProfile>> getProfiles() {
// if (principal != null) {
// return Optional.of(Collections.unmodifiableCollection(profiles));
// } else if (original instanceof Pac4JSecurityContext) {
// return ((Pac4JSecurityContext) original).getProfiles();
// } else {
// return Optional.empty();
// }
// }
//
// public JaxRsContext getContext() {
// // even after logout we can access the context
// return this.context;
// }
//
// @Override
// public Principal getUserPrincipal() {
// if (principal != null) {
// return principal;
// } else {
// return original != null ? original.getUserPrincipal() : null;
// }
// }
//
// @Override
// public boolean isUserInRole(String role) {
// if (principal != null) {
// return profiles.stream().anyMatch(p -> p.getRoles().contains(role));
// } else {
// return original != null && original.isUserInRole(role);
// }
// }
//
// @Override
// public boolean isSecure() {
// return original != null && original.isSecure();
// }
//
// @Override
// public String getAuthenticationScheme() {
// if (principal != null) {
// return "PAC4J";
// } else {
// return original != null ? original.getAuthenticationScheme() : null;
// }
// }
// }
// }
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestProfileManager.java
import org.pac4j.jax.rs.pac4j.JaxRsProfileManager;
package org.pac4j.jax.rs.helpers;
/**
* @author Victor Noel
* @since 2.2.0
*/
public class RequestProfileManager {
private final RequestJaxRsContext context;
public RequestProfileManager(RequestJaxRsContext context) {
this.context = context;
}
| public JaxRsProfileManager profileManager() { |
pac4j/jax-rs-pac4j | core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java | // Path: core/src/main/java/org/pac4j/jax/rs/pac4j/JaxRsProfileManager.java
// public static class Pac4JSecurityContext implements SecurityContext {
//
// private final SecurityContext original;
//
// /**
// * If this is null, it means we are not logged in!
// */
// private Principal principal;
//
// private final Collection<UserProfile> profiles;
//
// private final JaxRsContext context;
//
// public Pac4JSecurityContext(SecurityContext original, JaxRsContext context,
// Collection<UserProfile> profiles) {
// this.original = original;
// this.context = context;
// this.profiles = profiles;
// this.principal = ProfileHelper.flatIntoOneProfile(profiles).map(Pac4JPrincipal::new).orElse(null);
// }
//
// public Optional<Collection<UserProfile>> getProfiles() {
// if (principal != null) {
// return Optional.of(Collections.unmodifiableCollection(profiles));
// } else if (original instanceof Pac4JSecurityContext) {
// return ((Pac4JSecurityContext) original).getProfiles();
// } else {
// return Optional.empty();
// }
// }
//
// public JaxRsContext getContext() {
// // even after logout we can access the context
// return this.context;
// }
//
// @Override
// public Principal getUserPrincipal() {
// if (principal != null) {
// return principal;
// } else {
// return original != null ? original.getUserPrincipal() : null;
// }
// }
//
// @Override
// public boolean isUserInRole(String role) {
// if (principal != null) {
// return profiles.stream().anyMatch(p -> p.getRoles().contains(role));
// } else {
// return original != null && original.isUserInRole(role);
// }
// }
//
// @Override
// public boolean isSecure() {
// return original != null && original.isSecure();
// }
//
// @Override
// public String getAuthenticationScheme() {
// if (principal != null) {
// return "PAC4J";
// } else {
// return original != null ? original.getAuthenticationScheme() : null;
// }
// }
// }
| import java.util.Optional;
import org.pac4j.core.profile.ProfileHelper;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.pac4j.JaxRsProfileManager.Pac4JSecurityContext; | package org.pac4j.jax.rs.helpers;
/**
* @author Victor Noel
* @since 2.2.0
*/
public class RequestUserProfile {
private final RequestPac4JSecurityContext context;
public RequestUserProfile(RequestPac4JSecurityContext context) {
this.context = context;
}
public Optional<UserProfile> profile() {
return context.context() | // Path: core/src/main/java/org/pac4j/jax/rs/pac4j/JaxRsProfileManager.java
// public static class Pac4JSecurityContext implements SecurityContext {
//
// private final SecurityContext original;
//
// /**
// * If this is null, it means we are not logged in!
// */
// private Principal principal;
//
// private final Collection<UserProfile> profiles;
//
// private final JaxRsContext context;
//
// public Pac4JSecurityContext(SecurityContext original, JaxRsContext context,
// Collection<UserProfile> profiles) {
// this.original = original;
// this.context = context;
// this.profiles = profiles;
// this.principal = ProfileHelper.flatIntoOneProfile(profiles).map(Pac4JPrincipal::new).orElse(null);
// }
//
// public Optional<Collection<UserProfile>> getProfiles() {
// if (principal != null) {
// return Optional.of(Collections.unmodifiableCollection(profiles));
// } else if (original instanceof Pac4JSecurityContext) {
// return ((Pac4JSecurityContext) original).getProfiles();
// } else {
// return Optional.empty();
// }
// }
//
// public JaxRsContext getContext() {
// // even after logout we can access the context
// return this.context;
// }
//
// @Override
// public Principal getUserPrincipal() {
// if (principal != null) {
// return principal;
// } else {
// return original != null ? original.getUserPrincipal() : null;
// }
// }
//
// @Override
// public boolean isUserInRole(String role) {
// if (principal != null) {
// return profiles.stream().anyMatch(p -> p.getRoles().contains(role));
// } else {
// return original != null && original.isUserInRole(role);
// }
// }
//
// @Override
// public boolean isSecure() {
// return original != null && original.isSecure();
// }
//
// @Override
// public String getAuthenticationScheme() {
// if (principal != null) {
// return "PAC4J";
// } else {
// return original != null ? original.getAuthenticationScheme() : null;
// }
// }
// }
// Path: core/src/main/java/org/pac4j/jax/rs/helpers/RequestUserProfile.java
import java.util.Optional;
import org.pac4j.core.profile.ProfileHelper;
import org.pac4j.core.profile.UserProfile;
import org.pac4j.jax.rs.pac4j.JaxRsProfileManager.Pac4JSecurityContext;
package org.pac4j.jax.rs.helpers;
/**
* @author Victor Noel
* @since 2.2.0
*/
public class RequestUserProfile {
private final RequestPac4JSecurityContext context;
public RequestUserProfile(RequestPac4JSecurityContext context) {
this.context = context;
}
public Optional<UserProfile> profile() {
return context.context() | .flatMap(Pac4JSecurityContext::getProfiles) |
pac4j/jax-rs-pac4j | testing/src/main/java/org/pac4j/jax/rs/AbstractSessionTest.java | // Path: testing/src/main/java/org/pac4j/jax/rs/rules/SessionContainerRule.java
// public interface SessionContainerRule extends ContainerRule {
//
// @Override
// default Set<Class<?>> getResources() {
// Set<Class<?>> resources = ContainerRule.super.getResources();
// resources.add(TestSessionResource.class);
// return resources;
// }
// }
| import static org.assertj.core.api.Assertions.assertThat;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.junit.Test;
import org.pac4j.core.util.Pac4jConstants;
import org.pac4j.jax.rs.rules.SessionContainerRule; | package org.pac4j.jax.rs;
/**
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public abstract class AbstractSessionTest extends AbstractTest {
@Override | // Path: testing/src/main/java/org/pac4j/jax/rs/rules/SessionContainerRule.java
// public interface SessionContainerRule extends ContainerRule {
//
// @Override
// default Set<Class<?>> getResources() {
// Set<Class<?>> resources = ContainerRule.super.getResources();
// resources.add(TestSessionResource.class);
// return resources;
// }
// }
// Path: testing/src/main/java/org/pac4j/jax/rs/AbstractSessionTest.java
import static org.assertj.core.api.Assertions.assertThat;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.junit.Test;
import org.pac4j.core.util.Pac4jConstants;
import org.pac4j.jax.rs.rules.SessionContainerRule;
package org.pac4j.jax.rs;
/**
*
* @author Victor Noel - Linagora
* @since 1.0.0
*
*/
public abstract class AbstractSessionTest extends AbstractTest {
@Override | protected abstract SessionContainerRule createContainer(); |
APISENSE/android-network-measures | measures/src/main/java/io/apisense/network/udp/UDPBurstTask.java | // Path: measures/src/main/java/io/apisense/network/Measurement.java
// public abstract class Measurement {
// public final String taskName;
//
// protected Measurement(String taskName) {
// this.taskName = taskName;
// }
//
// /**
// * Ensure that the measurement is asynchronously called in an {@link ExecutorService}.
// *
// * @param callback The {@link MeasurementCallback} used
// * for reporting success or failure of this measurement.
// */
// public final void call(MeasurementCallback callback) {
// AsyncTask.execute(new MeasurementExecutor(this, callback));
// }
//
// /**
// * Actual, synchronous, process of a measurement.
// * This method has to be called from another thread than the UI one.
// *
// * @return The results of this measurement.
// * @throws MeasurementError If anything goes wrong during measurement.
// */
// public abstract MeasurementResult execute() throws MeasurementError;
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
| import android.support.annotation.NonNull;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;
import io.apisense.network.Measurement;
import io.apisense.network.MeasurementError; | package io.apisense.network.udp;
/**
* Abstract class containing common code used for UDP upload and download tests
*/
public abstract class UDPBurstTask extends Measurement {
protected static final int DEFAULT_PORT = 31341;
/**
* round-trip delay, in msec.
*/
protected static final int RCV_TIMEOUT = 2000;
protected long startTimeTask; //time in milliseconds
protected long endTimeTask; //time in milliseconds
protected UDPBurstConfig config;
public UDPBurstTask(String taskName, UDPBurstConfig udpBurstConfig) {
super(taskName);
this.config = udpBurstConfig;
}
/**
* Wait for the socket to retrieve a response to the previous burst.
*
* @param sock The socket to listen through.
* @return An {@link UDPPacket} containing the response.
* @throws MeasurementError If any error occurred during measurement.
*/
@NonNull | // Path: measures/src/main/java/io/apisense/network/Measurement.java
// public abstract class Measurement {
// public final String taskName;
//
// protected Measurement(String taskName) {
// this.taskName = taskName;
// }
//
// /**
// * Ensure that the measurement is asynchronously called in an {@link ExecutorService}.
// *
// * @param callback The {@link MeasurementCallback} used
// * for reporting success or failure of this measurement.
// */
// public final void call(MeasurementCallback callback) {
// AsyncTask.execute(new MeasurementExecutor(this, callback));
// }
//
// /**
// * Actual, synchronous, process of a measurement.
// * This method has to be called from another thread than the UI one.
// *
// * @return The results of this measurement.
// * @throws MeasurementError If anything goes wrong during measurement.
// */
// public abstract MeasurementResult execute() throws MeasurementError;
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
// Path: measures/src/main/java/io/apisense/network/udp/UDPBurstTask.java
import android.support.annotation.NonNull;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;
import io.apisense.network.Measurement;
import io.apisense.network.MeasurementError;
package io.apisense.network.udp;
/**
* Abstract class containing common code used for UDP upload and download tests
*/
public abstract class UDPBurstTask extends Measurement {
protected static final int DEFAULT_PORT = 31341;
/**
* round-trip delay, in msec.
*/
protected static final int RCV_TIMEOUT = 2000;
protected long startTimeTask; //time in milliseconds
protected long endTimeTask; //time in milliseconds
protected UDPBurstConfig config;
public UDPBurstTask(String taskName, UDPBurstConfig udpBurstConfig) {
super(taskName);
this.config = udpBurstConfig;
}
/**
* Wait for the socket to retrieve a response to the previous burst.
*
* @param sock The socket to listen through.
* @return An {@link UDPPacket} containing the response.
* @throws MeasurementError If any error occurred during measurement.
*/
@NonNull | protected UDPPacket retrieveResponseDatagram(DatagramSocket sock) throws MeasurementError { |
APISENSE/android-network-measures | measures/src/main/java/io/apisense/network/ping/ICMPTask.java | // Path: measures/src/main/java/io/apisense/network/Measurement.java
// public abstract class Measurement {
// public final String taskName;
//
// protected Measurement(String taskName) {
// this.taskName = taskName;
// }
//
// /**
// * Ensure that the measurement is asynchronously called in an {@link ExecutorService}.
// *
// * @param callback The {@link MeasurementCallback} used
// * for reporting success or failure of this measurement.
// */
// public final void call(MeasurementCallback callback) {
// AsyncTask.execute(new MeasurementExecutor(this, callback));
// }
//
// /**
// * Actual, synchronous, process of a measurement.
// * This method has to be called from another thread than the UI one.
// *
// * @return The results of this measurement.
// * @throws MeasurementError If anything goes wrong during measurement.
// */
// public abstract MeasurementResult execute() throws MeasurementError;
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
| import android.support.annotation.NonNull;
import android.util.Log;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import io.apisense.network.Measurement;
import io.apisense.network.MeasurementError; | if (matcher.matches()) {
ip = matcher.group(1);
latency = Float.valueOf(matcher.group(2)).longValue(); // milliseconds
}
matcher = PING_RESPONSE_RTT_SUCCESS.matcher(line);
if (matcher.matches()) {
float min = Float.valueOf(matcher.group(1));
float avg = Float.valueOf(matcher.group(2));
float max = Float.valueOf(matcher.group(3));
float mdev = Float.valueOf(matcher.group(4));
rtt = new Rtt(min, avg, max, mdev);
return new ICMPResult(startTimeMs, endTime, config, hostname, ip, latency, currentTtl, rtt);
}
matcher = PING_RESPONSE_TIMEOUT.matcher(line);
if (matcher.matches()) {
throw new PINGException("Packet is lost");
}
}
throw new PINGException("Could not parse response");
}
@Override
@NonNull | // Path: measures/src/main/java/io/apisense/network/Measurement.java
// public abstract class Measurement {
// public final String taskName;
//
// protected Measurement(String taskName) {
// this.taskName = taskName;
// }
//
// /**
// * Ensure that the measurement is asynchronously called in an {@link ExecutorService}.
// *
// * @param callback The {@link MeasurementCallback} used
// * for reporting success or failure of this measurement.
// */
// public final void call(MeasurementCallback callback) {
// AsyncTask.execute(new MeasurementExecutor(this, callback));
// }
//
// /**
// * Actual, synchronous, process of a measurement.
// * This method has to be called from another thread than the UI one.
// *
// * @return The results of this measurement.
// * @throws MeasurementError If anything goes wrong during measurement.
// */
// public abstract MeasurementResult execute() throws MeasurementError;
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
// Path: measures/src/main/java/io/apisense/network/ping/ICMPTask.java
import android.support.annotation.NonNull;
import android.util.Log;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import io.apisense.network.Measurement;
import io.apisense.network.MeasurementError;
if (matcher.matches()) {
ip = matcher.group(1);
latency = Float.valueOf(matcher.group(2)).longValue(); // milliseconds
}
matcher = PING_RESPONSE_RTT_SUCCESS.matcher(line);
if (matcher.matches()) {
float min = Float.valueOf(matcher.group(1));
float avg = Float.valueOf(matcher.group(2));
float max = Float.valueOf(matcher.group(3));
float mdev = Float.valueOf(matcher.group(4));
rtt = new Rtt(min, avg, max, mdev);
return new ICMPResult(startTimeMs, endTime, config, hostname, ip, latency, currentTtl, rtt);
}
matcher = PING_RESPONSE_TIMEOUT.matcher(line);
if (matcher.matches()) {
throw new PINGException("Packet is lost");
}
}
throw new PINGException("Could not parse response");
}
@Override
@NonNull | public ICMPResult execute() throws MeasurementError { |
APISENSE/android-network-measures | measures/src/main/java/io/apisense/network/dns/DNSLookupTask.java | // Path: measures/src/main/java/org/xbill/DNS/DNSClient.java
// public interface DNSClient {
// void bind(SocketAddress addr) throws IOException;
//
// void connect(SocketAddress addr) throws IOException;
//
// void send(byte[] data) throws IOException;
//
// byte[] recv(int max) throws IOException;
//
// void cleanup() throws IOException;
// }
//
// Path: measures/src/main/java/org/xbill/DNS/PublicTCPClient.java
// public final class PublicTCPClient implements DNSClient {
// private final TCPClient client;
//
// public PublicTCPClient(long endTime) throws IOException {
// client = new TCPClient(endTime);
// }
//
// @Override
// public void bind(SocketAddress addr) throws IOException {
// client.bind(addr);
// }
//
// @Override
// public void connect(SocketAddress addr) throws IOException {
// client.connect(addr);
// }
//
// @Override
// public void send(byte[] data) throws IOException {
// client.send(data);
// }
//
// /**
// * Receive DNS data.
// *
// * @param max Not used in tcp implementation
// * @return The received content.
// * @throws IOException {@inheritDoc}
// */
// @Override
// public byte[] recv(int max) throws IOException {
// return client.recv();
// }
//
// @Override
// public void cleanup() throws IOException {
// client.cleanup();
// }
// }
//
// Path: measures/src/main/java/org/xbill/DNS/PublicUDPClient.java
// public final class PublicUDPClient implements DNSClient {
// private final UDPClient client;
//
// public PublicUDPClient(long endTime) throws IOException {
// client = new UDPClient(endTime);
// }
//
// @Override
// public void bind(SocketAddress addr) throws IOException {
// client.bind(addr);
// }
//
// @Override
// public void connect(SocketAddress addr) throws IOException {
// client.connect(addr);
// }
//
// @Override
// public void send(byte[] data) throws IOException {
// client.send(data);
// }
//
// @Override
// public byte[] recv(int max) throws IOException {
// return client.recv(max);
// }
//
// @Override
// public void cleanup() throws IOException {
// client.cleanup();
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/Measurement.java
// public abstract class Measurement {
// public final String taskName;
//
// protected Measurement(String taskName) {
// this.taskName = taskName;
// }
//
// /**
// * Ensure that the measurement is asynchronously called in an {@link ExecutorService}.
// *
// * @param callback The {@link MeasurementCallback} used
// * for reporting success or failure of this measurement.
// */
// public final void call(MeasurementCallback callback) {
// AsyncTask.execute(new MeasurementExecutor(this, callback));
// }
//
// /**
// * Actual, synchronous, process of a measurement.
// * This method has to be called from another thread than the UI one.
// *
// * @return The results of this measurement.
// * @throws MeasurementError If anything goes wrong during measurement.
// */
// public abstract MeasurementResult execute() throws MeasurementError;
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
| import android.support.annotation.NonNull;
import android.util.Log;
import org.xbill.DNS.DClass;
import org.xbill.DNS.DNSClient;
import org.xbill.DNS.Flags;
import org.xbill.DNS.Message;
import org.xbill.DNS.Name;
import org.xbill.DNS.OPTRecord;
import org.xbill.DNS.PublicTCPClient;
import org.xbill.DNS.PublicUDPClient;
import org.xbill.DNS.Record;
import org.xbill.DNS.TextParseException;
import org.xbill.DNS.Type;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import io.apisense.network.Measurement;
import io.apisense.network.MeasurementError; | package io.apisense.network.dns;
/**
* Measures the DNS lookup time
*/
public class DNSLookupTask extends Measurement {
public static final String TAG = "DNSLookup";
private final DNSLookupConfig config;
public DNSLookupTask(DNSLookupConfig config) {
super(TAG);
this.config = config;
}
/**
* Parse the raw response bytes to a wrapped dns answer.
*
* @param useTCP If the client is currently using TCP.
* @param respBytes The raw response bytes.
* @return The parsed {@link Message}.
* @throws MeasurementError If the response could not be parsed.
* @throws TruncatedException If the response is truncated while client is using UDP.
*/
@NonNull
private Message parseMessage(boolean useTCP, byte[] respBytes) | // Path: measures/src/main/java/org/xbill/DNS/DNSClient.java
// public interface DNSClient {
// void bind(SocketAddress addr) throws IOException;
//
// void connect(SocketAddress addr) throws IOException;
//
// void send(byte[] data) throws IOException;
//
// byte[] recv(int max) throws IOException;
//
// void cleanup() throws IOException;
// }
//
// Path: measures/src/main/java/org/xbill/DNS/PublicTCPClient.java
// public final class PublicTCPClient implements DNSClient {
// private final TCPClient client;
//
// public PublicTCPClient(long endTime) throws IOException {
// client = new TCPClient(endTime);
// }
//
// @Override
// public void bind(SocketAddress addr) throws IOException {
// client.bind(addr);
// }
//
// @Override
// public void connect(SocketAddress addr) throws IOException {
// client.connect(addr);
// }
//
// @Override
// public void send(byte[] data) throws IOException {
// client.send(data);
// }
//
// /**
// * Receive DNS data.
// *
// * @param max Not used in tcp implementation
// * @return The received content.
// * @throws IOException {@inheritDoc}
// */
// @Override
// public byte[] recv(int max) throws IOException {
// return client.recv();
// }
//
// @Override
// public void cleanup() throws IOException {
// client.cleanup();
// }
// }
//
// Path: measures/src/main/java/org/xbill/DNS/PublicUDPClient.java
// public final class PublicUDPClient implements DNSClient {
// private final UDPClient client;
//
// public PublicUDPClient(long endTime) throws IOException {
// client = new UDPClient(endTime);
// }
//
// @Override
// public void bind(SocketAddress addr) throws IOException {
// client.bind(addr);
// }
//
// @Override
// public void connect(SocketAddress addr) throws IOException {
// client.connect(addr);
// }
//
// @Override
// public void send(byte[] data) throws IOException {
// client.send(data);
// }
//
// @Override
// public byte[] recv(int max) throws IOException {
// return client.recv(max);
// }
//
// @Override
// public void cleanup() throws IOException {
// client.cleanup();
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/Measurement.java
// public abstract class Measurement {
// public final String taskName;
//
// protected Measurement(String taskName) {
// this.taskName = taskName;
// }
//
// /**
// * Ensure that the measurement is asynchronously called in an {@link ExecutorService}.
// *
// * @param callback The {@link MeasurementCallback} used
// * for reporting success or failure of this measurement.
// */
// public final void call(MeasurementCallback callback) {
// AsyncTask.execute(new MeasurementExecutor(this, callback));
// }
//
// /**
// * Actual, synchronous, process of a measurement.
// * This method has to be called from another thread than the UI one.
// *
// * @return The results of this measurement.
// * @throws MeasurementError If anything goes wrong during measurement.
// */
// public abstract MeasurementResult execute() throws MeasurementError;
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
// Path: measures/src/main/java/io/apisense/network/dns/DNSLookupTask.java
import android.support.annotation.NonNull;
import android.util.Log;
import org.xbill.DNS.DClass;
import org.xbill.DNS.DNSClient;
import org.xbill.DNS.Flags;
import org.xbill.DNS.Message;
import org.xbill.DNS.Name;
import org.xbill.DNS.OPTRecord;
import org.xbill.DNS.PublicTCPClient;
import org.xbill.DNS.PublicUDPClient;
import org.xbill.DNS.Record;
import org.xbill.DNS.TextParseException;
import org.xbill.DNS.Type;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import io.apisense.network.Measurement;
import io.apisense.network.MeasurementError;
package io.apisense.network.dns;
/**
* Measures the DNS lookup time
*/
public class DNSLookupTask extends Measurement {
public static final String TAG = "DNSLookup";
private final DNSLookupConfig config;
public DNSLookupTask(DNSLookupConfig config) {
super(TAG);
this.config = config;
}
/**
* Parse the raw response bytes to a wrapped dns answer.
*
* @param useTCP If the client is currently using TCP.
* @param respBytes The raw response bytes.
* @return The parsed {@link Message}.
* @throws MeasurementError If the response could not be parsed.
* @throws TruncatedException If the response is truncated while client is using UDP.
*/
@NonNull
private Message parseMessage(boolean useTCP, byte[] respBytes) | throws TruncatedException, MeasurementError { |
APISENSE/android-network-measures | measures/src/main/java/io/apisense/network/dns/DNSLookupTask.java | // Path: measures/src/main/java/org/xbill/DNS/DNSClient.java
// public interface DNSClient {
// void bind(SocketAddress addr) throws IOException;
//
// void connect(SocketAddress addr) throws IOException;
//
// void send(byte[] data) throws IOException;
//
// byte[] recv(int max) throws IOException;
//
// void cleanup() throws IOException;
// }
//
// Path: measures/src/main/java/org/xbill/DNS/PublicTCPClient.java
// public final class PublicTCPClient implements DNSClient {
// private final TCPClient client;
//
// public PublicTCPClient(long endTime) throws IOException {
// client = new TCPClient(endTime);
// }
//
// @Override
// public void bind(SocketAddress addr) throws IOException {
// client.bind(addr);
// }
//
// @Override
// public void connect(SocketAddress addr) throws IOException {
// client.connect(addr);
// }
//
// @Override
// public void send(byte[] data) throws IOException {
// client.send(data);
// }
//
// /**
// * Receive DNS data.
// *
// * @param max Not used in tcp implementation
// * @return The received content.
// * @throws IOException {@inheritDoc}
// */
// @Override
// public byte[] recv(int max) throws IOException {
// return client.recv();
// }
//
// @Override
// public void cleanup() throws IOException {
// client.cleanup();
// }
// }
//
// Path: measures/src/main/java/org/xbill/DNS/PublicUDPClient.java
// public final class PublicUDPClient implements DNSClient {
// private final UDPClient client;
//
// public PublicUDPClient(long endTime) throws IOException {
// client = new UDPClient(endTime);
// }
//
// @Override
// public void bind(SocketAddress addr) throws IOException {
// client.bind(addr);
// }
//
// @Override
// public void connect(SocketAddress addr) throws IOException {
// client.connect(addr);
// }
//
// @Override
// public void send(byte[] data) throws IOException {
// client.send(data);
// }
//
// @Override
// public byte[] recv(int max) throws IOException {
// return client.recv(max);
// }
//
// @Override
// public void cleanup() throws IOException {
// client.cleanup();
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/Measurement.java
// public abstract class Measurement {
// public final String taskName;
//
// protected Measurement(String taskName) {
// this.taskName = taskName;
// }
//
// /**
// * Ensure that the measurement is asynchronously called in an {@link ExecutorService}.
// *
// * @param callback The {@link MeasurementCallback} used
// * for reporting success or failure of this measurement.
// */
// public final void call(MeasurementCallback callback) {
// AsyncTask.execute(new MeasurementExecutor(this, callback));
// }
//
// /**
// * Actual, synchronous, process of a measurement.
// * This method has to be called from another thread than the UI one.
// *
// * @return The results of this measurement.
// * @throws MeasurementError If anything goes wrong during measurement.
// */
// public abstract MeasurementResult execute() throws MeasurementError;
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
| import android.support.annotation.NonNull;
import android.util.Log;
import org.xbill.DNS.DClass;
import org.xbill.DNS.DNSClient;
import org.xbill.DNS.Flags;
import org.xbill.DNS.Message;
import org.xbill.DNS.Name;
import org.xbill.DNS.OPTRecord;
import org.xbill.DNS.PublicTCPClient;
import org.xbill.DNS.PublicUDPClient;
import org.xbill.DNS.Record;
import org.xbill.DNS.TextParseException;
import org.xbill.DNS.Type;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import io.apisense.network.Measurement;
import io.apisense.network.MeasurementError; | package io.apisense.network.dns;
/**
* Measures the DNS lookup time
*/
public class DNSLookupTask extends Measurement {
public static final String TAG = "DNSLookup";
private final DNSLookupConfig config;
public DNSLookupTask(DNSLookupConfig config) {
super(TAG);
this.config = config;
}
/**
* Parse the raw response bytes to a wrapped dns answer.
*
* @param useTCP If the client is currently using TCP.
* @param respBytes The raw response bytes.
* @return The parsed {@link Message}.
* @throws MeasurementError If the response could not be parsed.
* @throws TruncatedException If the response is truncated while client is using UDP.
*/
@NonNull
private Message parseMessage(boolean useTCP, byte[] respBytes)
throws TruncatedException, MeasurementError {
Message response;
try {
response = new Message(respBytes);
Log.d(TAG, "Successfully parsed response");
// if the response was truncated, then re-query over TCP
if (!useTCP && response.getHeader().getFlag(Flags.TC)) {
throw new TruncatedException();
}
} catch (IOException e) {
throw new MeasurementError(taskName, "Problem trying to parse dns packet", e);
}
return response;
}
/**
* Initialize and connect the dns TCP or UDP client.
*
* @param server The server to connect the client to.
* @param useTCP Tells if the client should be TCP or UDP.
* @param endTime The request timeout.
* @return The initialized client.
* @throws MeasurementError If any error occurred during client creation or connection.
*/
@NonNull | // Path: measures/src/main/java/org/xbill/DNS/DNSClient.java
// public interface DNSClient {
// void bind(SocketAddress addr) throws IOException;
//
// void connect(SocketAddress addr) throws IOException;
//
// void send(byte[] data) throws IOException;
//
// byte[] recv(int max) throws IOException;
//
// void cleanup() throws IOException;
// }
//
// Path: measures/src/main/java/org/xbill/DNS/PublicTCPClient.java
// public final class PublicTCPClient implements DNSClient {
// private final TCPClient client;
//
// public PublicTCPClient(long endTime) throws IOException {
// client = new TCPClient(endTime);
// }
//
// @Override
// public void bind(SocketAddress addr) throws IOException {
// client.bind(addr);
// }
//
// @Override
// public void connect(SocketAddress addr) throws IOException {
// client.connect(addr);
// }
//
// @Override
// public void send(byte[] data) throws IOException {
// client.send(data);
// }
//
// /**
// * Receive DNS data.
// *
// * @param max Not used in tcp implementation
// * @return The received content.
// * @throws IOException {@inheritDoc}
// */
// @Override
// public byte[] recv(int max) throws IOException {
// return client.recv();
// }
//
// @Override
// public void cleanup() throws IOException {
// client.cleanup();
// }
// }
//
// Path: measures/src/main/java/org/xbill/DNS/PublicUDPClient.java
// public final class PublicUDPClient implements DNSClient {
// private final UDPClient client;
//
// public PublicUDPClient(long endTime) throws IOException {
// client = new UDPClient(endTime);
// }
//
// @Override
// public void bind(SocketAddress addr) throws IOException {
// client.bind(addr);
// }
//
// @Override
// public void connect(SocketAddress addr) throws IOException {
// client.connect(addr);
// }
//
// @Override
// public void send(byte[] data) throws IOException {
// client.send(data);
// }
//
// @Override
// public byte[] recv(int max) throws IOException {
// return client.recv(max);
// }
//
// @Override
// public void cleanup() throws IOException {
// client.cleanup();
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/Measurement.java
// public abstract class Measurement {
// public final String taskName;
//
// protected Measurement(String taskName) {
// this.taskName = taskName;
// }
//
// /**
// * Ensure that the measurement is asynchronously called in an {@link ExecutorService}.
// *
// * @param callback The {@link MeasurementCallback} used
// * for reporting success or failure of this measurement.
// */
// public final void call(MeasurementCallback callback) {
// AsyncTask.execute(new MeasurementExecutor(this, callback));
// }
//
// /**
// * Actual, synchronous, process of a measurement.
// * This method has to be called from another thread than the UI one.
// *
// * @return The results of this measurement.
// * @throws MeasurementError If anything goes wrong during measurement.
// */
// public abstract MeasurementResult execute() throws MeasurementError;
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
// Path: measures/src/main/java/io/apisense/network/dns/DNSLookupTask.java
import android.support.annotation.NonNull;
import android.util.Log;
import org.xbill.DNS.DClass;
import org.xbill.DNS.DNSClient;
import org.xbill.DNS.Flags;
import org.xbill.DNS.Message;
import org.xbill.DNS.Name;
import org.xbill.DNS.OPTRecord;
import org.xbill.DNS.PublicTCPClient;
import org.xbill.DNS.PublicUDPClient;
import org.xbill.DNS.Record;
import org.xbill.DNS.TextParseException;
import org.xbill.DNS.Type;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import io.apisense.network.Measurement;
import io.apisense.network.MeasurementError;
package io.apisense.network.dns;
/**
* Measures the DNS lookup time
*/
public class DNSLookupTask extends Measurement {
public static final String TAG = "DNSLookup";
private final DNSLookupConfig config;
public DNSLookupTask(DNSLookupConfig config) {
super(TAG);
this.config = config;
}
/**
* Parse the raw response bytes to a wrapped dns answer.
*
* @param useTCP If the client is currently using TCP.
* @param respBytes The raw response bytes.
* @return The parsed {@link Message}.
* @throws MeasurementError If the response could not be parsed.
* @throws TruncatedException If the response is truncated while client is using UDP.
*/
@NonNull
private Message parseMessage(boolean useTCP, byte[] respBytes)
throws TruncatedException, MeasurementError {
Message response;
try {
response = new Message(respBytes);
Log.d(TAG, "Successfully parsed response");
// if the response was truncated, then re-query over TCP
if (!useTCP && response.getHeader().getFlag(Flags.TC)) {
throw new TruncatedException();
}
} catch (IOException e) {
throw new MeasurementError(taskName, "Problem trying to parse dns packet", e);
}
return response;
}
/**
* Initialize and connect the dns TCP or UDP client.
*
* @param server The server to connect the client to.
* @param useTCP Tells if the client should be TCP or UDP.
* @param endTime The request timeout.
* @return The initialized client.
* @throws MeasurementError If any error occurred during client creation or connection.
*/
@NonNull | private DNSClient connectClient(String server, boolean useTCP, long endTime) |
APISENSE/android-network-measures | measures/src/main/java/io/apisense/network/dns/DNSLookupTask.java | // Path: measures/src/main/java/org/xbill/DNS/DNSClient.java
// public interface DNSClient {
// void bind(SocketAddress addr) throws IOException;
//
// void connect(SocketAddress addr) throws IOException;
//
// void send(byte[] data) throws IOException;
//
// byte[] recv(int max) throws IOException;
//
// void cleanup() throws IOException;
// }
//
// Path: measures/src/main/java/org/xbill/DNS/PublicTCPClient.java
// public final class PublicTCPClient implements DNSClient {
// private final TCPClient client;
//
// public PublicTCPClient(long endTime) throws IOException {
// client = new TCPClient(endTime);
// }
//
// @Override
// public void bind(SocketAddress addr) throws IOException {
// client.bind(addr);
// }
//
// @Override
// public void connect(SocketAddress addr) throws IOException {
// client.connect(addr);
// }
//
// @Override
// public void send(byte[] data) throws IOException {
// client.send(data);
// }
//
// /**
// * Receive DNS data.
// *
// * @param max Not used in tcp implementation
// * @return The received content.
// * @throws IOException {@inheritDoc}
// */
// @Override
// public byte[] recv(int max) throws IOException {
// return client.recv();
// }
//
// @Override
// public void cleanup() throws IOException {
// client.cleanup();
// }
// }
//
// Path: measures/src/main/java/org/xbill/DNS/PublicUDPClient.java
// public final class PublicUDPClient implements DNSClient {
// private final UDPClient client;
//
// public PublicUDPClient(long endTime) throws IOException {
// client = new UDPClient(endTime);
// }
//
// @Override
// public void bind(SocketAddress addr) throws IOException {
// client.bind(addr);
// }
//
// @Override
// public void connect(SocketAddress addr) throws IOException {
// client.connect(addr);
// }
//
// @Override
// public void send(byte[] data) throws IOException {
// client.send(data);
// }
//
// @Override
// public byte[] recv(int max) throws IOException {
// return client.recv(max);
// }
//
// @Override
// public void cleanup() throws IOException {
// client.cleanup();
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/Measurement.java
// public abstract class Measurement {
// public final String taskName;
//
// protected Measurement(String taskName) {
// this.taskName = taskName;
// }
//
// /**
// * Ensure that the measurement is asynchronously called in an {@link ExecutorService}.
// *
// * @param callback The {@link MeasurementCallback} used
// * for reporting success or failure of this measurement.
// */
// public final void call(MeasurementCallback callback) {
// AsyncTask.execute(new MeasurementExecutor(this, callback));
// }
//
// /**
// * Actual, synchronous, process of a measurement.
// * This method has to be called from another thread than the UI one.
// *
// * @return The results of this measurement.
// * @throws MeasurementError If anything goes wrong during measurement.
// */
// public abstract MeasurementResult execute() throws MeasurementError;
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
| import android.support.annotation.NonNull;
import android.util.Log;
import org.xbill.DNS.DClass;
import org.xbill.DNS.DNSClient;
import org.xbill.DNS.Flags;
import org.xbill.DNS.Message;
import org.xbill.DNS.Name;
import org.xbill.DNS.OPTRecord;
import org.xbill.DNS.PublicTCPClient;
import org.xbill.DNS.PublicUDPClient;
import org.xbill.DNS.Record;
import org.xbill.DNS.TextParseException;
import org.xbill.DNS.Type;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import io.apisense.network.Measurement;
import io.apisense.network.MeasurementError; | package io.apisense.network.dns;
/**
* Measures the DNS lookup time
*/
public class DNSLookupTask extends Measurement {
public static final String TAG = "DNSLookup";
private final DNSLookupConfig config;
public DNSLookupTask(DNSLookupConfig config) {
super(TAG);
this.config = config;
}
/**
* Parse the raw response bytes to a wrapped dns answer.
*
* @param useTCP If the client is currently using TCP.
* @param respBytes The raw response bytes.
* @return The parsed {@link Message}.
* @throws MeasurementError If the response could not be parsed.
* @throws TruncatedException If the response is truncated while client is using UDP.
*/
@NonNull
private Message parseMessage(boolean useTCP, byte[] respBytes)
throws TruncatedException, MeasurementError {
Message response;
try {
response = new Message(respBytes);
Log.d(TAG, "Successfully parsed response");
// if the response was truncated, then re-query over TCP
if (!useTCP && response.getHeader().getFlag(Flags.TC)) {
throw new TruncatedException();
}
} catch (IOException e) {
throw new MeasurementError(taskName, "Problem trying to parse dns packet", e);
}
return response;
}
/**
* Initialize and connect the dns TCP or UDP client.
*
* @param server The server to connect the client to.
* @param useTCP Tells if the client should be TCP or UDP.
* @param endTime The request timeout.
* @return The initialized client.
* @throws MeasurementError If any error occurred during client creation or connection.
*/
@NonNull
private DNSClient connectClient(String server, boolean useTCP, long endTime)
throws MeasurementError {
DNSClient client;
try {
if (useTCP) { | // Path: measures/src/main/java/org/xbill/DNS/DNSClient.java
// public interface DNSClient {
// void bind(SocketAddress addr) throws IOException;
//
// void connect(SocketAddress addr) throws IOException;
//
// void send(byte[] data) throws IOException;
//
// byte[] recv(int max) throws IOException;
//
// void cleanup() throws IOException;
// }
//
// Path: measures/src/main/java/org/xbill/DNS/PublicTCPClient.java
// public final class PublicTCPClient implements DNSClient {
// private final TCPClient client;
//
// public PublicTCPClient(long endTime) throws IOException {
// client = new TCPClient(endTime);
// }
//
// @Override
// public void bind(SocketAddress addr) throws IOException {
// client.bind(addr);
// }
//
// @Override
// public void connect(SocketAddress addr) throws IOException {
// client.connect(addr);
// }
//
// @Override
// public void send(byte[] data) throws IOException {
// client.send(data);
// }
//
// /**
// * Receive DNS data.
// *
// * @param max Not used in tcp implementation
// * @return The received content.
// * @throws IOException {@inheritDoc}
// */
// @Override
// public byte[] recv(int max) throws IOException {
// return client.recv();
// }
//
// @Override
// public void cleanup() throws IOException {
// client.cleanup();
// }
// }
//
// Path: measures/src/main/java/org/xbill/DNS/PublicUDPClient.java
// public final class PublicUDPClient implements DNSClient {
// private final UDPClient client;
//
// public PublicUDPClient(long endTime) throws IOException {
// client = new UDPClient(endTime);
// }
//
// @Override
// public void bind(SocketAddress addr) throws IOException {
// client.bind(addr);
// }
//
// @Override
// public void connect(SocketAddress addr) throws IOException {
// client.connect(addr);
// }
//
// @Override
// public void send(byte[] data) throws IOException {
// client.send(data);
// }
//
// @Override
// public byte[] recv(int max) throws IOException {
// return client.recv(max);
// }
//
// @Override
// public void cleanup() throws IOException {
// client.cleanup();
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/Measurement.java
// public abstract class Measurement {
// public final String taskName;
//
// protected Measurement(String taskName) {
// this.taskName = taskName;
// }
//
// /**
// * Ensure that the measurement is asynchronously called in an {@link ExecutorService}.
// *
// * @param callback The {@link MeasurementCallback} used
// * for reporting success or failure of this measurement.
// */
// public final void call(MeasurementCallback callback) {
// AsyncTask.execute(new MeasurementExecutor(this, callback));
// }
//
// /**
// * Actual, synchronous, process of a measurement.
// * This method has to be called from another thread than the UI one.
// *
// * @return The results of this measurement.
// * @throws MeasurementError If anything goes wrong during measurement.
// */
// public abstract MeasurementResult execute() throws MeasurementError;
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
// Path: measures/src/main/java/io/apisense/network/dns/DNSLookupTask.java
import android.support.annotation.NonNull;
import android.util.Log;
import org.xbill.DNS.DClass;
import org.xbill.DNS.DNSClient;
import org.xbill.DNS.Flags;
import org.xbill.DNS.Message;
import org.xbill.DNS.Name;
import org.xbill.DNS.OPTRecord;
import org.xbill.DNS.PublicTCPClient;
import org.xbill.DNS.PublicUDPClient;
import org.xbill.DNS.Record;
import org.xbill.DNS.TextParseException;
import org.xbill.DNS.Type;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import io.apisense.network.Measurement;
import io.apisense.network.MeasurementError;
package io.apisense.network.dns;
/**
* Measures the DNS lookup time
*/
public class DNSLookupTask extends Measurement {
public static final String TAG = "DNSLookup";
private final DNSLookupConfig config;
public DNSLookupTask(DNSLookupConfig config) {
super(TAG);
this.config = config;
}
/**
* Parse the raw response bytes to a wrapped dns answer.
*
* @param useTCP If the client is currently using TCP.
* @param respBytes The raw response bytes.
* @return The parsed {@link Message}.
* @throws MeasurementError If the response could not be parsed.
* @throws TruncatedException If the response is truncated while client is using UDP.
*/
@NonNull
private Message parseMessage(boolean useTCP, byte[] respBytes)
throws TruncatedException, MeasurementError {
Message response;
try {
response = new Message(respBytes);
Log.d(TAG, "Successfully parsed response");
// if the response was truncated, then re-query over TCP
if (!useTCP && response.getHeader().getFlag(Flags.TC)) {
throw new TruncatedException();
}
} catch (IOException e) {
throw new MeasurementError(taskName, "Problem trying to parse dns packet", e);
}
return response;
}
/**
* Initialize and connect the dns TCP or UDP client.
*
* @param server The server to connect the client to.
* @param useTCP Tells if the client should be TCP or UDP.
* @param endTime The request timeout.
* @return The initialized client.
* @throws MeasurementError If any error occurred during client creation or connection.
*/
@NonNull
private DNSClient connectClient(String server, boolean useTCP, long endTime)
throws MeasurementError {
DNSClient client;
try {
if (useTCP) { | client = new PublicTCPClient(endTime); |
APISENSE/android-network-measures | measures/src/main/java/io/apisense/network/dns/DNSLookupTask.java | // Path: measures/src/main/java/org/xbill/DNS/DNSClient.java
// public interface DNSClient {
// void bind(SocketAddress addr) throws IOException;
//
// void connect(SocketAddress addr) throws IOException;
//
// void send(byte[] data) throws IOException;
//
// byte[] recv(int max) throws IOException;
//
// void cleanup() throws IOException;
// }
//
// Path: measures/src/main/java/org/xbill/DNS/PublicTCPClient.java
// public final class PublicTCPClient implements DNSClient {
// private final TCPClient client;
//
// public PublicTCPClient(long endTime) throws IOException {
// client = new TCPClient(endTime);
// }
//
// @Override
// public void bind(SocketAddress addr) throws IOException {
// client.bind(addr);
// }
//
// @Override
// public void connect(SocketAddress addr) throws IOException {
// client.connect(addr);
// }
//
// @Override
// public void send(byte[] data) throws IOException {
// client.send(data);
// }
//
// /**
// * Receive DNS data.
// *
// * @param max Not used in tcp implementation
// * @return The received content.
// * @throws IOException {@inheritDoc}
// */
// @Override
// public byte[] recv(int max) throws IOException {
// return client.recv();
// }
//
// @Override
// public void cleanup() throws IOException {
// client.cleanup();
// }
// }
//
// Path: measures/src/main/java/org/xbill/DNS/PublicUDPClient.java
// public final class PublicUDPClient implements DNSClient {
// private final UDPClient client;
//
// public PublicUDPClient(long endTime) throws IOException {
// client = new UDPClient(endTime);
// }
//
// @Override
// public void bind(SocketAddress addr) throws IOException {
// client.bind(addr);
// }
//
// @Override
// public void connect(SocketAddress addr) throws IOException {
// client.connect(addr);
// }
//
// @Override
// public void send(byte[] data) throws IOException {
// client.send(data);
// }
//
// @Override
// public byte[] recv(int max) throws IOException {
// return client.recv(max);
// }
//
// @Override
// public void cleanup() throws IOException {
// client.cleanup();
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/Measurement.java
// public abstract class Measurement {
// public final String taskName;
//
// protected Measurement(String taskName) {
// this.taskName = taskName;
// }
//
// /**
// * Ensure that the measurement is asynchronously called in an {@link ExecutorService}.
// *
// * @param callback The {@link MeasurementCallback} used
// * for reporting success or failure of this measurement.
// */
// public final void call(MeasurementCallback callback) {
// AsyncTask.execute(new MeasurementExecutor(this, callback));
// }
//
// /**
// * Actual, synchronous, process of a measurement.
// * This method has to be called from another thread than the UI one.
// *
// * @return The results of this measurement.
// * @throws MeasurementError If anything goes wrong during measurement.
// */
// public abstract MeasurementResult execute() throws MeasurementError;
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
| import android.support.annotation.NonNull;
import android.util.Log;
import org.xbill.DNS.DClass;
import org.xbill.DNS.DNSClient;
import org.xbill.DNS.Flags;
import org.xbill.DNS.Message;
import org.xbill.DNS.Name;
import org.xbill.DNS.OPTRecord;
import org.xbill.DNS.PublicTCPClient;
import org.xbill.DNS.PublicUDPClient;
import org.xbill.DNS.Record;
import org.xbill.DNS.TextParseException;
import org.xbill.DNS.Type;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import io.apisense.network.Measurement;
import io.apisense.network.MeasurementError; | try {
response = new Message(respBytes);
Log.d(TAG, "Successfully parsed response");
// if the response was truncated, then re-query over TCP
if (!useTCP && response.getHeader().getFlag(Flags.TC)) {
throw new TruncatedException();
}
} catch (IOException e) {
throw new MeasurementError(taskName, "Problem trying to parse dns packet", e);
}
return response;
}
/**
* Initialize and connect the dns TCP or UDP client.
*
* @param server The server to connect the client to.
* @param useTCP Tells if the client should be TCP or UDP.
* @param endTime The request timeout.
* @return The initialized client.
* @throws MeasurementError If any error occurred during client creation or connection.
*/
@NonNull
private DNSClient connectClient(String server, boolean useTCP, long endTime)
throws MeasurementError {
DNSClient client;
try {
if (useTCP) {
client = new PublicTCPClient(endTime);
} else { | // Path: measures/src/main/java/org/xbill/DNS/DNSClient.java
// public interface DNSClient {
// void bind(SocketAddress addr) throws IOException;
//
// void connect(SocketAddress addr) throws IOException;
//
// void send(byte[] data) throws IOException;
//
// byte[] recv(int max) throws IOException;
//
// void cleanup() throws IOException;
// }
//
// Path: measures/src/main/java/org/xbill/DNS/PublicTCPClient.java
// public final class PublicTCPClient implements DNSClient {
// private final TCPClient client;
//
// public PublicTCPClient(long endTime) throws IOException {
// client = new TCPClient(endTime);
// }
//
// @Override
// public void bind(SocketAddress addr) throws IOException {
// client.bind(addr);
// }
//
// @Override
// public void connect(SocketAddress addr) throws IOException {
// client.connect(addr);
// }
//
// @Override
// public void send(byte[] data) throws IOException {
// client.send(data);
// }
//
// /**
// * Receive DNS data.
// *
// * @param max Not used in tcp implementation
// * @return The received content.
// * @throws IOException {@inheritDoc}
// */
// @Override
// public byte[] recv(int max) throws IOException {
// return client.recv();
// }
//
// @Override
// public void cleanup() throws IOException {
// client.cleanup();
// }
// }
//
// Path: measures/src/main/java/org/xbill/DNS/PublicUDPClient.java
// public final class PublicUDPClient implements DNSClient {
// private final UDPClient client;
//
// public PublicUDPClient(long endTime) throws IOException {
// client = new UDPClient(endTime);
// }
//
// @Override
// public void bind(SocketAddress addr) throws IOException {
// client.bind(addr);
// }
//
// @Override
// public void connect(SocketAddress addr) throws IOException {
// client.connect(addr);
// }
//
// @Override
// public void send(byte[] data) throws IOException {
// client.send(data);
// }
//
// @Override
// public byte[] recv(int max) throws IOException {
// return client.recv(max);
// }
//
// @Override
// public void cleanup() throws IOException {
// client.cleanup();
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/Measurement.java
// public abstract class Measurement {
// public final String taskName;
//
// protected Measurement(String taskName) {
// this.taskName = taskName;
// }
//
// /**
// * Ensure that the measurement is asynchronously called in an {@link ExecutorService}.
// *
// * @param callback The {@link MeasurementCallback} used
// * for reporting success or failure of this measurement.
// */
// public final void call(MeasurementCallback callback) {
// AsyncTask.execute(new MeasurementExecutor(this, callback));
// }
//
// /**
// * Actual, synchronous, process of a measurement.
// * This method has to be called from another thread than the UI one.
// *
// * @return The results of this measurement.
// * @throws MeasurementError If anything goes wrong during measurement.
// */
// public abstract MeasurementResult execute() throws MeasurementError;
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
// Path: measures/src/main/java/io/apisense/network/dns/DNSLookupTask.java
import android.support.annotation.NonNull;
import android.util.Log;
import org.xbill.DNS.DClass;
import org.xbill.DNS.DNSClient;
import org.xbill.DNS.Flags;
import org.xbill.DNS.Message;
import org.xbill.DNS.Name;
import org.xbill.DNS.OPTRecord;
import org.xbill.DNS.PublicTCPClient;
import org.xbill.DNS.PublicUDPClient;
import org.xbill.DNS.Record;
import org.xbill.DNS.TextParseException;
import org.xbill.DNS.Type;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import io.apisense.network.Measurement;
import io.apisense.network.MeasurementError;
try {
response = new Message(respBytes);
Log.d(TAG, "Successfully parsed response");
// if the response was truncated, then re-query over TCP
if (!useTCP && response.getHeader().getFlag(Flags.TC)) {
throw new TruncatedException();
}
} catch (IOException e) {
throw new MeasurementError(taskName, "Problem trying to parse dns packet", e);
}
return response;
}
/**
* Initialize and connect the dns TCP or UDP client.
*
* @param server The server to connect the client to.
* @param useTCP Tells if the client should be TCP or UDP.
* @param endTime The request timeout.
* @return The initialized client.
* @throws MeasurementError If any error occurred during client creation or connection.
*/
@NonNull
private DNSClient connectClient(String server, boolean useTCP, long endTime)
throws MeasurementError {
DNSClient client;
try {
if (useTCP) {
client = new PublicTCPClient(endTime);
} else { | client = new PublicUDPClient(endTime); |
APISENSE/android-network-measures | measures/src/main/java/io/apisense/network/ping/TracerouteTask.java | // Path: measures/src/main/java/io/apisense/network/Measurement.java
// public abstract class Measurement {
// public final String taskName;
//
// protected Measurement(String taskName) {
// this.taskName = taskName;
// }
//
// /**
// * Ensure that the measurement is asynchronously called in an {@link ExecutorService}.
// *
// * @param callback The {@link MeasurementCallback} used
// * for reporting success or failure of this measurement.
// */
// public final void call(MeasurementCallback callback) {
// AsyncTask.execute(new MeasurementExecutor(this, callback));
// }
//
// /**
// * Actual, synchronous, process of a measurement.
// * This method has to be called from another thread than the UI one.
// *
// * @return The results of this measurement.
// * @throws MeasurementError If anything goes wrong during measurement.
// */
// public abstract MeasurementResult execute() throws MeasurementError;
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
// /**
// * Name of the task (ie TCP download, Traceroute, etc)
// */
// private final String taskName;
//
// /**
// * Time of the beginning of the task in milliseconds
// */
// private final long startTime;
//
// /**
// * Time of the end of the task in milliseconds
// */
// private final long endTime;
//
// /**
// * Number of milliseconds representing the duration of the task
// */
// private final long duration;
//
// protected MeasurementResult(String taskName, long startTime, long endTime) {
// this.taskName = taskName;
// this.startTime = startTime;
// this.endTime = endTime;
// this.duration = endTime - startTime;
// }
//
// public String getTaskName() {
// return taskName;
// }
//
// public long getStartTime() {
// return startTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public long getDuration() {
// return duration;
// }
//
// @Override
// public String toString() {
// return "MeasurementResult{" +
// "taskName='" + taskName + '\'' +
// ", startTime=" + startTime +
// ", endTime=" + endTime +
// ", duration=" + duration +
// '}';
// }
// }
| import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import io.apisense.network.Measurement;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult; | package io.apisense.network.ping;
/**
* Measurement class used to realise a Traceroute
*/
public class TracerouteTask extends Measurement {
private static final String TAG = "ICMPTraceroute";
private final TracerouteConfig config;
private String destIp;
private ICMPConfig icmpConfig;
public TracerouteTask(TracerouteConfig tracerouteConfig) {
super(TAG);
this.config = tracerouteConfig;
this.icmpConfig = new ICMPConfig(config.getUrl());
}
@Override | // Path: measures/src/main/java/io/apisense/network/Measurement.java
// public abstract class Measurement {
// public final String taskName;
//
// protected Measurement(String taskName) {
// this.taskName = taskName;
// }
//
// /**
// * Ensure that the measurement is asynchronously called in an {@link ExecutorService}.
// *
// * @param callback The {@link MeasurementCallback} used
// * for reporting success or failure of this measurement.
// */
// public final void call(MeasurementCallback callback) {
// AsyncTask.execute(new MeasurementExecutor(this, callback));
// }
//
// /**
// * Actual, synchronous, process of a measurement.
// * This method has to be called from another thread than the UI one.
// *
// * @return The results of this measurement.
// * @throws MeasurementError If anything goes wrong during measurement.
// */
// public abstract MeasurementResult execute() throws MeasurementError;
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
// /**
// * Name of the task (ie TCP download, Traceroute, etc)
// */
// private final String taskName;
//
// /**
// * Time of the beginning of the task in milliseconds
// */
// private final long startTime;
//
// /**
// * Time of the end of the task in milliseconds
// */
// private final long endTime;
//
// /**
// * Number of milliseconds representing the duration of the task
// */
// private final long duration;
//
// protected MeasurementResult(String taskName, long startTime, long endTime) {
// this.taskName = taskName;
// this.startTime = startTime;
// this.endTime = endTime;
// this.duration = endTime - startTime;
// }
//
// public String getTaskName() {
// return taskName;
// }
//
// public long getStartTime() {
// return startTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public long getDuration() {
// return duration;
// }
//
// @Override
// public String toString() {
// return "MeasurementResult{" +
// "taskName='" + taskName + '\'' +
// ", startTime=" + startTime +
// ", endTime=" + endTime +
// ", duration=" + duration +
// '}';
// }
// }
// Path: measures/src/main/java/io/apisense/network/ping/TracerouteTask.java
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import io.apisense.network.Measurement;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult;
package io.apisense.network.ping;
/**
* Measurement class used to realise a Traceroute
*/
public class TracerouteTask extends Measurement {
private static final String TAG = "ICMPTraceroute";
private final TracerouteConfig config;
private String destIp;
private ICMPConfig icmpConfig;
public TracerouteTask(TracerouteConfig tracerouteConfig) {
super(TAG);
this.config = tracerouteConfig;
this.icmpConfig = new ICMPConfig(config.getUrl());
}
@Override | public MeasurementResult execute() throws MeasurementError { |
APISENSE/android-network-measures | measures/src/main/java/io/apisense/network/ping/TracerouteTask.java | // Path: measures/src/main/java/io/apisense/network/Measurement.java
// public abstract class Measurement {
// public final String taskName;
//
// protected Measurement(String taskName) {
// this.taskName = taskName;
// }
//
// /**
// * Ensure that the measurement is asynchronously called in an {@link ExecutorService}.
// *
// * @param callback The {@link MeasurementCallback} used
// * for reporting success or failure of this measurement.
// */
// public final void call(MeasurementCallback callback) {
// AsyncTask.execute(new MeasurementExecutor(this, callback));
// }
//
// /**
// * Actual, synchronous, process of a measurement.
// * This method has to be called from another thread than the UI one.
// *
// * @return The results of this measurement.
// * @throws MeasurementError If anything goes wrong during measurement.
// */
// public abstract MeasurementResult execute() throws MeasurementError;
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
// /**
// * Name of the task (ie TCP download, Traceroute, etc)
// */
// private final String taskName;
//
// /**
// * Time of the beginning of the task in milliseconds
// */
// private final long startTime;
//
// /**
// * Time of the end of the task in milliseconds
// */
// private final long endTime;
//
// /**
// * Number of milliseconds representing the duration of the task
// */
// private final long duration;
//
// protected MeasurementResult(String taskName, long startTime, long endTime) {
// this.taskName = taskName;
// this.startTime = startTime;
// this.endTime = endTime;
// this.duration = endTime - startTime;
// }
//
// public String getTaskName() {
// return taskName;
// }
//
// public long getStartTime() {
// return startTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public long getDuration() {
// return duration;
// }
//
// @Override
// public String toString() {
// return "MeasurementResult{" +
// "taskName='" + taskName + '\'' +
// ", startTime=" + startTime +
// ", endTime=" + endTime +
// ", duration=" + duration +
// '}';
// }
// }
| import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import io.apisense.network.Measurement;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult; | package io.apisense.network.ping;
/**
* Measurement class used to realise a Traceroute
*/
public class TracerouteTask extends Measurement {
private static final String TAG = "ICMPTraceroute";
private final TracerouteConfig config;
private String destIp;
private ICMPConfig icmpConfig;
public TracerouteTask(TracerouteConfig tracerouteConfig) {
super(TAG);
this.config = tracerouteConfig;
this.icmpConfig = new ICMPConfig(config.getUrl());
}
@Override | // Path: measures/src/main/java/io/apisense/network/Measurement.java
// public abstract class Measurement {
// public final String taskName;
//
// protected Measurement(String taskName) {
// this.taskName = taskName;
// }
//
// /**
// * Ensure that the measurement is asynchronously called in an {@link ExecutorService}.
// *
// * @param callback The {@link MeasurementCallback} used
// * for reporting success or failure of this measurement.
// */
// public final void call(MeasurementCallback callback) {
// AsyncTask.execute(new MeasurementExecutor(this, callback));
// }
//
// /**
// * Actual, synchronous, process of a measurement.
// * This method has to be called from another thread than the UI one.
// *
// * @return The results of this measurement.
// * @throws MeasurementError If anything goes wrong during measurement.
// */
// public abstract MeasurementResult execute() throws MeasurementError;
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
// /**
// * Name of the task (ie TCP download, Traceroute, etc)
// */
// private final String taskName;
//
// /**
// * Time of the beginning of the task in milliseconds
// */
// private final long startTime;
//
// /**
// * Time of the end of the task in milliseconds
// */
// private final long endTime;
//
// /**
// * Number of milliseconds representing the duration of the task
// */
// private final long duration;
//
// protected MeasurementResult(String taskName, long startTime, long endTime) {
// this.taskName = taskName;
// this.startTime = startTime;
// this.endTime = endTime;
// this.duration = endTime - startTime;
// }
//
// public String getTaskName() {
// return taskName;
// }
//
// public long getStartTime() {
// return startTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public long getDuration() {
// return duration;
// }
//
// @Override
// public String toString() {
// return "MeasurementResult{" +
// "taskName='" + taskName + '\'' +
// ", startTime=" + startTime +
// ", endTime=" + endTime +
// ", duration=" + duration +
// '}';
// }
// }
// Path: measures/src/main/java/io/apisense/network/ping/TracerouteTask.java
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import io.apisense.network.Measurement;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult;
package io.apisense.network.ping;
/**
* Measurement class used to realise a Traceroute
*/
public class TracerouteTask extends Measurement {
private static final String TAG = "ICMPTraceroute";
private final TracerouteConfig config;
private String destIp;
private ICMPConfig icmpConfig;
public TracerouteTask(TracerouteConfig tracerouteConfig) {
super(TAG);
this.config = tracerouteConfig;
this.icmpConfig = new ICMPConfig(config.getUrl());
}
@Override | public MeasurementResult execute() throws MeasurementError { |
APISENSE/android-network-measures | measures/src/main/java/io/apisense/network/tcp/TCPUploadTask.java | // Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
// /**
// * Name of the task (ie TCP download, Traceroute, etc)
// */
// private final String taskName;
//
// /**
// * Time of the beginning of the task in milliseconds
// */
// private final long startTime;
//
// /**
// * Time of the end of the task in milliseconds
// */
// private final long endTime;
//
// /**
// * Number of milliseconds representing the duration of the task
// */
// private final long duration;
//
// protected MeasurementResult(String taskName, long startTime, long endTime) {
// this.taskName = taskName;
// this.startTime = startTime;
// this.endTime = endTime;
// this.duration = endTime - startTime;
// }
//
// public String getTaskName() {
// return taskName;
// }
//
// public long getStartTime() {
// return startTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public long getDuration() {
// return duration;
// }
//
// @Override
// public String toString() {
// return "MeasurementResult{" +
// "taskName='" + taskName + '\'' +
// ", startTime=" + startTime +
// ", endTime=" + endTime +
// ", duration=" + duration +
// '}';
// }
// }
| import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult; | package io.apisense.network.tcp;
/**
* Measurement class used to realise an TCP upload test
*/
public class TCPUploadTask extends TCPThroughputTask {
private static final String TAG = "TCPUploadTask";
private static final int PORT_UPLINK = 6002;
private static final String UPLINK_FINISH_MSG = "*";
private static final long MB_TO_B = 1048576;
public TCPUploadTask(TCPThroughputConfig tcpThroughputConfig) {
super(TAG, tcpThroughputConfig);
}
/**
* {@inheritDoc}
*
* @return A {@link TCPThroughputResult} object containing information on the TCP upload test.
* @throws MeasurementError {@inheritDoc}
*/ | // Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
// /**
// * Name of the task (ie TCP download, Traceroute, etc)
// */
// private final String taskName;
//
// /**
// * Time of the beginning of the task in milliseconds
// */
// private final long startTime;
//
// /**
// * Time of the end of the task in milliseconds
// */
// private final long endTime;
//
// /**
// * Number of milliseconds representing the duration of the task
// */
// private final long duration;
//
// protected MeasurementResult(String taskName, long startTime, long endTime) {
// this.taskName = taskName;
// this.startTime = startTime;
// this.endTime = endTime;
// this.duration = endTime - startTime;
// }
//
// public String getTaskName() {
// return taskName;
// }
//
// public long getStartTime() {
// return startTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public long getDuration() {
// return duration;
// }
//
// @Override
// public String toString() {
// return "MeasurementResult{" +
// "taskName='" + taskName + '\'' +
// ", startTime=" + startTime +
// ", endTime=" + endTime +
// ", duration=" + duration +
// '}';
// }
// }
// Path: measures/src/main/java/io/apisense/network/tcp/TCPUploadTask.java
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult;
package io.apisense.network.tcp;
/**
* Measurement class used to realise an TCP upload test
*/
public class TCPUploadTask extends TCPThroughputTask {
private static final String TAG = "TCPUploadTask";
private static final int PORT_UPLINK = 6002;
private static final String UPLINK_FINISH_MSG = "*";
private static final long MB_TO_B = 1048576;
public TCPUploadTask(TCPThroughputConfig tcpThroughputConfig) {
super(TAG, tcpThroughputConfig);
}
/**
* {@inheritDoc}
*
* @return A {@link TCPThroughputResult} object containing information on the TCP upload test.
* @throws MeasurementError {@inheritDoc}
*/ | public MeasurementResult execute() throws MeasurementError { |
APISENSE/android-network-measures | measures/src/main/java/io/apisense/network/tcp/TCPUploadTask.java | // Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
// /**
// * Name of the task (ie TCP download, Traceroute, etc)
// */
// private final String taskName;
//
// /**
// * Time of the beginning of the task in milliseconds
// */
// private final long startTime;
//
// /**
// * Time of the end of the task in milliseconds
// */
// private final long endTime;
//
// /**
// * Number of milliseconds representing the duration of the task
// */
// private final long duration;
//
// protected MeasurementResult(String taskName, long startTime, long endTime) {
// this.taskName = taskName;
// this.startTime = startTime;
// this.endTime = endTime;
// this.duration = endTime - startTime;
// }
//
// public String getTaskName() {
// return taskName;
// }
//
// public long getStartTime() {
// return startTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public long getDuration() {
// return duration;
// }
//
// @Override
// public String toString() {
// return "MeasurementResult{" +
// "taskName='" + taskName + '\'' +
// ", startTime=" + startTime +
// ", endTime=" + endTime +
// ", duration=" + duration +
// '}';
// }
// }
| import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult; | package io.apisense.network.tcp;
/**
* Measurement class used to realise an TCP upload test
*/
public class TCPUploadTask extends TCPThroughputTask {
private static final String TAG = "TCPUploadTask";
private static final int PORT_UPLINK = 6002;
private static final String UPLINK_FINISH_MSG = "*";
private static final long MB_TO_B = 1048576;
public TCPUploadTask(TCPThroughputConfig tcpThroughputConfig) {
super(TAG, tcpThroughputConfig);
}
/**
* {@inheritDoc}
*
* @return A {@link TCPThroughputResult} object containing information on the TCP upload test.
* @throws MeasurementError {@inheritDoc}
*/ | // Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
// /**
// * Name of the task (ie TCP download, Traceroute, etc)
// */
// private final String taskName;
//
// /**
// * Time of the beginning of the task in milliseconds
// */
// private final long startTime;
//
// /**
// * Time of the end of the task in milliseconds
// */
// private final long endTime;
//
// /**
// * Number of milliseconds representing the duration of the task
// */
// private final long duration;
//
// protected MeasurementResult(String taskName, long startTime, long endTime) {
// this.taskName = taskName;
// this.startTime = startTime;
// this.endTime = endTime;
// this.duration = endTime - startTime;
// }
//
// public String getTaskName() {
// return taskName;
// }
//
// public long getStartTime() {
// return startTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public long getDuration() {
// return duration;
// }
//
// @Override
// public String toString() {
// return "MeasurementResult{" +
// "taskName='" + taskName + '\'' +
// ", startTime=" + startTime +
// ", endTime=" + endTime +
// ", duration=" + duration +
// '}';
// }
// }
// Path: measures/src/main/java/io/apisense/network/tcp/TCPUploadTask.java
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.Socket;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult;
package io.apisense.network.tcp;
/**
* Measurement class used to realise an TCP upload test
*/
public class TCPUploadTask extends TCPThroughputTask {
private static final String TAG = "TCPUploadTask";
private static final int PORT_UPLINK = 6002;
private static final String UPLINK_FINISH_MSG = "*";
private static final long MB_TO_B = 1048576;
public TCPUploadTask(TCPThroughputConfig tcpThroughputConfig) {
super(TAG, tcpThroughputConfig);
}
/**
* {@inheritDoc}
*
* @return A {@link TCPThroughputResult} object containing information on the TCP upload test.
* @throws MeasurementError {@inheritDoc}
*/ | public MeasurementResult execute() throws MeasurementError { |
APISENSE/android-network-measures | measures/src/main/java/io/apisense/network/udp/UDPUploadBurstTask.java | // Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
// /**
// * Name of the task (ie TCP download, Traceroute, etc)
// */
// private final String taskName;
//
// /**
// * Time of the beginning of the task in milliseconds
// */
// private final long startTime;
//
// /**
// * Time of the end of the task in milliseconds
// */
// private final long endTime;
//
// /**
// * Number of milliseconds representing the duration of the task
// */
// private final long duration;
//
// protected MeasurementResult(String taskName, long startTime, long endTime) {
// this.taskName = taskName;
// this.startTime = startTime;
// this.endTime = endTime;
// this.duration = endTime - startTime;
// }
//
// public String getTaskName() {
// return taskName;
// }
//
// public long getStartTime() {
// return startTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public long getDuration() {
// return duration;
// }
//
// @Override
// public String toString() {
// return "MeasurementResult{" +
// "taskName='" + taskName + '\'' +
// ", startTime=" + startTime +
// ", endTime=" + endTime +
// ", duration=" + duration +
// '}';
// }
// }
| import android.support.annotation.NonNull;
import android.util.Log;
import java.io.IOException;
import java.net.DatagramSocket;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult; | package io.apisense.network.udp;
/**
* Measurement class used to realise an UDP upload burst
* Measures the jitter, the jitter, the loss, and the number of out of order packets in upload
*/
public class UDPUploadBurstTask extends UDPBurstTask {
private static final String TAG = "UDPUploadBurst";
public UDPUploadBurstTask(UDPBurstConfig udpBurstConfig) {
super(TAG, udpBurstConfig);
}
/**
* {@inheritDoc}
*
* @return A {@link UDPBurstResult} object containing information on the UDP upload burst.
* @throws MeasurementError {@inheritDoc}
*/ | // Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
// /**
// * Name of the task (ie TCP download, Traceroute, etc)
// */
// private final String taskName;
//
// /**
// * Time of the beginning of the task in milliseconds
// */
// private final long startTime;
//
// /**
// * Time of the end of the task in milliseconds
// */
// private final long endTime;
//
// /**
// * Number of milliseconds representing the duration of the task
// */
// private final long duration;
//
// protected MeasurementResult(String taskName, long startTime, long endTime) {
// this.taskName = taskName;
// this.startTime = startTime;
// this.endTime = endTime;
// this.duration = endTime - startTime;
// }
//
// public String getTaskName() {
// return taskName;
// }
//
// public long getStartTime() {
// return startTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public long getDuration() {
// return duration;
// }
//
// @Override
// public String toString() {
// return "MeasurementResult{" +
// "taskName='" + taskName + '\'' +
// ", startTime=" + startTime +
// ", endTime=" + endTime +
// ", duration=" + duration +
// '}';
// }
// }
// Path: measures/src/main/java/io/apisense/network/udp/UDPUploadBurstTask.java
import android.support.annotation.NonNull;
import android.util.Log;
import java.io.IOException;
import java.net.DatagramSocket;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult;
package io.apisense.network.udp;
/**
* Measurement class used to realise an UDP upload burst
* Measures the jitter, the jitter, the loss, and the number of out of order packets in upload
*/
public class UDPUploadBurstTask extends UDPBurstTask {
private static final String TAG = "UDPUploadBurst";
public UDPUploadBurstTask(UDPBurstConfig udpBurstConfig) {
super(TAG, udpBurstConfig);
}
/**
* {@inheritDoc}
*
* @return A {@link UDPBurstResult} object containing information on the UDP upload burst.
* @throws MeasurementError {@inheritDoc}
*/ | public MeasurementResult execute() throws MeasurementError { |
APISENSE/android-network-measures | measures/src/main/java/io/apisense/network/udp/UDPUploadBurstTask.java | // Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
// /**
// * Name of the task (ie TCP download, Traceroute, etc)
// */
// private final String taskName;
//
// /**
// * Time of the beginning of the task in milliseconds
// */
// private final long startTime;
//
// /**
// * Time of the end of the task in milliseconds
// */
// private final long endTime;
//
// /**
// * Number of milliseconds representing the duration of the task
// */
// private final long duration;
//
// protected MeasurementResult(String taskName, long startTime, long endTime) {
// this.taskName = taskName;
// this.startTime = startTime;
// this.endTime = endTime;
// this.duration = endTime - startTime;
// }
//
// public String getTaskName() {
// return taskName;
// }
//
// public long getStartTime() {
// return startTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public long getDuration() {
// return duration;
// }
//
// @Override
// public String toString() {
// return "MeasurementResult{" +
// "taskName='" + taskName + '\'' +
// ", startTime=" + startTime +
// ", endTime=" + endTime +
// ", duration=" + duration +
// '}';
// }
// }
| import android.support.annotation.NonNull;
import android.util.Log;
import java.io.IOException;
import java.net.DatagramSocket;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult; | package io.apisense.network.udp;
/**
* Measurement class used to realise an UDP upload burst
* Measures the jitter, the jitter, the loss, and the number of out of order packets in upload
*/
public class UDPUploadBurstTask extends UDPBurstTask {
private static final String TAG = "UDPUploadBurst";
public UDPUploadBurstTask(UDPBurstConfig udpBurstConfig) {
super(TAG, udpBurstConfig);
}
/**
* {@inheritDoc}
*
* @return A {@link UDPBurstResult} object containing information on the UDP upload burst.
* @throws MeasurementError {@inheritDoc}
*/ | // Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
// /**
// * Name of the task (ie TCP download, Traceroute, etc)
// */
// private final String taskName;
//
// /**
// * Time of the beginning of the task in milliseconds
// */
// private final long startTime;
//
// /**
// * Time of the end of the task in milliseconds
// */
// private final long endTime;
//
// /**
// * Number of milliseconds representing the duration of the task
// */
// private final long duration;
//
// protected MeasurementResult(String taskName, long startTime, long endTime) {
// this.taskName = taskName;
// this.startTime = startTime;
// this.endTime = endTime;
// this.duration = endTime - startTime;
// }
//
// public String getTaskName() {
// return taskName;
// }
//
// public long getStartTime() {
// return startTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public long getDuration() {
// return duration;
// }
//
// @Override
// public String toString() {
// return "MeasurementResult{" +
// "taskName='" + taskName + '\'' +
// ", startTime=" + startTime +
// ", endTime=" + endTime +
// ", duration=" + duration +
// '}';
// }
// }
// Path: measures/src/main/java/io/apisense/network/udp/UDPUploadBurstTask.java
import android.support.annotation.NonNull;
import android.util.Log;
import java.io.IOException;
import java.net.DatagramSocket;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult;
package io.apisense.network.udp;
/**
* Measurement class used to realise an UDP upload burst
* Measures the jitter, the jitter, the loss, and the number of out of order packets in upload
*/
public class UDPUploadBurstTask extends UDPBurstTask {
private static final String TAG = "UDPUploadBurst";
public UDPUploadBurstTask(UDPBurstConfig udpBurstConfig) {
super(TAG, udpBurstConfig);
}
/**
* {@inheritDoc}
*
* @return A {@link UDPBurstResult} object containing information on the UDP upload burst.
* @throws MeasurementError {@inheritDoc}
*/ | public MeasurementResult execute() throws MeasurementError { |
APISENSE/android-network-measures | measures/src/main/java/io/apisense/network/udp/UDPPacket.java | // Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
| import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import io.apisense.network.MeasurementError; | package io.apisense.network.udp;
/**
* @author Hongyi Yao (hyyao@umich.edu) A helper structure for packing and unpacking network
* message
*/
final class UDPPacket {
static final int PKT_ERROR = 1;
static final int PKT_RESPONSE = 2;
static final int PKT_DATA = 3;
static final int PKT_REQUEST = 4;
/**
* Name of the task to referecence in case of a {@link MeasurementError}.
*/
private final String taskName;
/**
* Type of the {@link UDPPacket},
* may be {@link UDPPacket#PKT_ERROR}, {@link UDPPacket#PKT_RESPONSE},
* {@link UDPPacket#PKT_DATA}, or {@link UDPPacket#PKT_REQUEST}
*/
public final int type;
/**
* Number of burst to send.
*/
public final int burstCount;
/**
* Number of packet received in a wrong order
*/
public final int outOfOrderNum;
/**
* Data packet: local timestamp
* Response packet: jitter
*/
public final long timestamp;
/**
* Size of each UDP packet to send.
*/
public final int packetSize;
/**
* Request sequence number.
*/
public final int seq;
/**
* Time to wait between each packet.
*/
public final int udpInterval;
/**
* Identification of the packet,
* determine its order in the sequence.
*/
public int packetNum;
/**
* Build from scratch an {@link UDPPacket} from the given configuration.
*
* @param taskName Name of the task to referecence in case of a {@link MeasurementError}
* @param type Type of packet to build.
* @param config Burst configuration to set in the packet.
*/
public UDPPacket(String taskName, int type, UDPBurstConfig config) {
this.taskName = taskName;
this.type = type;
this.burstCount = config.getUdpBurstCount();
this.packetSize = config.getPacketSizeByte();
this.udpInterval = (int) Math.ceil(config.getUdpInterval() / 1000); // convert µs to ms
this.seq = 0;
// Unrelevant properties
outOfOrderNum = 0;
timestamp = System.currentTimeMillis();
}
/**
* Unpack received message and fill the structure
*
* @param taskName Name of the task to referecence in case of a {@link MeasurementError}
* @param rawdata Network message
* @throws MeasurementError stream reader failed
*/ | // Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
// Path: measures/src/main/java/io/apisense/network/udp/UDPPacket.java
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import io.apisense.network.MeasurementError;
package io.apisense.network.udp;
/**
* @author Hongyi Yao (hyyao@umich.edu) A helper structure for packing and unpacking network
* message
*/
final class UDPPacket {
static final int PKT_ERROR = 1;
static final int PKT_RESPONSE = 2;
static final int PKT_DATA = 3;
static final int PKT_REQUEST = 4;
/**
* Name of the task to referecence in case of a {@link MeasurementError}.
*/
private final String taskName;
/**
* Type of the {@link UDPPacket},
* may be {@link UDPPacket#PKT_ERROR}, {@link UDPPacket#PKT_RESPONSE},
* {@link UDPPacket#PKT_DATA}, or {@link UDPPacket#PKT_REQUEST}
*/
public final int type;
/**
* Number of burst to send.
*/
public final int burstCount;
/**
* Number of packet received in a wrong order
*/
public final int outOfOrderNum;
/**
* Data packet: local timestamp
* Response packet: jitter
*/
public final long timestamp;
/**
* Size of each UDP packet to send.
*/
public final int packetSize;
/**
* Request sequence number.
*/
public final int seq;
/**
* Time to wait between each packet.
*/
public final int udpInterval;
/**
* Identification of the packet,
* determine its order in the sequence.
*/
public int packetNum;
/**
* Build from scratch an {@link UDPPacket} from the given configuration.
*
* @param taskName Name of the task to referecence in case of a {@link MeasurementError}
* @param type Type of packet to build.
* @param config Burst configuration to set in the packet.
*/
public UDPPacket(String taskName, int type, UDPBurstConfig config) {
this.taskName = taskName;
this.type = type;
this.burstCount = config.getUdpBurstCount();
this.packetSize = config.getPacketSizeByte();
this.udpInterval = (int) Math.ceil(config.getUdpInterval() / 1000); // convert µs to ms
this.seq = 0;
// Unrelevant properties
outOfOrderNum = 0;
timestamp = System.currentTimeMillis();
}
/**
* Unpack received message and fill the structure
*
* @param taskName Name of the task to referecence in case of a {@link MeasurementError}
* @param rawdata Network message
* @throws MeasurementError stream reader failed
*/ | public UDPPacket(String taskName, byte[] rawdata) throws MeasurementError { |
APISENSE/android-network-measures | measures/src/main/java/io/apisense/network/tcp/TCPDownloadTask.java | // Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
// /**
// * Name of the task (ie TCP download, Traceroute, etc)
// */
// private final String taskName;
//
// /**
// * Time of the beginning of the task in milliseconds
// */
// private final long startTime;
//
// /**
// * Time of the end of the task in milliseconds
// */
// private final long endTime;
//
// /**
// * Number of milliseconds representing the duration of the task
// */
// private final long duration;
//
// protected MeasurementResult(String taskName, long startTime, long endTime) {
// this.taskName = taskName;
// this.startTime = startTime;
// this.endTime = endTime;
// this.duration = endTime - startTime;
// }
//
// public String getTaskName() {
// return taskName;
// }
//
// public long getStartTime() {
// return startTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public long getDuration() {
// return duration;
// }
//
// @Override
// public String toString() {
// return "MeasurementResult{" +
// "taskName='" + taskName + '\'' +
// ", startTime=" + startTime +
// ", endTime=" + endTime +
// ", duration=" + duration +
// '}';
// }
// }
| import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult; | package io.apisense.network.tcp;
/**
* Measurement class used to realise an TCP download test
*/
public class TCPDownloadTask extends TCPThroughputTask {
private static final String TAG = "TCPDownloadTask";
private static final int PORT_DOWNLINK = 6001;
public TCPDownloadTask(TCPThroughputConfig tcpThroughputConfig) {
super(TAG, tcpThroughputConfig);
}
/**
* {@inheritDoc}
*
* @return A {@link TCPThroughputResult} object containing information on the TCP download test.
* @throws MeasurementError {@inheritDoc}
*/ | // Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
// /**
// * Name of the task (ie TCP download, Traceroute, etc)
// */
// private final String taskName;
//
// /**
// * Time of the beginning of the task in milliseconds
// */
// private final long startTime;
//
// /**
// * Time of the end of the task in milliseconds
// */
// private final long endTime;
//
// /**
// * Number of milliseconds representing the duration of the task
// */
// private final long duration;
//
// protected MeasurementResult(String taskName, long startTime, long endTime) {
// this.taskName = taskName;
// this.startTime = startTime;
// this.endTime = endTime;
// this.duration = endTime - startTime;
// }
//
// public String getTaskName() {
// return taskName;
// }
//
// public long getStartTime() {
// return startTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public long getDuration() {
// return duration;
// }
//
// @Override
// public String toString() {
// return "MeasurementResult{" +
// "taskName='" + taskName + '\'' +
// ", startTime=" + startTime +
// ", endTime=" + endTime +
// ", duration=" + duration +
// '}';
// }
// }
// Path: measures/src/main/java/io/apisense/network/tcp/TCPDownloadTask.java
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult;
package io.apisense.network.tcp;
/**
* Measurement class used to realise an TCP download test
*/
public class TCPDownloadTask extends TCPThroughputTask {
private static final String TAG = "TCPDownloadTask";
private static final int PORT_DOWNLINK = 6001;
public TCPDownloadTask(TCPThroughputConfig tcpThroughputConfig) {
super(TAG, tcpThroughputConfig);
}
/**
* {@inheritDoc}
*
* @return A {@link TCPThroughputResult} object containing information on the TCP download test.
* @throws MeasurementError {@inheritDoc}
*/ | public MeasurementResult execute() throws MeasurementError { |
APISENSE/android-network-measures | measures/src/main/java/io/apisense/network/tcp/TCPDownloadTask.java | // Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
// /**
// * Name of the task (ie TCP download, Traceroute, etc)
// */
// private final String taskName;
//
// /**
// * Time of the beginning of the task in milliseconds
// */
// private final long startTime;
//
// /**
// * Time of the end of the task in milliseconds
// */
// private final long endTime;
//
// /**
// * Number of milliseconds representing the duration of the task
// */
// private final long duration;
//
// protected MeasurementResult(String taskName, long startTime, long endTime) {
// this.taskName = taskName;
// this.startTime = startTime;
// this.endTime = endTime;
// this.duration = endTime - startTime;
// }
//
// public String getTaskName() {
// return taskName;
// }
//
// public long getStartTime() {
// return startTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public long getDuration() {
// return duration;
// }
//
// @Override
// public String toString() {
// return "MeasurementResult{" +
// "taskName='" + taskName + '\'' +
// ", startTime=" + startTime +
// ", endTime=" + endTime +
// ", duration=" + duration +
// '}';
// }
// }
| import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult; | package io.apisense.network.tcp;
/**
* Measurement class used to realise an TCP download test
*/
public class TCPDownloadTask extends TCPThroughputTask {
private static final String TAG = "TCPDownloadTask";
private static final int PORT_DOWNLINK = 6001;
public TCPDownloadTask(TCPThroughputConfig tcpThroughputConfig) {
super(TAG, tcpThroughputConfig);
}
/**
* {@inheritDoc}
*
* @return A {@link TCPThroughputResult} object containing information on the TCP download test.
* @throws MeasurementError {@inheritDoc}
*/ | // Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
// /**
// * Name of the task (ie TCP download, Traceroute, etc)
// */
// private final String taskName;
//
// /**
// * Time of the beginning of the task in milliseconds
// */
// private final long startTime;
//
// /**
// * Time of the end of the task in milliseconds
// */
// private final long endTime;
//
// /**
// * Number of milliseconds representing the duration of the task
// */
// private final long duration;
//
// protected MeasurementResult(String taskName, long startTime, long endTime) {
// this.taskName = taskName;
// this.startTime = startTime;
// this.endTime = endTime;
// this.duration = endTime - startTime;
// }
//
// public String getTaskName() {
// return taskName;
// }
//
// public long getStartTime() {
// return startTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public long getDuration() {
// return duration;
// }
//
// @Override
// public String toString() {
// return "MeasurementResult{" +
// "taskName='" + taskName + '\'' +
// ", startTime=" + startTime +
// ", endTime=" + endTime +
// ", duration=" + duration +
// '}';
// }
// }
// Path: measures/src/main/java/io/apisense/network/tcp/TCPDownloadTask.java
import android.util.Log;
import java.io.IOException;
import java.io.InputStream;
import java.net.Socket;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult;
package io.apisense.network.tcp;
/**
* Measurement class used to realise an TCP download test
*/
public class TCPDownloadTask extends TCPThroughputTask {
private static final String TAG = "TCPDownloadTask";
private static final int PORT_DOWNLINK = 6001;
public TCPDownloadTask(TCPThroughputConfig tcpThroughputConfig) {
super(TAG, tcpThroughputConfig);
}
/**
* {@inheritDoc}
*
* @return A {@link TCPThroughputResult} object containing information on the TCP download test.
* @throws MeasurementError {@inheritDoc}
*/ | public MeasurementResult execute() throws MeasurementError { |
APISENSE/android-network-measures | measures/src/main/java/io/apisense/network/udp/UDPDownloadBurstTask.java | // Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
// /**
// * Name of the task (ie TCP download, Traceroute, etc)
// */
// private final String taskName;
//
// /**
// * Time of the beginning of the task in milliseconds
// */
// private final long startTime;
//
// /**
// * Time of the end of the task in milliseconds
// */
// private final long endTime;
//
// /**
// * Number of milliseconds representing the duration of the task
// */
// private final long duration;
//
// protected MeasurementResult(String taskName, long startTime, long endTime) {
// this.taskName = taskName;
// this.startTime = startTime;
// this.endTime = endTime;
// this.duration = endTime - startTime;
// }
//
// public String getTaskName() {
// return taskName;
// }
//
// public long getStartTime() {
// return startTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public long getDuration() {
// return duration;
// }
//
// @Override
// public String toString() {
// return "MeasurementResult{" +
// "taskName='" + taskName + '\'' +
// ", startTime=" + startTime +
// ", endTime=" + endTime +
// ", duration=" + duration +
// '}';
// }
// }
| import android.util.Log;
import java.io.IOException;
import java.net.DatagramSocket;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult; | package io.apisense.network.udp;
/**
* Measurement class used to realise an UDP download burst
* Measures the jitter, the jitter, the loss, and the number of out of order packets in download
*/
public class UDPDownloadBurstTask extends UDPBurstTask {
public static final String TAG = "UDPDownloadBurst";
public UDPDownloadBurstTask(UDPBurstConfig udpBurstConfig) {
super(TAG, udpBurstConfig);
}
/**
* {@inheritDoc}
*
* @return A {@link UDPBurstResult} object containing information on the UDP download burst.
* @throws MeasurementError {@inheritDoc}
*/ | // Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
// /**
// * Name of the task (ie TCP download, Traceroute, etc)
// */
// private final String taskName;
//
// /**
// * Time of the beginning of the task in milliseconds
// */
// private final long startTime;
//
// /**
// * Time of the end of the task in milliseconds
// */
// private final long endTime;
//
// /**
// * Number of milliseconds representing the duration of the task
// */
// private final long duration;
//
// protected MeasurementResult(String taskName, long startTime, long endTime) {
// this.taskName = taskName;
// this.startTime = startTime;
// this.endTime = endTime;
// this.duration = endTime - startTime;
// }
//
// public String getTaskName() {
// return taskName;
// }
//
// public long getStartTime() {
// return startTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public long getDuration() {
// return duration;
// }
//
// @Override
// public String toString() {
// return "MeasurementResult{" +
// "taskName='" + taskName + '\'' +
// ", startTime=" + startTime +
// ", endTime=" + endTime +
// ", duration=" + duration +
// '}';
// }
// }
// Path: measures/src/main/java/io/apisense/network/udp/UDPDownloadBurstTask.java
import android.util.Log;
import java.io.IOException;
import java.net.DatagramSocket;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult;
package io.apisense.network.udp;
/**
* Measurement class used to realise an UDP download burst
* Measures the jitter, the jitter, the loss, and the number of out of order packets in download
*/
public class UDPDownloadBurstTask extends UDPBurstTask {
public static final String TAG = "UDPDownloadBurst";
public UDPDownloadBurstTask(UDPBurstConfig udpBurstConfig) {
super(TAG, udpBurstConfig);
}
/**
* {@inheritDoc}
*
* @return A {@link UDPBurstResult} object containing information on the UDP download burst.
* @throws MeasurementError {@inheritDoc}
*/ | public MeasurementResult execute() throws MeasurementError { |
APISENSE/android-network-measures | measures/src/main/java/io/apisense/network/udp/UDPDownloadBurstTask.java | // Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
// /**
// * Name of the task (ie TCP download, Traceroute, etc)
// */
// private final String taskName;
//
// /**
// * Time of the beginning of the task in milliseconds
// */
// private final long startTime;
//
// /**
// * Time of the end of the task in milliseconds
// */
// private final long endTime;
//
// /**
// * Number of milliseconds representing the duration of the task
// */
// private final long duration;
//
// protected MeasurementResult(String taskName, long startTime, long endTime) {
// this.taskName = taskName;
// this.startTime = startTime;
// this.endTime = endTime;
// this.duration = endTime - startTime;
// }
//
// public String getTaskName() {
// return taskName;
// }
//
// public long getStartTime() {
// return startTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public long getDuration() {
// return duration;
// }
//
// @Override
// public String toString() {
// return "MeasurementResult{" +
// "taskName='" + taskName + '\'' +
// ", startTime=" + startTime +
// ", endTime=" + endTime +
// ", duration=" + duration +
// '}';
// }
// }
| import android.util.Log;
import java.io.IOException;
import java.net.DatagramSocket;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult; | package io.apisense.network.udp;
/**
* Measurement class used to realise an UDP download burst
* Measures the jitter, the jitter, the loss, and the number of out of order packets in download
*/
public class UDPDownloadBurstTask extends UDPBurstTask {
public static final String TAG = "UDPDownloadBurst";
public UDPDownloadBurstTask(UDPBurstConfig udpBurstConfig) {
super(TAG, udpBurstConfig);
}
/**
* {@inheritDoc}
*
* @return A {@link UDPBurstResult} object containing information on the UDP download burst.
* @throws MeasurementError {@inheritDoc}
*/ | // Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementResult.java
// public abstract class MeasurementResult {
// /**
// * Name of the task (ie TCP download, Traceroute, etc)
// */
// private final String taskName;
//
// /**
// * Time of the beginning of the task in milliseconds
// */
// private final long startTime;
//
// /**
// * Time of the end of the task in milliseconds
// */
// private final long endTime;
//
// /**
// * Number of milliseconds representing the duration of the task
// */
// private final long duration;
//
// protected MeasurementResult(String taskName, long startTime, long endTime) {
// this.taskName = taskName;
// this.startTime = startTime;
// this.endTime = endTime;
// this.duration = endTime - startTime;
// }
//
// public String getTaskName() {
// return taskName;
// }
//
// public long getStartTime() {
// return startTime;
// }
//
// public long getEndTime() {
// return endTime;
// }
//
// public long getDuration() {
// return duration;
// }
//
// @Override
// public String toString() {
// return "MeasurementResult{" +
// "taskName='" + taskName + '\'' +
// ", startTime=" + startTime +
// ", endTime=" + endTime +
// ", duration=" + duration +
// '}';
// }
// }
// Path: measures/src/main/java/io/apisense/network/udp/UDPDownloadBurstTask.java
import android.util.Log;
import java.io.IOException;
import java.net.DatagramSocket;
import io.apisense.network.MeasurementError;
import io.apisense.network.MeasurementResult;
package io.apisense.network.udp;
/**
* Measurement class used to realise an UDP download burst
* Measures the jitter, the jitter, the loss, and the number of out of order packets in download
*/
public class UDPDownloadBurstTask extends UDPBurstTask {
public static final String TAG = "UDPDownloadBurst";
public UDPDownloadBurstTask(UDPBurstConfig udpBurstConfig) {
super(TAG, udpBurstConfig);
}
/**
* {@inheritDoc}
*
* @return A {@link UDPBurstResult} object containing information on the UDP download burst.
* @throws MeasurementError {@inheritDoc}
*/ | public MeasurementResult execute() throws MeasurementError { |
APISENSE/android-network-measures | measures/src/main/java/io/apisense/network/udp/UDPBurstConfig.java | // Path: measures/src/main/java/io/apisense/network/MeasurementConfigException.java
// public class MeasurementConfigException extends Exception {
// public MeasurementConfigException(String reason) {
// super(reason);
// }
//
// public MeasurementConfigException(Exception cause) {
// super(cause);
// }
// }
| import java.net.InetAddress;
import java.net.UnknownHostException;
import io.apisense.network.MeasurementConfigException; | package io.apisense.network.udp;
/**
* Configuration class for both upload an download UDPBurstTask
*/
public class UDPBurstConfig {
/**
* Min packet size = (int type) + (int burstCount) + (int packetNum) + (int intervalNum) + (long
* timestamp) + (int packetSize) + (int seq) + (int udpInterval) = 36
*/
private static final int MIN_PACKETSIZE = 36;
/**
* Leave enough margin for min MTU in the link and IP options.
*/
private static final int MAX_PACKETSIZE = 500;
/**
* Size of the packets in bytes
*/
private int packetSizeByte = 100;
/**
* Number of packet to send by burst.
*/
private int udpBurstCount = 16;
/**
* Interval between burst (µs).
*
* This value will be rounded in {@link UDPPacket#UDPPacket(int, UDPBurstConfig)}.
*/
private int udpInterval = 500;
/**
* IP address of the remote server used for the test
*/
private InetAddress targetIp;
/**
* URL of the remote server used for the test
*/
private String url;
| // Path: measures/src/main/java/io/apisense/network/MeasurementConfigException.java
// public class MeasurementConfigException extends Exception {
// public MeasurementConfigException(String reason) {
// super(reason);
// }
//
// public MeasurementConfigException(Exception cause) {
// super(cause);
// }
// }
// Path: measures/src/main/java/io/apisense/network/udp/UDPBurstConfig.java
import java.net.InetAddress;
import java.net.UnknownHostException;
import io.apisense.network.MeasurementConfigException;
package io.apisense.network.udp;
/**
* Configuration class for both upload an download UDPBurstTask
*/
public class UDPBurstConfig {
/**
* Min packet size = (int type) + (int burstCount) + (int packetNum) + (int intervalNum) + (long
* timestamp) + (int packetSize) + (int seq) + (int udpInterval) = 36
*/
private static final int MIN_PACKETSIZE = 36;
/**
* Leave enough margin for min MTU in the link and IP options.
*/
private static final int MAX_PACKETSIZE = 500;
/**
* Size of the packets in bytes
*/
private int packetSizeByte = 100;
/**
* Number of packet to send by burst.
*/
private int udpBurstCount = 16;
/**
* Interval between burst (µs).
*
* This value will be rounded in {@link UDPPacket#UDPPacket(int, UDPBurstConfig)}.
*/
private int udpInterval = 500;
/**
* IP address of the remote server used for the test
*/
private InetAddress targetIp;
/**
* URL of the remote server used for the test
*/
private String url;
| public UDPBurstConfig(String url, int packetSizeByte) throws MeasurementConfigException { |
APISENSE/android-network-measures | measures/src/main/java/io/apisense/network/tcp/TCPThroughputTask.java | // Path: measures/src/main/java/io/apisense/network/Measurement.java
// public abstract class Measurement {
// public final String taskName;
//
// protected Measurement(String taskName) {
// this.taskName = taskName;
// }
//
// /**
// * Ensure that the measurement is asynchronously called in an {@link ExecutorService}.
// *
// * @param callback The {@link MeasurementCallback} used
// * for reporting success or failure of this measurement.
// */
// public final void call(MeasurementCallback callback) {
// AsyncTask.execute(new MeasurementExecutor(this, callback));
// }
//
// /**
// * Actual, synchronous, process of a measurement.
// * This method has to be called from another thread than the UI one.
// *
// * @return The results of this measurement.
// * @throws MeasurementError If anything goes wrong during measurement.
// */
// public abstract MeasurementResult execute() throws MeasurementError;
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
| import android.util.Log;
import java.io.Closeable;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import io.apisense.network.Measurement;
import io.apisense.network.MeasurementError; | package io.apisense.network.tcp;
/**
* Abstract class containing common code used for UDP upload and download tests
*/
abstract class TCPThroughputTask extends Measurement {
protected static final int BUFFER_SIZE = 5000;
private static final String TAG = "TCPThroughputTask";
private static final int SEC_TO_MS = 1000;
protected final TCPThroughputConfig config;
// helper variables
protected int accumulativeSize = 0;
//start time of each sampling period in milliseconds
protected long startSampleTime = 0;
protected long taskStartTime = 0;
protected long taskEndTime = 0;
/**
* Data consummed (sent/received) after slow star period (in bits)
*/
protected long dataConsumedAfterSlowStart = 0;
List<Double> samplingResults = new ArrayList<>();
TCPThroughputTask(String taskName, TCPThroughputConfig tcpThroughputConfig) {
super(taskName);
config = tcpThroughputConfig;
}
| // Path: measures/src/main/java/io/apisense/network/Measurement.java
// public abstract class Measurement {
// public final String taskName;
//
// protected Measurement(String taskName) {
// this.taskName = taskName;
// }
//
// /**
// * Ensure that the measurement is asynchronously called in an {@link ExecutorService}.
// *
// * @param callback The {@link MeasurementCallback} used
// * for reporting success or failure of this measurement.
// */
// public final void call(MeasurementCallback callback) {
// AsyncTask.execute(new MeasurementExecutor(this, callback));
// }
//
// /**
// * Actual, synchronous, process of a measurement.
// * This method has to be called from another thread than the UI one.
// *
// * @return The results of this measurement.
// * @throws MeasurementError If anything goes wrong during measurement.
// */
// public abstract MeasurementResult execute() throws MeasurementError;
// }
//
// Path: measures/src/main/java/io/apisense/network/MeasurementError.java
// public class MeasurementError extends Exception {
// public final String taskName;
//
// public MeasurementError(String taskName, String reason) {
// super(reason);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, String reason, Throwable e) {
// super(reason, e);
// this.taskName = taskName;
// }
//
// public MeasurementError(String taskName, Exception e) {
// this(taskName, e.getMessage(), e);
// }
// }
// Path: measures/src/main/java/io/apisense/network/tcp/TCPThroughputTask.java
import android.util.Log;
import java.io.Closeable;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import io.apisense.network.Measurement;
import io.apisense.network.MeasurementError;
package io.apisense.network.tcp;
/**
* Abstract class containing common code used for UDP upload and download tests
*/
abstract class TCPThroughputTask extends Measurement {
protected static final int BUFFER_SIZE = 5000;
private static final String TAG = "TCPThroughputTask";
private static final int SEC_TO_MS = 1000;
protected final TCPThroughputConfig config;
// helper variables
protected int accumulativeSize = 0;
//start time of each sampling period in milliseconds
protected long startSampleTime = 0;
protected long taskStartTime = 0;
protected long taskEndTime = 0;
/**
* Data consummed (sent/received) after slow star period (in bits)
*/
protected long dataConsumedAfterSlowStart = 0;
List<Double> samplingResults = new ArrayList<>();
TCPThroughputTask(String taskName, TCPThroughputConfig tcpThroughputConfig) {
super(taskName);
config = tcpThroughputConfig;
}
| protected Socket buildUpSocket(InetAddress hostname, int portNum) throws MeasurementError { |
toby1984/threadwatch | src/main/java/de/codesourcery/threadwatcher/ui/IntervalPanel.java | // Path: src/main/java/de/codesourcery/threadwatcher/HiResInterval.java
// public final class HiResInterval {
//
// public final HiResTimestamp start;
// public final HiResTimestamp end;
//
// public HiResInterval(DateTime start, DateTime end) {
// this( new HiResTimestamp( start , false ) ,new HiResTimestamp( end , false ) );
// }
//
// public HiResInterval(HiResTimestamp start, HiResTimestamp end)
// {
// if ( start.isAfter(end ) ) {
// throw new IllegalArgumentException("start "+start+" s after end "+end+" ?");
// }
// if ( start.truncatedToMillis != end.truncatedToMillis ) {
// throw new IllegalArgumentException("start "+start+" and end "+end+" have different precisions");
// }
// this.start = start;
// this.end = end;
// }
//
// public boolean contains(HiResTimestamp timestamp)
// {
// return start.compareTo( timestamp ) <= 0 &&
// end.compareTo( timestamp ) >0;
// }
//
// public boolean containsEndInclusive(HiResTimestamp timestamp)
// {
// return start.compareTo( timestamp ) <= 0 &&
// end.compareTo( timestamp ) >= 0;
// }
//
// public HiResInterval rollBySeconds(int seconds) {
// return new HiResInterval( start.plusSeconds( seconds ) , end.plusSeconds( seconds ) );
// }
//
// public HiResInterval rollByMilliseconds(long millis)
// {
// return new HiResInterval( start.plusMilliseconds( millis ) , end.plusMilliseconds( millis ) );
// }
//
// public double getDurationInMilliseconds()
// {
// return getDurationInMilliseconds(this.start,this.end);
// }
//
// public static double getDurationInMilliseconds(HiResTimestamp start,HiResTimestamp end)
// {
// if ( start.compareTo( end ) > 0 ) {
// throw new IllegalArgumentException( "start "+start+" > end "+end);
// }
// return getDurationInMilliseconds(start.secondsSinceEpoch , start.nanoseconds , end.secondsSinceEpoch , end.nanoseconds );
// }
//
// public static double getDurationInMilliseconds(long startSeconds,long startNanos,long endSeconds,long endNanos)
// {
// double nanos1 = startSeconds*1000000000+startNanos;
// double nanos2 = endSeconds*1000000000+endNanos;
// double deltaNano = nanos2-nanos1;
// double result = deltaNano/1000000;
// if ( result < 0 ) {
// throw new RuntimeException("getDurationMillis( "+startSeconds+"."+startNanos+" - "+endSeconds+"."+endNanos+" ) = "+deltaNano);
// }
// return result;
// }
//
// @Override
// public String toString() {
// return start.toString()+" - "+end.toString();
// }
//
// public boolean overlaps(HiResInterval interval)
// {
// return overlaps(this,interval) || overlaps( interval, this );
// }
//
// private static boolean overlaps(HiResInterval i1,HiResInterval i2)
// {
// if ( i1.start.compareTo( i2.start ) <= 0 )
// {
// if ( i2.contains( i1.end ) ) {
// return true;
// }
// return i1.end.compareTo( i2.end ) >= 0;
// } else if ( i2.contains( i1.start ) && i2.contains( i1.end ) ) {
// return true;
// }
// return false;
// }
//
// public String toUIString()
// {
// DateTimeFormatter DF = new DateTimeFormatterBuilder()
// .appendYear(4, 4)
// .appendLiteral('-')
// .appendMonthOfYear(1)
// .appendLiteral('-')
// .appendDayOfMonth(1)
// .appendLiteral(" ")
// .appendHourOfDay(2)
// .appendLiteral(':')
// .appendMinuteOfHour(2)
// .appendLiteral(':')
// .appendSecondOfMinute(2)
// .appendLiteral('.')
// .appendMillisOfSecond(1)
// .toFormatter();
//
// final String start = DF.print( this.start.toDateTime());
// final String end = DF.print( this.end.toDateTime());
// return start+" - "+end+" [ "+getDurationInMilliseconds()+" ms ]";
// }
// }
| import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import de.codesourcery.threadwatcher.HiResInterval; | /**
* Copyright 2013 Tobias Gierke <tobias.gierke@code-sourcery.de>
*
* 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 de.codesourcery.threadwatcher.ui;
public class IntervalPanel extends JPanel {
private final JTextField viewIntervalStart = new JTextField();
private final JTextField viewIntervalEnd = new JTextField();
private final JTextField viewIntervalDuration= new JTextField();
@Override
public void setBackground(Color bg) {
super.setBackground(bg);
if ( viewIntervalStart != null ) {
viewIntervalStart.setBackground( bg );
viewIntervalEnd.setBackground( bg );
viewIntervalDuration.setBackground( bg );
}
}
| // Path: src/main/java/de/codesourcery/threadwatcher/HiResInterval.java
// public final class HiResInterval {
//
// public final HiResTimestamp start;
// public final HiResTimestamp end;
//
// public HiResInterval(DateTime start, DateTime end) {
// this( new HiResTimestamp( start , false ) ,new HiResTimestamp( end , false ) );
// }
//
// public HiResInterval(HiResTimestamp start, HiResTimestamp end)
// {
// if ( start.isAfter(end ) ) {
// throw new IllegalArgumentException("start "+start+" s after end "+end+" ?");
// }
// if ( start.truncatedToMillis != end.truncatedToMillis ) {
// throw new IllegalArgumentException("start "+start+" and end "+end+" have different precisions");
// }
// this.start = start;
// this.end = end;
// }
//
// public boolean contains(HiResTimestamp timestamp)
// {
// return start.compareTo( timestamp ) <= 0 &&
// end.compareTo( timestamp ) >0;
// }
//
// public boolean containsEndInclusive(HiResTimestamp timestamp)
// {
// return start.compareTo( timestamp ) <= 0 &&
// end.compareTo( timestamp ) >= 0;
// }
//
// public HiResInterval rollBySeconds(int seconds) {
// return new HiResInterval( start.plusSeconds( seconds ) , end.plusSeconds( seconds ) );
// }
//
// public HiResInterval rollByMilliseconds(long millis)
// {
// return new HiResInterval( start.plusMilliseconds( millis ) , end.plusMilliseconds( millis ) );
// }
//
// public double getDurationInMilliseconds()
// {
// return getDurationInMilliseconds(this.start,this.end);
// }
//
// public static double getDurationInMilliseconds(HiResTimestamp start,HiResTimestamp end)
// {
// if ( start.compareTo( end ) > 0 ) {
// throw new IllegalArgumentException( "start "+start+" > end "+end);
// }
// return getDurationInMilliseconds(start.secondsSinceEpoch , start.nanoseconds , end.secondsSinceEpoch , end.nanoseconds );
// }
//
// public static double getDurationInMilliseconds(long startSeconds,long startNanos,long endSeconds,long endNanos)
// {
// double nanos1 = startSeconds*1000000000+startNanos;
// double nanos2 = endSeconds*1000000000+endNanos;
// double deltaNano = nanos2-nanos1;
// double result = deltaNano/1000000;
// if ( result < 0 ) {
// throw new RuntimeException("getDurationMillis( "+startSeconds+"."+startNanos+" - "+endSeconds+"."+endNanos+" ) = "+deltaNano);
// }
// return result;
// }
//
// @Override
// public String toString() {
// return start.toString()+" - "+end.toString();
// }
//
// public boolean overlaps(HiResInterval interval)
// {
// return overlaps(this,interval) || overlaps( interval, this );
// }
//
// private static boolean overlaps(HiResInterval i1,HiResInterval i2)
// {
// if ( i1.start.compareTo( i2.start ) <= 0 )
// {
// if ( i2.contains( i1.end ) ) {
// return true;
// }
// return i1.end.compareTo( i2.end ) >= 0;
// } else if ( i2.contains( i1.start ) && i2.contains( i1.end ) ) {
// return true;
// }
// return false;
// }
//
// public String toUIString()
// {
// DateTimeFormatter DF = new DateTimeFormatterBuilder()
// .appendYear(4, 4)
// .appendLiteral('-')
// .appendMonthOfYear(1)
// .appendLiteral('-')
// .appendDayOfMonth(1)
// .appendLiteral(" ")
// .appendHourOfDay(2)
// .appendLiteral(':')
// .appendMinuteOfHour(2)
// .appendLiteral(':')
// .appendSecondOfMinute(2)
// .appendLiteral('.')
// .appendMillisOfSecond(1)
// .toFormatter();
//
// final String start = DF.print( this.start.toDateTime());
// final String end = DF.print( this.end.toDateTime());
// return start+" - "+end+" [ "+getDurationInMilliseconds()+" ms ]";
// }
// }
// Path: src/main/java/de/codesourcery/threadwatcher/ui/IntervalPanel.java
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import de.codesourcery.threadwatcher.HiResInterval;
/**
* Copyright 2013 Tobias Gierke <tobias.gierke@code-sourcery.de>
*
* 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 de.codesourcery.threadwatcher.ui;
public class IntervalPanel extends JPanel {
private final JTextField viewIntervalStart = new JTextField();
private final JTextField viewIntervalEnd = new JTextField();
private final JTextField viewIntervalDuration= new JTextField();
@Override
public void setBackground(Color bg) {
super.setBackground(bg);
if ( viewIntervalStart != null ) {
viewIntervalStart.setBackground( bg );
viewIntervalEnd.setBackground( bg );
viewIntervalDuration.setBackground( bg );
}
}
| public IntervalPanel(HiResInterval interval) |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogError.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IORuntimeException.java
// public final class IORuntimeException extends AndroidScreenCastRuntimeException {
//
// public IORuntimeException(String message, IOException cause) {
// super(message, cause);
// }
//
// public IORuntimeException(IOException cause) {
// super(cause);
// }
//
// public IORuntimeException(String message, IOException cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/util/StringUtils.java
// public final class StringUtils {
//
// private StringUtils() {
// }
//
// public static boolean isNotEmpty(final CharSequence charSequence) {
// return charSequence != null && charSequence.length() > 0;
// }
// }
| import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
import com.github.xsavikx.androidscreencast.util.StringUtils;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter; | errorDialogLabel = new JLabel();
JScrollPane scrollPane = new JScrollPane();
errorDescription = new JTextArea();
errorDescription.setLineWrap(true);
errorDescription.setWrapStyleWord(true);
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout(5, 5));
errorDialogLabel.setText(ex.getClass().getSimpleName());
errorDialogLabel.setLabelFor(errorDescription);
errorDialogLabel.setHorizontalAlignment(SwingConstants.CENTER);
contentPane.add(errorDialogLabel, BorderLayout.NORTH);
setErrorDetails(ex);
scrollPane.setViewportView(errorDescription);
contentPane.add(scrollPane, BorderLayout.CENTER);
pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setSize((int) screenSize.getWidth() >> 1, (int) screenSize.getHeight() >> 1);
setLocationRelativeTo(null);
setAlwaysOnTop(true);
}
private void setErrorDetails(Throwable e) {
Throwable ex = getRealException(e);
errorDialogLabel.setText(ex.getClass().getSimpleName());
try (StringWriter stringWriter = new StringWriter()) { | // Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IORuntimeException.java
// public final class IORuntimeException extends AndroidScreenCastRuntimeException {
//
// public IORuntimeException(String message, IOException cause) {
// super(message, cause);
// }
//
// public IORuntimeException(IOException cause) {
// super(cause);
// }
//
// public IORuntimeException(String message, IOException cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/util/StringUtils.java
// public final class StringUtils {
//
// private StringUtils() {
// }
//
// public static boolean isNotEmpty(final CharSequence charSequence) {
// return charSequence != null && charSequence.length() > 0;
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogError.java
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
import com.github.xsavikx.androidscreencast.util.StringUtils;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
errorDialogLabel = new JLabel();
JScrollPane scrollPane = new JScrollPane();
errorDescription = new JTextArea();
errorDescription.setLineWrap(true);
errorDescription.setWrapStyleWord(true);
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout(5, 5));
errorDialogLabel.setText(ex.getClass().getSimpleName());
errorDialogLabel.setLabelFor(errorDescription);
errorDialogLabel.setHorizontalAlignment(SwingConstants.CENTER);
contentPane.add(errorDialogLabel, BorderLayout.NORTH);
setErrorDetails(ex);
scrollPane.setViewportView(errorDescription);
contentPane.add(scrollPane, BorderLayout.CENTER);
pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setSize((int) screenSize.getWidth() >> 1, (int) screenSize.getHeight() >> 1);
setLocationRelativeTo(null);
setAlwaysOnTop(true);
}
private void setErrorDetails(Throwable e) {
Throwable ex = getRealException(e);
errorDialogLabel.setText(ex.getClass().getSimpleName());
try (StringWriter stringWriter = new StringWriter()) { | AndroidScreenCastRuntimeException realCause = getCause(ex); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogError.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IORuntimeException.java
// public final class IORuntimeException extends AndroidScreenCastRuntimeException {
//
// public IORuntimeException(String message, IOException cause) {
// super(message, cause);
// }
//
// public IORuntimeException(IOException cause) {
// super(cause);
// }
//
// public IORuntimeException(String message, IOException cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/util/StringUtils.java
// public final class StringUtils {
//
// private StringUtils() {
// }
//
// public static boolean isNotEmpty(final CharSequence charSequence) {
// return charSequence != null && charSequence.length() > 0;
// }
// }
| import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
import com.github.xsavikx.androidscreencast.util.StringUtils;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter; | errorDescription.setLineWrap(true);
errorDescription.setWrapStyleWord(true);
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout(5, 5));
errorDialogLabel.setText(ex.getClass().getSimpleName());
errorDialogLabel.setLabelFor(errorDescription);
errorDialogLabel.setHorizontalAlignment(SwingConstants.CENTER);
contentPane.add(errorDialogLabel, BorderLayout.NORTH);
setErrorDetails(ex);
scrollPane.setViewportView(errorDescription);
contentPane.add(scrollPane, BorderLayout.CENTER);
pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setSize((int) screenSize.getWidth() >> 1, (int) screenSize.getHeight() >> 1);
setLocationRelativeTo(null);
setAlwaysOnTop(true);
}
private void setErrorDetails(Throwable e) {
Throwable ex = getRealException(e);
errorDialogLabel.setText(ex.getClass().getSimpleName());
try (StringWriter stringWriter = new StringWriter()) {
AndroidScreenCastRuntimeException realCause = getCause(ex);
if (realCause != null) {
errorDialogLabel.setText(realCause.getClass().getSimpleName()); | // Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IORuntimeException.java
// public final class IORuntimeException extends AndroidScreenCastRuntimeException {
//
// public IORuntimeException(String message, IOException cause) {
// super(message, cause);
// }
//
// public IORuntimeException(IOException cause) {
// super(cause);
// }
//
// public IORuntimeException(String message, IOException cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/util/StringUtils.java
// public final class StringUtils {
//
// private StringUtils() {
// }
//
// public static boolean isNotEmpty(final CharSequence charSequence) {
// return charSequence != null && charSequence.length() > 0;
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogError.java
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
import com.github.xsavikx.androidscreencast.util.StringUtils;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
errorDescription.setLineWrap(true);
errorDescription.setWrapStyleWord(true);
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout(5, 5));
errorDialogLabel.setText(ex.getClass().getSimpleName());
errorDialogLabel.setLabelFor(errorDescription);
errorDialogLabel.setHorizontalAlignment(SwingConstants.CENTER);
contentPane.add(errorDialogLabel, BorderLayout.NORTH);
setErrorDetails(ex);
scrollPane.setViewportView(errorDescription);
contentPane.add(scrollPane, BorderLayout.CENTER);
pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setSize((int) screenSize.getWidth() >> 1, (int) screenSize.getHeight() >> 1);
setLocationRelativeTo(null);
setAlwaysOnTop(true);
}
private void setErrorDetails(Throwable e) {
Throwable ex = getRealException(e);
errorDialogLabel.setText(ex.getClass().getSimpleName());
try (StringWriter stringWriter = new StringWriter()) {
AndroidScreenCastRuntimeException realCause = getCause(ex);
if (realCause != null) {
errorDialogLabel.setText(realCause.getClass().getSimpleName()); | if (StringUtils.isNotEmpty(realCause.getMessage())) |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogError.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IORuntimeException.java
// public final class IORuntimeException extends AndroidScreenCastRuntimeException {
//
// public IORuntimeException(String message, IOException cause) {
// super(message, cause);
// }
//
// public IORuntimeException(IOException cause) {
// super(cause);
// }
//
// public IORuntimeException(String message, IOException cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/util/StringUtils.java
// public final class StringUtils {
//
// private StringUtils() {
// }
//
// public static boolean isNotEmpty(final CharSequence charSequence) {
// return charSequence != null && charSequence.length() > 0;
// }
// }
| import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
import com.github.xsavikx.androidscreencast.util.StringUtils;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter; | contentPane.add(errorDialogLabel, BorderLayout.NORTH);
setErrorDetails(ex);
scrollPane.setViewportView(errorDescription);
contentPane.add(scrollPane, BorderLayout.CENTER);
pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setSize((int) screenSize.getWidth() >> 1, (int) screenSize.getHeight() >> 1);
setLocationRelativeTo(null);
setAlwaysOnTop(true);
}
private void setErrorDetails(Throwable e) {
Throwable ex = getRealException(e);
errorDialogLabel.setText(ex.getClass().getSimpleName());
try (StringWriter stringWriter = new StringWriter()) {
AndroidScreenCastRuntimeException realCause = getCause(ex);
if (realCause != null) {
errorDialogLabel.setText(realCause.getClass().getSimpleName());
if (StringUtils.isNotEmpty(realCause.getMessage()))
stringWriter.append(realCause.getMessage()).append('\n').append('\n');
if (StringUtils.isNotEmpty(realCause.getAdditionalInformation()))
stringWriter.append(realCause.getAdditionalInformation());
} else {
if (StringUtils.isNotEmpty(ex.getMessage()))
stringWriter.append(ex.getMessage()).append('\n').append('\n');
ex.printStackTrace(new PrintWriter(stringWriter));
}
errorDescription.setText(stringWriter.toString());
} catch (IOException ioe) { | // Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IORuntimeException.java
// public final class IORuntimeException extends AndroidScreenCastRuntimeException {
//
// public IORuntimeException(String message, IOException cause) {
// super(message, cause);
// }
//
// public IORuntimeException(IOException cause) {
// super(cause);
// }
//
// public IORuntimeException(String message, IOException cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/util/StringUtils.java
// public final class StringUtils {
//
// private StringUtils() {
// }
//
// public static boolean isNotEmpty(final CharSequence charSequence) {
// return charSequence != null && charSequence.length() > 0;
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/ui/JDialogError.java
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
import com.github.xsavikx.androidscreencast.util.StringUtils;
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
contentPane.add(errorDialogLabel, BorderLayout.NORTH);
setErrorDetails(ex);
scrollPane.setViewportView(errorDescription);
contentPane.add(scrollPane, BorderLayout.CENTER);
pack();
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
setSize((int) screenSize.getWidth() >> 1, (int) screenSize.getHeight() >> 1);
setLocationRelativeTo(null);
setAlwaysOnTop(true);
}
private void setErrorDetails(Throwable e) {
Throwable ex = getRealException(e);
errorDialogLabel.setText(ex.getClass().getSimpleName());
try (StringWriter stringWriter = new StringWriter()) {
AndroidScreenCastRuntimeException realCause = getCause(ex);
if (realCause != null) {
errorDialogLabel.setText(realCause.getClass().getSimpleName());
if (StringUtils.isNotEmpty(realCause.getMessage()))
stringWriter.append(realCause.getMessage()).append('\n').append('\n');
if (StringUtils.isNotEmpty(realCause.getAdditionalInformation()))
stringWriter.append(realCause.getAdditionalInformation());
} else {
if (StringUtils.isNotEmpty(ex.getMessage()))
stringWriter.append(ex.getMessage()).append('\n').append('\n');
ex.printStackTrace(new PrintWriter(stringWriter));
}
errorDescription.setText(stringWriter.toString());
} catch (IOException ioe) { | throw new IORuntimeException(ioe); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/ShellCommandExecutor.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/Command.java
// public interface Command {
//
// String INPUT = "input";
// String WHITESPACE = " ";
//
// String getFormattedCommand();
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/exception/AdbShellCommandExecutionException.java
// public final class AdbShellCommandExecutionException extends CommandExecutionException {
//
// private static final String ERROR_MESSAGE = "Error while executing command: %s";
//
// private static final long serialVersionUID = -503890452151627952L;
//
// public AdbShellCommandExecutionException(Command command, Throwable cause) {
// super(String.format(ERROR_MESSAGE, command.getFormattedCommand()), cause);
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfigurationPropertyKeys.java
// public static final String ADB_COMMAND_TIMEOUT_KEY = "adb.command.timeout";
| import com.android.ddmlib.*;
import com.github.xsavikx.androidscreencast.api.command.Command;
import com.github.xsavikx.androidscreencast.api.command.exception.AdbShellCommandExecutionException;
import org.slf4j.Logger;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.ADB_COMMAND_TIMEOUT_KEY;
import static org.slf4j.LoggerFactory.getLogger; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api.command.executor;
@Singleton
public final class ShellCommandExecutor implements CommandExecutor {
private final IDevice device;
private final IShellOutputReceiver shellOutputReceiver;
private final long adbCommandTimeout;
@Inject
public ShellCommandExecutor(final IDevice device,
final IShellOutputReceiver shellOutputReceiver, | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/Command.java
// public interface Command {
//
// String INPUT = "input";
// String WHITESPACE = " ";
//
// String getFormattedCommand();
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/exception/AdbShellCommandExecutionException.java
// public final class AdbShellCommandExecutionException extends CommandExecutionException {
//
// private static final String ERROR_MESSAGE = "Error while executing command: %s";
//
// private static final long serialVersionUID = -503890452151627952L;
//
// public AdbShellCommandExecutionException(Command command, Throwable cause) {
// super(String.format(ERROR_MESSAGE, command.getFormattedCommand()), cause);
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfigurationPropertyKeys.java
// public static final String ADB_COMMAND_TIMEOUT_KEY = "adb.command.timeout";
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/ShellCommandExecutor.java
import com.android.ddmlib.*;
import com.github.xsavikx.androidscreencast.api.command.Command;
import com.github.xsavikx.androidscreencast.api.command.exception.AdbShellCommandExecutionException;
import org.slf4j.Logger;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.ADB_COMMAND_TIMEOUT_KEY;
import static org.slf4j.LoggerFactory.getLogger;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api.command.executor;
@Singleton
public final class ShellCommandExecutor implements CommandExecutor {
private final IDevice device;
private final IShellOutputReceiver shellOutputReceiver;
private final long adbCommandTimeout;
@Inject
public ShellCommandExecutor(final IDevice device,
final IShellOutputReceiver shellOutputReceiver, | @Named(ADB_COMMAND_TIMEOUT_KEY) long adbCommandTimeout) { |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/ShellCommandExecutor.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/Command.java
// public interface Command {
//
// String INPUT = "input";
// String WHITESPACE = " ";
//
// String getFormattedCommand();
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/exception/AdbShellCommandExecutionException.java
// public final class AdbShellCommandExecutionException extends CommandExecutionException {
//
// private static final String ERROR_MESSAGE = "Error while executing command: %s";
//
// private static final long serialVersionUID = -503890452151627952L;
//
// public AdbShellCommandExecutionException(Command command, Throwable cause) {
// super(String.format(ERROR_MESSAGE, command.getFormattedCommand()), cause);
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfigurationPropertyKeys.java
// public static final String ADB_COMMAND_TIMEOUT_KEY = "adb.command.timeout";
| import com.android.ddmlib.*;
import com.github.xsavikx.androidscreencast.api.command.Command;
import com.github.xsavikx.androidscreencast.api.command.exception.AdbShellCommandExecutionException;
import org.slf4j.Logger;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.ADB_COMMAND_TIMEOUT_KEY;
import static org.slf4j.LoggerFactory.getLogger; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api.command.executor;
@Singleton
public final class ShellCommandExecutor implements CommandExecutor {
private final IDevice device;
private final IShellOutputReceiver shellOutputReceiver;
private final long adbCommandTimeout;
@Inject
public ShellCommandExecutor(final IDevice device,
final IShellOutputReceiver shellOutputReceiver,
@Named(ADB_COMMAND_TIMEOUT_KEY) long adbCommandTimeout) {
this.device = device;
this.shellOutputReceiver = shellOutputReceiver;
this.adbCommandTimeout = adbCommandTimeout;
}
@Override | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/Command.java
// public interface Command {
//
// String INPUT = "input";
// String WHITESPACE = " ";
//
// String getFormattedCommand();
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/exception/AdbShellCommandExecutionException.java
// public final class AdbShellCommandExecutionException extends CommandExecutionException {
//
// private static final String ERROR_MESSAGE = "Error while executing command: %s";
//
// private static final long serialVersionUID = -503890452151627952L;
//
// public AdbShellCommandExecutionException(Command command, Throwable cause) {
// super(String.format(ERROR_MESSAGE, command.getFormattedCommand()), cause);
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfigurationPropertyKeys.java
// public static final String ADB_COMMAND_TIMEOUT_KEY = "adb.command.timeout";
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/ShellCommandExecutor.java
import com.android.ddmlib.*;
import com.github.xsavikx.androidscreencast.api.command.Command;
import com.github.xsavikx.androidscreencast.api.command.exception.AdbShellCommandExecutionException;
import org.slf4j.Logger;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.ADB_COMMAND_TIMEOUT_KEY;
import static org.slf4j.LoggerFactory.getLogger;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api.command.executor;
@Singleton
public final class ShellCommandExecutor implements CommandExecutor {
private final IDevice device;
private final IShellOutputReceiver shellOutputReceiver;
private final long adbCommandTimeout;
@Inject
public ShellCommandExecutor(final IDevice device,
final IShellOutputReceiver shellOutputReceiver,
@Named(ADB_COMMAND_TIMEOUT_KEY) long adbCommandTimeout) {
this.device = device;
this.shellOutputReceiver = shellOutputReceiver;
this.adbCommandTimeout = adbCommandTimeout;
}
@Override | public void execute(Command command) { |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/ShellCommandExecutor.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/Command.java
// public interface Command {
//
// String INPUT = "input";
// String WHITESPACE = " ";
//
// String getFormattedCommand();
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/exception/AdbShellCommandExecutionException.java
// public final class AdbShellCommandExecutionException extends CommandExecutionException {
//
// private static final String ERROR_MESSAGE = "Error while executing command: %s";
//
// private static final long serialVersionUID = -503890452151627952L;
//
// public AdbShellCommandExecutionException(Command command, Throwable cause) {
// super(String.format(ERROR_MESSAGE, command.getFormattedCommand()), cause);
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfigurationPropertyKeys.java
// public static final String ADB_COMMAND_TIMEOUT_KEY = "adb.command.timeout";
| import com.android.ddmlib.*;
import com.github.xsavikx.androidscreencast.api.command.Command;
import com.github.xsavikx.androidscreencast.api.command.exception.AdbShellCommandExecutionException;
import org.slf4j.Logger;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.ADB_COMMAND_TIMEOUT_KEY;
import static org.slf4j.LoggerFactory.getLogger; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api.command.executor;
@Singleton
public final class ShellCommandExecutor implements CommandExecutor {
private final IDevice device;
private final IShellOutputReceiver shellOutputReceiver;
private final long adbCommandTimeout;
@Inject
public ShellCommandExecutor(final IDevice device,
final IShellOutputReceiver shellOutputReceiver,
@Named(ADB_COMMAND_TIMEOUT_KEY) long adbCommandTimeout) {
this.device = device;
this.shellOutputReceiver = shellOutputReceiver;
this.adbCommandTimeout = adbCommandTimeout;
}
@Override
public void execute(Command command) {
log().debug("Executing command: {}", command);
try {
device.executeShellCommand(command.getFormattedCommand(), shellOutputReceiver,
adbCommandTimeout, TimeUnit.SECONDS);
log().debug("Command {} successfully executed.", command);
} catch (TimeoutException | AdbCommandRejectedException | ShellCommandUnresponsiveException | IOException e) {
log().error("An exception happened during command execution: {}.", command, e); | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/Command.java
// public interface Command {
//
// String INPUT = "input";
// String WHITESPACE = " ";
//
// String getFormattedCommand();
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/exception/AdbShellCommandExecutionException.java
// public final class AdbShellCommandExecutionException extends CommandExecutionException {
//
// private static final String ERROR_MESSAGE = "Error while executing command: %s";
//
// private static final long serialVersionUID = -503890452151627952L;
//
// public AdbShellCommandExecutionException(Command command, Throwable cause) {
// super(String.format(ERROR_MESSAGE, command.getFormattedCommand()), cause);
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfigurationPropertyKeys.java
// public static final String ADB_COMMAND_TIMEOUT_KEY = "adb.command.timeout";
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/ShellCommandExecutor.java
import com.android.ddmlib.*;
import com.github.xsavikx.androidscreencast.api.command.Command;
import com.github.xsavikx.androidscreencast.api.command.exception.AdbShellCommandExecutionException;
import org.slf4j.Logger;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.ADB_COMMAND_TIMEOUT_KEY;
import static org.slf4j.LoggerFactory.getLogger;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api.command.executor;
@Singleton
public final class ShellCommandExecutor implements CommandExecutor {
private final IDevice device;
private final IShellOutputReceiver shellOutputReceiver;
private final long adbCommandTimeout;
@Inject
public ShellCommandExecutor(final IDevice device,
final IShellOutputReceiver shellOutputReceiver,
@Named(ADB_COMMAND_TIMEOUT_KEY) long adbCommandTimeout) {
this.device = device;
this.shellOutputReceiver = shellOutputReceiver;
this.adbCommandTimeout = adbCommandTimeout;
}
@Override
public void execute(Command command) {
log().debug("Executing command: {}", command);
try {
device.executeShellCommand(command.getFormattedCommand(), shellOutputReceiver,
adbCommandTimeout, TimeUnit.SECONDS);
log().debug("Command {} successfully executed.", command);
} catch (TimeoutException | AdbCommandRejectedException | ShellCommandUnresponsiveException | IOException e) {
log().error("An exception happened during command execution: {}.", command, e); | throw new AdbShellCommandExecutionException(command, e); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/api/command/exception/AdbShellCommandExecutionException.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/Command.java
// public interface Command {
//
// String INPUT = "input";
// String WHITESPACE = " ";
//
// String getFormattedCommand();
// }
| import com.github.xsavikx.androidscreencast.api.command.Command; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api.command.exception;
public final class AdbShellCommandExecutionException extends CommandExecutionException {
private static final String ERROR_MESSAGE = "Error while executing command: %s";
private static final long serialVersionUID = -503890452151627952L;
| // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/Command.java
// public interface Command {
//
// String INPUT = "input";
// String WHITESPACE = " ";
//
// String getFormattedCommand();
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/exception/AdbShellCommandExecutionException.java
import com.github.xsavikx.androidscreencast.api.command.Command;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api.command.exception;
public final class AdbShellCommandExecutionException extends CommandExecutionException {
private static final String ERROR_MESSAGE = "Error while executing command: %s";
private static final long serialVersionUID = -503890452151627952L;
| public AdbShellCommandExecutionException(Command command, Throwable cause) { |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/Main.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/app/Application.java
// public interface Application {
//
// void stop();
//
// void handleException(Thread thread, Throwable ex);
//
// void start();
//
// void init();
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java
// public final class MainComponentProvider {
// private static MainComponent INSTANCE;
//
// private MainComponentProvider() {
//
// }
//
// public static MainComponent mainComponent() {
// if (INSTANCE == null) {
// INSTANCE = DaggerMainComponent.create();
// }
// return INSTANCE;
// }
// }
| import com.github.xsavikx.androidscreencast.app.Application;
import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider;
import org.slf4j.Logger;
import java.util.Arrays;
import static org.slf4j.LoggerFactory.getLogger; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast;
public final class Main {
private Main() {
}
public static void main(String[] args) {
log().debug("Starting Android Screencast with the args: {}", Arrays.toString(args));
try { | // Path: src/main/java/com/github/xsavikx/androidscreencast/app/Application.java
// public interface Application {
//
// void stop();
//
// void handleException(Thread thread, Throwable ex);
//
// void start();
//
// void init();
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java
// public final class MainComponentProvider {
// private static MainComponent INSTANCE;
//
// private MainComponentProvider() {
//
// }
//
// public static MainComponent mainComponent() {
// if (INSTANCE == null) {
// INSTANCE = DaggerMainComponent.create();
// }
// return INSTANCE;
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/Main.java
import com.github.xsavikx.androidscreencast.app.Application;
import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider;
import org.slf4j.Logger;
import java.util.Arrays;
import static org.slf4j.LoggerFactory.getLogger;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast;
public final class Main {
private Main() {
}
public static void main(String[] args) {
log().debug("Starting Android Screencast with the args: {}", Arrays.toString(args));
try { | Application application = MainComponentProvider.mainComponent().application(); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/Main.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/app/Application.java
// public interface Application {
//
// void stop();
//
// void handleException(Thread thread, Throwable ex);
//
// void start();
//
// void init();
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java
// public final class MainComponentProvider {
// private static MainComponent INSTANCE;
//
// private MainComponentProvider() {
//
// }
//
// public static MainComponent mainComponent() {
// if (INSTANCE == null) {
// INSTANCE = DaggerMainComponent.create();
// }
// return INSTANCE;
// }
// }
| import com.github.xsavikx.androidscreencast.app.Application;
import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider;
import org.slf4j.Logger;
import java.util.Arrays;
import static org.slf4j.LoggerFactory.getLogger; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast;
public final class Main {
private Main() {
}
public static void main(String[] args) {
log().debug("Starting Android Screencast with the args: {}", Arrays.toString(args));
try { | // Path: src/main/java/com/github/xsavikx/androidscreencast/app/Application.java
// public interface Application {
//
// void stop();
//
// void handleException(Thread thread, Throwable ex);
//
// void start();
//
// void init();
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java
// public final class MainComponentProvider {
// private static MainComponent INSTANCE;
//
// private MainComponentProvider() {
//
// }
//
// public static MainComponent mainComponent() {
// if (INSTANCE == null) {
// INSTANCE = DaggerMainComponent.create();
// }
// return INSTANCE;
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/Main.java
import com.github.xsavikx.androidscreencast.app.Application;
import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider;
import org.slf4j.Logger;
import java.util.Arrays;
import static org.slf4j.LoggerFactory.getLogger;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast;
public final class Main {
private Main() {
}
public static void main(String[] args) {
log().debug("Starting Android Screencast with the args: {}", Arrays.toString(args));
try { | Application application = MainComponentProvider.mainComponent().application(); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDevice.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java
// @Singleton
// public final class FileInfo {
//
// public AndroidDeviceImpl device;
// public String path;
// public String attribs;
// public boolean directory;
// public String name;
//
// @Inject
// public FileInfo() {
// }
//
// public File downloadTemporary() {
// try {
// File tempFile = File.createTempFile("android", name);
// device.pullFile(path + name, tempFile);
// tempFile.deleteOnExit();
// return tempFile;
// } catch (IOException ex) {
// throw new IORuntimeException(ex);
// }
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
| import com.github.xsavikx.androidscreencast.api.file.FileInfo;
import java.io.File;
import java.util.List; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api;
public interface AndroidDevice {
String executeCommand(String command);
| // Path: src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java
// @Singleton
// public final class FileInfo {
//
// public AndroidDeviceImpl device;
// public String path;
// public String attribs;
// public boolean directory;
// public String name;
//
// @Inject
// public FileInfo() {
// }
//
// public File downloadTemporary() {
// try {
// File tempFile = File.createTempFile("android", name);
// device.pullFile(path + name, tempFile);
// tempFile.deleteOnExit();
// return tempFile;
// } catch (IOException ex) {
// throw new IORuntimeException(ex);
// }
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDevice.java
import com.github.xsavikx.androidscreencast.api.file.FileInfo;
import java.io.File;
import java.util.List;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api;
public interface AndroidDevice {
String executeCommand(String command);
| List<FileInfo> list(String path); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/api/recording/atom/CommonAtom.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IORuntimeException.java
// public final class IORuntimeException extends AndroidScreenCastRuntimeException {
//
// public IORuntimeException(String message, IOException cause) {
// super(message, cause);
// }
//
// public IORuntimeException(IOException cause) {
// super(cause);
// }
//
// public IORuntimeException(String message, IOException cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
| import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
import javax.imageio.stream.ImageOutputStream;
import java.io.IOException; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api.recording.atom;
abstract class CommonAtom extends Atom {
protected static final long HEADER_ELEMENT_SIZE = 8;
public CommonAtom(AtomType type, ImageOutputStream imageOutputStream) {
super(type, imageOutputStream);
try {
int headerSize = getHeaderElements();
for (int i = 0; i < headerSize; i++) {
out.writeLong(0); // make room for the atom header
}
} catch (IOException e) { | // Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IORuntimeException.java
// public final class IORuntimeException extends AndroidScreenCastRuntimeException {
//
// public IORuntimeException(String message, IOException cause) {
// super(message, cause);
// }
//
// public IORuntimeException(IOException cause) {
// super(cause);
// }
//
// public IORuntimeException(String message, IOException cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/recording/atom/CommonAtom.java
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
import javax.imageio.stream.ImageOutputStream;
import java.io.IOException;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api.recording.atom;
abstract class CommonAtom extends Atom {
protected static final long HEADER_ELEMENT_SIZE = 8;
public CommonAtom(AtomType type, ImageOutputStream imageOutputStream) {
super(type, imageOutputStream);
try {
int headerSize = getHeaderElements();
for (int i = 0; i < headerSize; i++) {
out.writeLong(0); // make room for the atom header
}
} catch (IOException e) { | throw new IORuntimeException(e); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/api/recording/DataAtomOutputStream.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/recording/atom/AtomType.java
// public enum AtomType {
// MEDIA_DATA("mdat"),
// MOVIE("moov"),
// MOVIE_HEADER("mvhd"),
// TRACK("trak"),
// TRACK_HEADER("tkhd"),
// MEDIA("mdia"),
// MEDIA_HEADER("mdhd"),
// HANDLER("hdlr"),
// MEDIA_HANDLER("mhlr"),
// VIDEO("vide"),
// MEDIA_INFORMATION("minf"),
// VIDEO_MEDIA_INFORMATION("vmhd"),
// FILE_ALIAS("alis"),
// DATA_INFORMATION("dinf"),
// DATA_REFERENCE("dref"),
// SAMPLE_TABLE("stbl"),
// SAMPLE_DESCRIPTION("stsd"),
// RAW("raw "),
// JAVA("java"),
// JPEG("jpeg"),
// PNG("png "),
// TIME_TO_SAMPLE_MAPPING("stts"),
// SAMPLE_TO_CHUNK_MAPPING("stsc"),
// SAMPLE_SIZE("stsz"),
// STANDARD_CHUNK_OFFSET_TABLE("stco"),
// WIDE_CHUNK_OFFSET_TABLE("co64"),
// FILE_TYPE("ftyp"),
// QUICK_TIME("qt "),
// WIDE("wide"),
// DATA_HANDLER("dhlr");
// /**
// * String representation of AtomType that must have exactly 4 characters
// */
// private final String stringRepresentation;
//
// AtomType(String stringRepresentation) {
// this.stringRepresentation = stringRepresentation;
// }
//
// public String toStringRepresentation() {
// return stringRepresentation;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IORuntimeException.java
// public final class IORuntimeException extends AndroidScreenCastRuntimeException {
//
// public IORuntimeException(String message, IOException cause) {
// super(message, cause);
// }
//
// public IORuntimeException(IOException cause) {
// super(cause);
// }
//
// public IORuntimeException(String message, IOException cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
| import static com.google.common.base.Preconditions.checkNotNull;
import com.github.xsavikx.androidscreencast.api.recording.atom.AtomType;
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import static com.google.common.base.Preconditions.checkArgument; | *
* @param v The value
* @throws java.io.IOException
*/
void writeShort(int v) throws IOException {
out.write((v >> 8) & 0xff);
out.write((v >>> 0) & 0xff);
incCount(2);
}
/**
* Writes an Atom Type identifier (4 bytes).
*
* @param type A string with a length of 4 characters.
*/
private void writeType(String type) throws IOException {
checkArgument(type.length() == 4, "Type string must have exactly 4 characters. type=%s", type);
try {
out.write(type.getBytes(StandardCharsets.US_ASCII), 0, 4);
incCount(4);
} catch (UnsupportedEncodingException e) {
throw new InternalError(e.toString());
}
}
/**
* Writes an Atom Type identifier (4 bytes).
*
* @param atomType AtomType to be written
*/ | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/recording/atom/AtomType.java
// public enum AtomType {
// MEDIA_DATA("mdat"),
// MOVIE("moov"),
// MOVIE_HEADER("mvhd"),
// TRACK("trak"),
// TRACK_HEADER("tkhd"),
// MEDIA("mdia"),
// MEDIA_HEADER("mdhd"),
// HANDLER("hdlr"),
// MEDIA_HANDLER("mhlr"),
// VIDEO("vide"),
// MEDIA_INFORMATION("minf"),
// VIDEO_MEDIA_INFORMATION("vmhd"),
// FILE_ALIAS("alis"),
// DATA_INFORMATION("dinf"),
// DATA_REFERENCE("dref"),
// SAMPLE_TABLE("stbl"),
// SAMPLE_DESCRIPTION("stsd"),
// RAW("raw "),
// JAVA("java"),
// JPEG("jpeg"),
// PNG("png "),
// TIME_TO_SAMPLE_MAPPING("stts"),
// SAMPLE_TO_CHUNK_MAPPING("stsc"),
// SAMPLE_SIZE("stsz"),
// STANDARD_CHUNK_OFFSET_TABLE("stco"),
// WIDE_CHUNK_OFFSET_TABLE("co64"),
// FILE_TYPE("ftyp"),
// QUICK_TIME("qt "),
// WIDE("wide"),
// DATA_HANDLER("dhlr");
// /**
// * String representation of AtomType that must have exactly 4 characters
// */
// private final String stringRepresentation;
//
// AtomType(String stringRepresentation) {
// this.stringRepresentation = stringRepresentation;
// }
//
// public String toStringRepresentation() {
// return stringRepresentation;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IORuntimeException.java
// public final class IORuntimeException extends AndroidScreenCastRuntimeException {
//
// public IORuntimeException(String message, IOException cause) {
// super(message, cause);
// }
//
// public IORuntimeException(IOException cause) {
// super(cause);
// }
//
// public IORuntimeException(String message, IOException cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/recording/DataAtomOutputStream.java
import static com.google.common.base.Preconditions.checkNotNull;
import com.github.xsavikx.androidscreencast.api.recording.atom.AtomType;
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import static com.google.common.base.Preconditions.checkArgument;
*
* @param v The value
* @throws java.io.IOException
*/
void writeShort(int v) throws IOException {
out.write((v >> 8) & 0xff);
out.write((v >>> 0) & 0xff);
incCount(2);
}
/**
* Writes an Atom Type identifier (4 bytes).
*
* @param type A string with a length of 4 characters.
*/
private void writeType(String type) throws IOException {
checkArgument(type.length() == 4, "Type string must have exactly 4 characters. type=%s", type);
try {
out.write(type.getBytes(StandardCharsets.US_ASCII), 0, 4);
incCount(4);
} catch (UnsupportedEncodingException e) {
throw new InternalError(e.toString());
}
}
/**
* Writes an Atom Type identifier (4 bytes).
*
* @param atomType AtomType to be written
*/ | public void writeType(AtomType atomType) throws IOException { |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/api/recording/DataAtomOutputStream.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/recording/atom/AtomType.java
// public enum AtomType {
// MEDIA_DATA("mdat"),
// MOVIE("moov"),
// MOVIE_HEADER("mvhd"),
// TRACK("trak"),
// TRACK_HEADER("tkhd"),
// MEDIA("mdia"),
// MEDIA_HEADER("mdhd"),
// HANDLER("hdlr"),
// MEDIA_HANDLER("mhlr"),
// VIDEO("vide"),
// MEDIA_INFORMATION("minf"),
// VIDEO_MEDIA_INFORMATION("vmhd"),
// FILE_ALIAS("alis"),
// DATA_INFORMATION("dinf"),
// DATA_REFERENCE("dref"),
// SAMPLE_TABLE("stbl"),
// SAMPLE_DESCRIPTION("stsd"),
// RAW("raw "),
// JAVA("java"),
// JPEG("jpeg"),
// PNG("png "),
// TIME_TO_SAMPLE_MAPPING("stts"),
// SAMPLE_TO_CHUNK_MAPPING("stsc"),
// SAMPLE_SIZE("stsz"),
// STANDARD_CHUNK_OFFSET_TABLE("stco"),
// WIDE_CHUNK_OFFSET_TABLE("co64"),
// FILE_TYPE("ftyp"),
// QUICK_TIME("qt "),
// WIDE("wide"),
// DATA_HANDLER("dhlr");
// /**
// * String representation of AtomType that must have exactly 4 characters
// */
// private final String stringRepresentation;
//
// AtomType(String stringRepresentation) {
// this.stringRepresentation = stringRepresentation;
// }
//
// public String toStringRepresentation() {
// return stringRepresentation;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IORuntimeException.java
// public final class IORuntimeException extends AndroidScreenCastRuntimeException {
//
// public IORuntimeException(String message, IOException cause) {
// super(message, cause);
// }
//
// public IORuntimeException(IOException cause) {
// super(cause);
// }
//
// public IORuntimeException(String message, IOException cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
| import static com.google.common.base.Preconditions.checkNotNull;
import com.github.xsavikx.androidscreencast.api.recording.atom.AtomType;
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import static com.google.common.base.Preconditions.checkArgument; | public void writeType(AtomType atomType) throws IOException {
checkNotNull(atomType, "AtomType should not be null");
writeType(atomType.toStringRepresentation());
}
/**
* Writes an unsigned 32 bit integer value.
*
* @param v The value
* @throws java.io.IOException
*/
public void writeUInt(long v) throws IOException {
out.write((int) ((v >>> 24) & 0xff));
out.write((int) ((v >>> 16) & 0xff));
out.write((int) ((v >>> 8) & 0xff));
out.write((int) ((v >>> 0) & 0xff));
incCount(4);
}
void writeUShort(int v) throws IOException {
out.write((v >> 8) & 0xff);
out.write((v >>> 0) & 0xff);
incCount(2);
}
@Override
public void close() {
try {
flush();
} catch (IOException e) { | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/recording/atom/AtomType.java
// public enum AtomType {
// MEDIA_DATA("mdat"),
// MOVIE("moov"),
// MOVIE_HEADER("mvhd"),
// TRACK("trak"),
// TRACK_HEADER("tkhd"),
// MEDIA("mdia"),
// MEDIA_HEADER("mdhd"),
// HANDLER("hdlr"),
// MEDIA_HANDLER("mhlr"),
// VIDEO("vide"),
// MEDIA_INFORMATION("minf"),
// VIDEO_MEDIA_INFORMATION("vmhd"),
// FILE_ALIAS("alis"),
// DATA_INFORMATION("dinf"),
// DATA_REFERENCE("dref"),
// SAMPLE_TABLE("stbl"),
// SAMPLE_DESCRIPTION("stsd"),
// RAW("raw "),
// JAVA("java"),
// JPEG("jpeg"),
// PNG("png "),
// TIME_TO_SAMPLE_MAPPING("stts"),
// SAMPLE_TO_CHUNK_MAPPING("stsc"),
// SAMPLE_SIZE("stsz"),
// STANDARD_CHUNK_OFFSET_TABLE("stco"),
// WIDE_CHUNK_OFFSET_TABLE("co64"),
// FILE_TYPE("ftyp"),
// QUICK_TIME("qt "),
// WIDE("wide"),
// DATA_HANDLER("dhlr");
// /**
// * String representation of AtomType that must have exactly 4 characters
// */
// private final String stringRepresentation;
//
// AtomType(String stringRepresentation) {
// this.stringRepresentation = stringRepresentation;
// }
//
// public String toStringRepresentation() {
// return stringRepresentation;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IORuntimeException.java
// public final class IORuntimeException extends AndroidScreenCastRuntimeException {
//
// public IORuntimeException(String message, IOException cause) {
// super(message, cause);
// }
//
// public IORuntimeException(IOException cause) {
// super(cause);
// }
//
// public IORuntimeException(String message, IOException cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/recording/DataAtomOutputStream.java
import static com.google.common.base.Preconditions.checkNotNull;
import com.github.xsavikx.androidscreencast.api.recording.atom.AtomType;
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import static com.google.common.base.Preconditions.checkArgument;
public void writeType(AtomType atomType) throws IOException {
checkNotNull(atomType, "AtomType should not be null");
writeType(atomType.toStringRepresentation());
}
/**
* Writes an unsigned 32 bit integer value.
*
* @param v The value
* @throws java.io.IOException
*/
public void writeUInt(long v) throws IOException {
out.write((int) ((v >>> 24) & 0xff));
out.write((int) ((v >>> 16) & 0xff));
out.write((int) ((v >>> 8) & 0xff));
out.write((int) ((v >>> 0) & 0xff));
incCount(4);
}
void writeUShort(int v) throws IOException {
out.write((v >> 8) & 0xff);
out.write((v >>> 0) & 0xff);
incCount(2);
}
@Override
public void close() {
try {
flush();
} catch (IOException e) { | throw new IORuntimeException(e); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/api/adb/AndroidDebugBridgeWrapper.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IllegalAdbConfigurationException.java
// public final class IllegalAdbConfigurationException extends AndroidScreenCastRuntimeException {
//
// public IllegalAdbConfigurationException(String adbPath) {
// super(String.format("Exception happened during running your ADB instance. Probably ADB path is misconfigured. ADB path='%s'", adbPath));
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/util/StringUtils.java
// public final class StringUtils {
//
// private StringUtils() {
// }
//
// public static boolean isNotEmpty(final CharSequence charSequence) {
// return charSequence != null && charSequence.length() > 0;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfigurationPropertyKeys.java
// public static final String ADB_PATH_KEY = "adb.path";
| import com.android.ddmlib.AndroidDebugBridge;
import com.android.ddmlib.IDevice;
import com.github.xsavikx.androidscreencast.exception.IllegalAdbConfigurationException;
import com.github.xsavikx.androidscreencast.util.StringUtils;
import com.google.common.annotations.VisibleForTesting;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.IOException;
import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.ADB_PATH_KEY; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api.adb;
@Singleton
public class AndroidDebugBridgeWrapper {
private final String adbPath;
private AndroidDebugBridge adb;
@Inject | // Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IllegalAdbConfigurationException.java
// public final class IllegalAdbConfigurationException extends AndroidScreenCastRuntimeException {
//
// public IllegalAdbConfigurationException(String adbPath) {
// super(String.format("Exception happened during running your ADB instance. Probably ADB path is misconfigured. ADB path='%s'", adbPath));
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/util/StringUtils.java
// public final class StringUtils {
//
// private StringUtils() {
// }
//
// public static boolean isNotEmpty(final CharSequence charSequence) {
// return charSequence != null && charSequence.length() > 0;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfigurationPropertyKeys.java
// public static final String ADB_PATH_KEY = "adb.path";
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/adb/AndroidDebugBridgeWrapper.java
import com.android.ddmlib.AndroidDebugBridge;
import com.android.ddmlib.IDevice;
import com.github.xsavikx.androidscreencast.exception.IllegalAdbConfigurationException;
import com.github.xsavikx.androidscreencast.util.StringUtils;
import com.google.common.annotations.VisibleForTesting;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.IOException;
import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.ADB_PATH_KEY;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api.adb;
@Singleton
public class AndroidDebugBridgeWrapper {
private final String adbPath;
private AndroidDebugBridge adb;
@Inject | public AndroidDebugBridgeWrapper(@Named(ADB_PATH_KEY) String adbPath) { |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/api/adb/AndroidDebugBridgeWrapper.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IllegalAdbConfigurationException.java
// public final class IllegalAdbConfigurationException extends AndroidScreenCastRuntimeException {
//
// public IllegalAdbConfigurationException(String adbPath) {
// super(String.format("Exception happened during running your ADB instance. Probably ADB path is misconfigured. ADB path='%s'", adbPath));
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/util/StringUtils.java
// public final class StringUtils {
//
// private StringUtils() {
// }
//
// public static boolean isNotEmpty(final CharSequence charSequence) {
// return charSequence != null && charSequence.length() > 0;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfigurationPropertyKeys.java
// public static final String ADB_PATH_KEY = "adb.path";
| import com.android.ddmlib.AndroidDebugBridge;
import com.android.ddmlib.IDevice;
import com.github.xsavikx.androidscreencast.exception.IllegalAdbConfigurationException;
import com.github.xsavikx.androidscreencast.util.StringUtils;
import com.google.common.annotations.VisibleForTesting;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.IOException;
import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.ADB_PATH_KEY; | public IDevice[] getDevices() {
return getAdb().getDevices();
}
public boolean hasInitialDeviceList() {
return getAdb().hasInitialDeviceList();
}
public void stop() {
if (hasAdbPathFilled()) {
AndroidDebugBridge.disconnectBridge();
}
AndroidDebugBridge.terminate();
}
private AndroidDebugBridge getAdb() {
if (adb == null) {
init();
}
return adb;
}
private void init() {
if (adb != null) {
return;
}
try {
adb = createAndroidDebugBridge();
} catch (IllegalArgumentException e) {
if (hasAdbProcFailed(e)) { | // Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IllegalAdbConfigurationException.java
// public final class IllegalAdbConfigurationException extends AndroidScreenCastRuntimeException {
//
// public IllegalAdbConfigurationException(String adbPath) {
// super(String.format("Exception happened during running your ADB instance. Probably ADB path is misconfigured. ADB path='%s'", adbPath));
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/util/StringUtils.java
// public final class StringUtils {
//
// private StringUtils() {
// }
//
// public static boolean isNotEmpty(final CharSequence charSequence) {
// return charSequence != null && charSequence.length() > 0;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfigurationPropertyKeys.java
// public static final String ADB_PATH_KEY = "adb.path";
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/adb/AndroidDebugBridgeWrapper.java
import com.android.ddmlib.AndroidDebugBridge;
import com.android.ddmlib.IDevice;
import com.github.xsavikx.androidscreencast.exception.IllegalAdbConfigurationException;
import com.github.xsavikx.androidscreencast.util.StringUtils;
import com.google.common.annotations.VisibleForTesting;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.IOException;
import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.ADB_PATH_KEY;
public IDevice[] getDevices() {
return getAdb().getDevices();
}
public boolean hasInitialDeviceList() {
return getAdb().hasInitialDeviceList();
}
public void stop() {
if (hasAdbPathFilled()) {
AndroidDebugBridge.disconnectBridge();
}
AndroidDebugBridge.terminate();
}
private AndroidDebugBridge getAdb() {
if (adb == null) {
init();
}
return adb;
}
private void init() {
if (adb != null) {
return;
}
try {
adb = createAndroidDebugBridge();
} catch (IllegalArgumentException e) {
if (hasAdbProcFailed(e)) { | throw new IllegalAdbConfigurationException(adbPath); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/api/adb/AndroidDebugBridgeWrapper.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IllegalAdbConfigurationException.java
// public final class IllegalAdbConfigurationException extends AndroidScreenCastRuntimeException {
//
// public IllegalAdbConfigurationException(String adbPath) {
// super(String.format("Exception happened during running your ADB instance. Probably ADB path is misconfigured. ADB path='%s'", adbPath));
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/util/StringUtils.java
// public final class StringUtils {
//
// private StringUtils() {
// }
//
// public static boolean isNotEmpty(final CharSequence charSequence) {
// return charSequence != null && charSequence.length() > 0;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfigurationPropertyKeys.java
// public static final String ADB_PATH_KEY = "adb.path";
| import com.android.ddmlib.AndroidDebugBridge;
import com.android.ddmlib.IDevice;
import com.github.xsavikx.androidscreencast.exception.IllegalAdbConfigurationException;
import com.github.xsavikx.androidscreencast.util.StringUtils;
import com.google.common.annotations.VisibleForTesting;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.IOException;
import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.ADB_PATH_KEY; | if (adb == null) {
init();
}
return adb;
}
private void init() {
if (adb != null) {
return;
}
try {
adb = createAndroidDebugBridge();
} catch (IllegalArgumentException e) {
if (hasAdbProcFailed(e)) {
throw new IllegalAdbConfigurationException(adbPath);
}
throw e;
}
}
@VisibleForTesting
AndroidDebugBridge createAndroidDebugBridge() {
AndroidDebugBridge.initIfNeeded(false);
if (hasAdbPathFilled()) {
return AndroidDebugBridge.createBridge(adbPath, false);
}
return AndroidDebugBridge.createBridge();
}
private boolean hasAdbPathFilled() { | // Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IllegalAdbConfigurationException.java
// public final class IllegalAdbConfigurationException extends AndroidScreenCastRuntimeException {
//
// public IllegalAdbConfigurationException(String adbPath) {
// super(String.format("Exception happened during running your ADB instance. Probably ADB path is misconfigured. ADB path='%s'", adbPath));
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/util/StringUtils.java
// public final class StringUtils {
//
// private StringUtils() {
// }
//
// public static boolean isNotEmpty(final CharSequence charSequence) {
// return charSequence != null && charSequence.length() > 0;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfigurationPropertyKeys.java
// public static final String ADB_PATH_KEY = "adb.path";
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/adb/AndroidDebugBridgeWrapper.java
import com.android.ddmlib.AndroidDebugBridge;
import com.android.ddmlib.IDevice;
import com.github.xsavikx.androidscreencast.exception.IllegalAdbConfigurationException;
import com.github.xsavikx.androidscreencast.util.StringUtils;
import com.google.common.annotations.VisibleForTesting;
import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;
import java.io.IOException;
import static com.github.xsavikx.androidscreencast.configuration.ApplicationConfigurationPropertyKeys.ADB_PATH_KEY;
if (adb == null) {
init();
}
return adb;
}
private void init() {
if (adb != null) {
return;
}
try {
adb = createAndroidDebugBridge();
} catch (IllegalArgumentException e) {
if (hasAdbProcFailed(e)) {
throw new IllegalAdbConfigurationException(adbPath);
}
throw e;
}
}
@VisibleForTesting
AndroidDebugBridge createAndroidDebugBridge() {
AndroidDebugBridge.initIfNeeded(false);
if (hasAdbPathFilled()) {
return AndroidDebugBridge.createBridge(adbPath, false);
}
return AndroidDebugBridge.createBridge();
}
private boolean hasAdbPathFilled() { | return StringUtils.isNotEmpty(adbPath); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfiguration.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
| import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.configuration;
@Singleton
public class ApplicationConfiguration {
private static final String PROPERTIES_LOCATION = "./app.properties";
private final Properties properties;
@Inject
public ApplicationConfiguration() {
properties = initProperties();
}
private Properties initProperties() {
final Properties properties = new Properties();
loadProperties(properties, PROPERTIES_LOCATION);
return properties;
}
private void loadProperties(final Properties properties, final String propertiesLocation) {
final File propertiesFile = new File(propertiesLocation);
if (propertiesFile.exists()) {
try (final FileInputStream fis = new FileInputStream(propertiesFile)) {
properties.load(fis);
} catch (final IOException e) { | // Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/configuration/ApplicationConfiguration.java
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.configuration;
@Singleton
public class ApplicationConfiguration {
private static final String PROPERTIES_LOCATION = "./app.properties";
private final Properties properties;
@Inject
public ApplicationConfiguration() {
properties = initProperties();
}
private Properties initProperties() {
final Properties properties = new Properties();
loadProperties(properties, PROPERTIES_LOCATION);
return properties;
}
private void loadProperties(final Properties properties, final String propertiesLocation) {
final File propertiesFile = new File(propertiesLocation);
if (propertiesFile.exists()) {
try (final FileInputStream fis = new FileInputStream(propertiesFile)) {
properties.load(fis);
} catch (final IOException e) { | throw new AndroidScreenCastRuntimeException(e); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/api/recording/atom/Atom.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IORuntimeException.java
// public final class IORuntimeException extends AndroidScreenCastRuntimeException {
//
// public IORuntimeException(String message, IOException cause) {
// super(message, cause);
// }
//
// public IORuntimeException(IOException cause) {
// super(cause);
// }
//
// public IORuntimeException(String message, IOException cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
| import static com.google.common.base.Preconditions.checkNotNull;
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
import javax.imageio.stream.ImageOutputStream;
import java.io.IOException; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api.recording.atom;
/**
* Atom base class.
*/
abstract class Atom {
static final long MAXIMUM_ATOM_SIZE = 0xffffffffL;
/**
* The type of the atom. A String with the length of 4 characters.
*/
final AtomType type;
protected final ImageOutputStream out;
/**
* The offset of the atom relative to the start of the ImageOutputStream.
*/
long offset;
/**
* Shows whether current atom processing is finished or not
*/
boolean finished;
/**
* Creates a new Atom at the current position of the ImageOutputStream.
*
* @param type The type of the atom. A string with a length of 4 characters.
*/
Atom(AtomType type, ImageOutputStream imageOutputStream) {
checkNotNull(type, "Type should not be null");
checkNotNull(imageOutputStream, "ImageOutputStream should not be null");
this.out = imageOutputStream;
this.type = type;
try {
offset = out.getStreamPosition();
} catch (IOException e) { | // Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IORuntimeException.java
// public final class IORuntimeException extends AndroidScreenCastRuntimeException {
//
// public IORuntimeException(String message, IOException cause) {
// super(message, cause);
// }
//
// public IORuntimeException(IOException cause) {
// super(cause);
// }
//
// public IORuntimeException(String message, IOException cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/recording/atom/Atom.java
import static com.google.common.base.Preconditions.checkNotNull;
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
import javax.imageio.stream.ImageOutputStream;
import java.io.IOException;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api.recording.atom;
/**
* Atom base class.
*/
abstract class Atom {
static final long MAXIMUM_ATOM_SIZE = 0xffffffffL;
/**
* The type of the atom. A String with the length of 4 characters.
*/
final AtomType type;
protected final ImageOutputStream out;
/**
* The offset of the atom relative to the start of the ImageOutputStream.
*/
long offset;
/**
* Shows whether current atom processing is finished or not
*/
boolean finished;
/**
* Creates a new Atom at the current position of the ImageOutputStream.
*
* @param type The type of the atom. A string with a length of 4 characters.
*/
Atom(AtomType type, ImageOutputStream imageOutputStream) {
checkNotNull(type, "Type should not be null");
checkNotNull(imageOutputStream, "ImageOutputStream should not be null");
this.out = imageOutputStream;
this.type = type;
try {
offset = out.getStreamPosition();
} catch (IOException e) { | throw new IORuntimeException(e); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/KeyCommand.java
// public final class KeyCommand extends InputCommand {
//
// private final int code;
// private boolean longpress;
//
// public KeyCommand(int keyCode) {
// this.code = keyCode;
// }
//
// private KeyCommand(InputKeyEvent inputKeyEvent) {
// code = inputKeyEvent.getCode();
// }
//
// public KeyCommand(int keyCode, boolean longpress) {
// this(keyCode);
// this.longpress = longpress;
// }
//
// public KeyCommand(InputKeyEvent inputKeyEvent, boolean longpress) {
// this(inputKeyEvent);
// this.longpress = longpress;
// }
//
// public void setLongPress(boolean longpress) {
// this.longpress = longpress;
// }
//
// @Override
// protected String getCommandPart() {
// StringBuilder stringBuilder = new StringBuilder("keyevent");
// if (longpress) {
// stringBuilder.append(" --longpress");
// }
// stringBuilder.append(' ').append(code);
// return stringBuilder.toString();
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/injector/KeyCodeConverter.java
// public final class KeyCodeConverter {
//
// private KeyCodeConverter() {
// }
//
// public static int getKeyCode(KeyEvent e) {
// log().debug("Getting key code for event: {}.", e);
// int code = InputKeyEvent.KEYCODE_UNKNOWN.getCode();
// char c = e.getKeyChar();
// int keyCode = e.getKeyCode();
// InputKeyEvent inputKeyEvent = InputKeyEvent.getByCharacterOrKeyCode(Character.toLowerCase(c), keyCode);
// if (inputKeyEvent != null) {
// code = inputKeyEvent.getCode();
// }
// log().debug("Received KeyEvent={}. Produced KeyCode={}", e, code);
// return code;
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(KeyCodeConverter.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java
// public final class MainComponentProvider {
// private static MainComponent INSTANCE;
//
// private MainComponentProvider() {
//
// }
//
// public static MainComponent mainComponent() {
// if (INSTANCE == null) {
// INSTANCE = DaggerMainComponent.create();
// }
// return INSTANCE;
// }
// }
| import com.github.xsavikx.androidscreencast.api.command.KeyCommand;
import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.api.injector.KeyCodeConverter;
import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.ui.interaction;
public final class KeyEventDispatcherImpl implements KeyEventDispatcher {
private final Window window; | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/KeyCommand.java
// public final class KeyCommand extends InputCommand {
//
// private final int code;
// private boolean longpress;
//
// public KeyCommand(int keyCode) {
// this.code = keyCode;
// }
//
// private KeyCommand(InputKeyEvent inputKeyEvent) {
// code = inputKeyEvent.getCode();
// }
//
// public KeyCommand(int keyCode, boolean longpress) {
// this(keyCode);
// this.longpress = longpress;
// }
//
// public KeyCommand(InputKeyEvent inputKeyEvent, boolean longpress) {
// this(inputKeyEvent);
// this.longpress = longpress;
// }
//
// public void setLongPress(boolean longpress) {
// this.longpress = longpress;
// }
//
// @Override
// protected String getCommandPart() {
// StringBuilder stringBuilder = new StringBuilder("keyevent");
// if (longpress) {
// stringBuilder.append(" --longpress");
// }
// stringBuilder.append(' ').append(code);
// return stringBuilder.toString();
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/injector/KeyCodeConverter.java
// public final class KeyCodeConverter {
//
// private KeyCodeConverter() {
// }
//
// public static int getKeyCode(KeyEvent e) {
// log().debug("Getting key code for event: {}.", e);
// int code = InputKeyEvent.KEYCODE_UNKNOWN.getCode();
// char c = e.getKeyChar();
// int keyCode = e.getKeyCode();
// InputKeyEvent inputKeyEvent = InputKeyEvent.getByCharacterOrKeyCode(Character.toLowerCase(c), keyCode);
// if (inputKeyEvent != null) {
// code = inputKeyEvent.getCode();
// }
// log().debug("Received KeyEvent={}. Produced KeyCode={}", e, code);
// return code;
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(KeyCodeConverter.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java
// public final class MainComponentProvider {
// private static MainComponent INSTANCE;
//
// private MainComponentProvider() {
//
// }
//
// public static MainComponent mainComponent() {
// if (INSTANCE == null) {
// INSTANCE = DaggerMainComponent.create();
// }
// return INSTANCE;
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java
import com.github.xsavikx.androidscreencast.api.command.KeyCommand;
import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.api.injector.KeyCodeConverter;
import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.ui.interaction;
public final class KeyEventDispatcherImpl implements KeyEventDispatcher {
private final Window window; | private CommandExecutor commandExecutor; |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/KeyCommand.java
// public final class KeyCommand extends InputCommand {
//
// private final int code;
// private boolean longpress;
//
// public KeyCommand(int keyCode) {
// this.code = keyCode;
// }
//
// private KeyCommand(InputKeyEvent inputKeyEvent) {
// code = inputKeyEvent.getCode();
// }
//
// public KeyCommand(int keyCode, boolean longpress) {
// this(keyCode);
// this.longpress = longpress;
// }
//
// public KeyCommand(InputKeyEvent inputKeyEvent, boolean longpress) {
// this(inputKeyEvent);
// this.longpress = longpress;
// }
//
// public void setLongPress(boolean longpress) {
// this.longpress = longpress;
// }
//
// @Override
// protected String getCommandPart() {
// StringBuilder stringBuilder = new StringBuilder("keyevent");
// if (longpress) {
// stringBuilder.append(" --longpress");
// }
// stringBuilder.append(' ').append(code);
// return stringBuilder.toString();
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/injector/KeyCodeConverter.java
// public final class KeyCodeConverter {
//
// private KeyCodeConverter() {
// }
//
// public static int getKeyCode(KeyEvent e) {
// log().debug("Getting key code for event: {}.", e);
// int code = InputKeyEvent.KEYCODE_UNKNOWN.getCode();
// char c = e.getKeyChar();
// int keyCode = e.getKeyCode();
// InputKeyEvent inputKeyEvent = InputKeyEvent.getByCharacterOrKeyCode(Character.toLowerCase(c), keyCode);
// if (inputKeyEvent != null) {
// code = inputKeyEvent.getCode();
// }
// log().debug("Received KeyEvent={}. Produced KeyCode={}", e, code);
// return code;
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(KeyCodeConverter.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java
// public final class MainComponentProvider {
// private static MainComponent INSTANCE;
//
// private MainComponentProvider() {
//
// }
//
// public static MainComponent mainComponent() {
// if (INSTANCE == null) {
// INSTANCE = DaggerMainComponent.create();
// }
// return INSTANCE;
// }
// }
| import com.github.xsavikx.androidscreencast.api.command.KeyCommand;
import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.api.injector.KeyCodeConverter;
import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.ui.interaction;
public final class KeyEventDispatcherImpl implements KeyEventDispatcher {
private final Window window;
private CommandExecutor commandExecutor; | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/KeyCommand.java
// public final class KeyCommand extends InputCommand {
//
// private final int code;
// private boolean longpress;
//
// public KeyCommand(int keyCode) {
// this.code = keyCode;
// }
//
// private KeyCommand(InputKeyEvent inputKeyEvent) {
// code = inputKeyEvent.getCode();
// }
//
// public KeyCommand(int keyCode, boolean longpress) {
// this(keyCode);
// this.longpress = longpress;
// }
//
// public KeyCommand(InputKeyEvent inputKeyEvent, boolean longpress) {
// this(inputKeyEvent);
// this.longpress = longpress;
// }
//
// public void setLongPress(boolean longpress) {
// this.longpress = longpress;
// }
//
// @Override
// protected String getCommandPart() {
// StringBuilder stringBuilder = new StringBuilder("keyevent");
// if (longpress) {
// stringBuilder.append(" --longpress");
// }
// stringBuilder.append(' ').append(code);
// return stringBuilder.toString();
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/injector/KeyCodeConverter.java
// public final class KeyCodeConverter {
//
// private KeyCodeConverter() {
// }
//
// public static int getKeyCode(KeyEvent e) {
// log().debug("Getting key code for event: {}.", e);
// int code = InputKeyEvent.KEYCODE_UNKNOWN.getCode();
// char c = e.getKeyChar();
// int keyCode = e.getKeyCode();
// InputKeyEvent inputKeyEvent = InputKeyEvent.getByCharacterOrKeyCode(Character.toLowerCase(c), keyCode);
// if (inputKeyEvent != null) {
// code = inputKeyEvent.getCode();
// }
// log().debug("Received KeyEvent={}. Produced KeyCode={}", e, code);
// return code;
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(KeyCodeConverter.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java
// public final class MainComponentProvider {
// private static MainComponent INSTANCE;
//
// private MainComponentProvider() {
//
// }
//
// public static MainComponent mainComponent() {
// if (INSTANCE == null) {
// INSTANCE = DaggerMainComponent.create();
// }
// return INSTANCE;
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java
import com.github.xsavikx.androidscreencast.api.command.KeyCommand;
import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.api.injector.KeyCodeConverter;
import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.ui.interaction;
public final class KeyEventDispatcherImpl implements KeyEventDispatcher {
private final Window window;
private CommandExecutor commandExecutor; | private InputCommandFactory inputCommandFactory; |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/KeyCommand.java
// public final class KeyCommand extends InputCommand {
//
// private final int code;
// private boolean longpress;
//
// public KeyCommand(int keyCode) {
// this.code = keyCode;
// }
//
// private KeyCommand(InputKeyEvent inputKeyEvent) {
// code = inputKeyEvent.getCode();
// }
//
// public KeyCommand(int keyCode, boolean longpress) {
// this(keyCode);
// this.longpress = longpress;
// }
//
// public KeyCommand(InputKeyEvent inputKeyEvent, boolean longpress) {
// this(inputKeyEvent);
// this.longpress = longpress;
// }
//
// public void setLongPress(boolean longpress) {
// this.longpress = longpress;
// }
//
// @Override
// protected String getCommandPart() {
// StringBuilder stringBuilder = new StringBuilder("keyevent");
// if (longpress) {
// stringBuilder.append(" --longpress");
// }
// stringBuilder.append(' ').append(code);
// return stringBuilder.toString();
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/injector/KeyCodeConverter.java
// public final class KeyCodeConverter {
//
// private KeyCodeConverter() {
// }
//
// public static int getKeyCode(KeyEvent e) {
// log().debug("Getting key code for event: {}.", e);
// int code = InputKeyEvent.KEYCODE_UNKNOWN.getCode();
// char c = e.getKeyChar();
// int keyCode = e.getKeyCode();
// InputKeyEvent inputKeyEvent = InputKeyEvent.getByCharacterOrKeyCode(Character.toLowerCase(c), keyCode);
// if (inputKeyEvent != null) {
// code = inputKeyEvent.getCode();
// }
// log().debug("Received KeyEvent={}. Produced KeyCode={}", e, code);
// return code;
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(KeyCodeConverter.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java
// public final class MainComponentProvider {
// private static MainComponent INSTANCE;
//
// private MainComponentProvider() {
//
// }
//
// public static MainComponent mainComponent() {
// if (INSTANCE == null) {
// INSTANCE = DaggerMainComponent.create();
// }
// return INSTANCE;
// }
// }
| import com.github.xsavikx.androidscreencast.api.command.KeyCommand;
import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.api.injector.KeyCodeConverter;
import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.ui.interaction;
public final class KeyEventDispatcherImpl implements KeyEventDispatcher {
private final Window window;
private CommandExecutor commandExecutor;
private InputCommandFactory inputCommandFactory;
KeyEventDispatcherImpl(Window frame) {
this.window = frame;
}
@Override
public boolean dispatchKeyEvent(final KeyEvent e) {
if (!window.isActive())
return false;
if (e.getID() == KeyEvent.KEY_TYPED) { | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/KeyCommand.java
// public final class KeyCommand extends InputCommand {
//
// private final int code;
// private boolean longpress;
//
// public KeyCommand(int keyCode) {
// this.code = keyCode;
// }
//
// private KeyCommand(InputKeyEvent inputKeyEvent) {
// code = inputKeyEvent.getCode();
// }
//
// public KeyCommand(int keyCode, boolean longpress) {
// this(keyCode);
// this.longpress = longpress;
// }
//
// public KeyCommand(InputKeyEvent inputKeyEvent, boolean longpress) {
// this(inputKeyEvent);
// this.longpress = longpress;
// }
//
// public void setLongPress(boolean longpress) {
// this.longpress = longpress;
// }
//
// @Override
// protected String getCommandPart() {
// StringBuilder stringBuilder = new StringBuilder("keyevent");
// if (longpress) {
// stringBuilder.append(" --longpress");
// }
// stringBuilder.append(' ').append(code);
// return stringBuilder.toString();
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/injector/KeyCodeConverter.java
// public final class KeyCodeConverter {
//
// private KeyCodeConverter() {
// }
//
// public static int getKeyCode(KeyEvent e) {
// log().debug("Getting key code for event: {}.", e);
// int code = InputKeyEvent.KEYCODE_UNKNOWN.getCode();
// char c = e.getKeyChar();
// int keyCode = e.getKeyCode();
// InputKeyEvent inputKeyEvent = InputKeyEvent.getByCharacterOrKeyCode(Character.toLowerCase(c), keyCode);
// if (inputKeyEvent != null) {
// code = inputKeyEvent.getCode();
// }
// log().debug("Received KeyEvent={}. Produced KeyCode={}", e, code);
// return code;
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(KeyCodeConverter.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java
// public final class MainComponentProvider {
// private static MainComponent INSTANCE;
//
// private MainComponentProvider() {
//
// }
//
// public static MainComponent mainComponent() {
// if (INSTANCE == null) {
// INSTANCE = DaggerMainComponent.create();
// }
// return INSTANCE;
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java
import com.github.xsavikx.androidscreencast.api.command.KeyCommand;
import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.api.injector.KeyCodeConverter;
import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.ui.interaction;
public final class KeyEventDispatcherImpl implements KeyEventDispatcher {
private final Window window;
private CommandExecutor commandExecutor;
private InputCommandFactory inputCommandFactory;
KeyEventDispatcherImpl(Window frame) {
this.window = frame;
}
@Override
public boolean dispatchKeyEvent(final KeyEvent e) {
if (!window.isActive())
return false;
if (e.getID() == KeyEvent.KEY_TYPED) { | final int code = KeyCodeConverter.getKeyCode(e); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/KeyCommand.java
// public final class KeyCommand extends InputCommand {
//
// private final int code;
// private boolean longpress;
//
// public KeyCommand(int keyCode) {
// this.code = keyCode;
// }
//
// private KeyCommand(InputKeyEvent inputKeyEvent) {
// code = inputKeyEvent.getCode();
// }
//
// public KeyCommand(int keyCode, boolean longpress) {
// this(keyCode);
// this.longpress = longpress;
// }
//
// public KeyCommand(InputKeyEvent inputKeyEvent, boolean longpress) {
// this(inputKeyEvent);
// this.longpress = longpress;
// }
//
// public void setLongPress(boolean longpress) {
// this.longpress = longpress;
// }
//
// @Override
// protected String getCommandPart() {
// StringBuilder stringBuilder = new StringBuilder("keyevent");
// if (longpress) {
// stringBuilder.append(" --longpress");
// }
// stringBuilder.append(' ').append(code);
// return stringBuilder.toString();
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/injector/KeyCodeConverter.java
// public final class KeyCodeConverter {
//
// private KeyCodeConverter() {
// }
//
// public static int getKeyCode(KeyEvent e) {
// log().debug("Getting key code for event: {}.", e);
// int code = InputKeyEvent.KEYCODE_UNKNOWN.getCode();
// char c = e.getKeyChar();
// int keyCode = e.getKeyCode();
// InputKeyEvent inputKeyEvent = InputKeyEvent.getByCharacterOrKeyCode(Character.toLowerCase(c), keyCode);
// if (inputKeyEvent != null) {
// code = inputKeyEvent.getCode();
// }
// log().debug("Received KeyEvent={}. Produced KeyCode={}", e, code);
// return code;
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(KeyCodeConverter.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java
// public final class MainComponentProvider {
// private static MainComponent INSTANCE;
//
// private MainComponentProvider() {
//
// }
//
// public static MainComponent mainComponent() {
// if (INSTANCE == null) {
// INSTANCE = DaggerMainComponent.create();
// }
// return INSTANCE;
// }
// }
| import com.github.xsavikx.androidscreencast.api.command.KeyCommand;
import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.api.injector.KeyCodeConverter;
import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.ui.interaction;
public final class KeyEventDispatcherImpl implements KeyEventDispatcher {
private final Window window;
private CommandExecutor commandExecutor;
private InputCommandFactory inputCommandFactory;
KeyEventDispatcherImpl(Window frame) {
this.window = frame;
}
@Override
public boolean dispatchKeyEvent(final KeyEvent e) {
if (!window.isActive())
return false;
if (e.getID() == KeyEvent.KEY_TYPED) {
final int code = KeyCodeConverter.getKeyCode(e);
SwingUtilities.invokeLater(() -> { | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/KeyCommand.java
// public final class KeyCommand extends InputCommand {
//
// private final int code;
// private boolean longpress;
//
// public KeyCommand(int keyCode) {
// this.code = keyCode;
// }
//
// private KeyCommand(InputKeyEvent inputKeyEvent) {
// code = inputKeyEvent.getCode();
// }
//
// public KeyCommand(int keyCode, boolean longpress) {
// this(keyCode);
// this.longpress = longpress;
// }
//
// public KeyCommand(InputKeyEvent inputKeyEvent, boolean longpress) {
// this(inputKeyEvent);
// this.longpress = longpress;
// }
//
// public void setLongPress(boolean longpress) {
// this.longpress = longpress;
// }
//
// @Override
// protected String getCommandPart() {
// StringBuilder stringBuilder = new StringBuilder("keyevent");
// if (longpress) {
// stringBuilder.append(" --longpress");
// }
// stringBuilder.append(' ').append(code);
// return stringBuilder.toString();
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/injector/KeyCodeConverter.java
// public final class KeyCodeConverter {
//
// private KeyCodeConverter() {
// }
//
// public static int getKeyCode(KeyEvent e) {
// log().debug("Getting key code for event: {}.", e);
// int code = InputKeyEvent.KEYCODE_UNKNOWN.getCode();
// char c = e.getKeyChar();
// int keyCode = e.getKeyCode();
// InputKeyEvent inputKeyEvent = InputKeyEvent.getByCharacterOrKeyCode(Character.toLowerCase(c), keyCode);
// if (inputKeyEvent != null) {
// code = inputKeyEvent.getCode();
// }
// log().debug("Received KeyEvent={}. Produced KeyCode={}", e, code);
// return code;
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(KeyCodeConverter.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java
// public final class MainComponentProvider {
// private static MainComponent INSTANCE;
//
// private MainComponentProvider() {
//
// }
//
// public static MainComponent mainComponent() {
// if (INSTANCE == null) {
// INSTANCE = DaggerMainComponent.create();
// }
// return INSTANCE;
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java
import com.github.xsavikx.androidscreencast.api.command.KeyCommand;
import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.api.injector.KeyCodeConverter;
import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.ui.interaction;
public final class KeyEventDispatcherImpl implements KeyEventDispatcher {
private final Window window;
private CommandExecutor commandExecutor;
private InputCommandFactory inputCommandFactory;
KeyEventDispatcherImpl(Window frame) {
this.window = frame;
}
@Override
public boolean dispatchKeyEvent(final KeyEvent e) {
if (!window.isActive())
return false;
if (e.getID() == KeyEvent.KEY_TYPED) {
final int code = KeyCodeConverter.getKeyCode(e);
SwingUtilities.invokeLater(() -> { | final KeyCommand command = getInputCommandFactory().getKeyCommand(code); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/KeyCommand.java
// public final class KeyCommand extends InputCommand {
//
// private final int code;
// private boolean longpress;
//
// public KeyCommand(int keyCode) {
// this.code = keyCode;
// }
//
// private KeyCommand(InputKeyEvent inputKeyEvent) {
// code = inputKeyEvent.getCode();
// }
//
// public KeyCommand(int keyCode, boolean longpress) {
// this(keyCode);
// this.longpress = longpress;
// }
//
// public KeyCommand(InputKeyEvent inputKeyEvent, boolean longpress) {
// this(inputKeyEvent);
// this.longpress = longpress;
// }
//
// public void setLongPress(boolean longpress) {
// this.longpress = longpress;
// }
//
// @Override
// protected String getCommandPart() {
// StringBuilder stringBuilder = new StringBuilder("keyevent");
// if (longpress) {
// stringBuilder.append(" --longpress");
// }
// stringBuilder.append(' ').append(code);
// return stringBuilder.toString();
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/injector/KeyCodeConverter.java
// public final class KeyCodeConverter {
//
// private KeyCodeConverter() {
// }
//
// public static int getKeyCode(KeyEvent e) {
// log().debug("Getting key code for event: {}.", e);
// int code = InputKeyEvent.KEYCODE_UNKNOWN.getCode();
// char c = e.getKeyChar();
// int keyCode = e.getKeyCode();
// InputKeyEvent inputKeyEvent = InputKeyEvent.getByCharacterOrKeyCode(Character.toLowerCase(c), keyCode);
// if (inputKeyEvent != null) {
// code = inputKeyEvent.getCode();
// }
// log().debug("Received KeyEvent={}. Produced KeyCode={}", e, code);
// return code;
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(KeyCodeConverter.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java
// public final class MainComponentProvider {
// private static MainComponent INSTANCE;
//
// private MainComponentProvider() {
//
// }
//
// public static MainComponent mainComponent() {
// if (INSTANCE == null) {
// INSTANCE = DaggerMainComponent.create();
// }
// return INSTANCE;
// }
// }
| import com.github.xsavikx.androidscreencast.api.command.KeyCommand;
import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.api.injector.KeyCodeConverter;
import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.ui.interaction;
public final class KeyEventDispatcherImpl implements KeyEventDispatcher {
private final Window window;
private CommandExecutor commandExecutor;
private InputCommandFactory inputCommandFactory;
KeyEventDispatcherImpl(Window frame) {
this.window = frame;
}
@Override
public boolean dispatchKeyEvent(final KeyEvent e) {
if (!window.isActive())
return false;
if (e.getID() == KeyEvent.KEY_TYPED) {
final int code = KeyCodeConverter.getKeyCode(e);
SwingUtilities.invokeLater(() -> {
final KeyCommand command = getInputCommandFactory().getKeyCommand(code);
getCommandExecutor().execute(command);
});
}
return false;
}
private InputCommandFactory getInputCommandFactory() {
if (inputCommandFactory == null) { | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/KeyCommand.java
// public final class KeyCommand extends InputCommand {
//
// private final int code;
// private boolean longpress;
//
// public KeyCommand(int keyCode) {
// this.code = keyCode;
// }
//
// private KeyCommand(InputKeyEvent inputKeyEvent) {
// code = inputKeyEvent.getCode();
// }
//
// public KeyCommand(int keyCode, boolean longpress) {
// this(keyCode);
// this.longpress = longpress;
// }
//
// public KeyCommand(InputKeyEvent inputKeyEvent, boolean longpress) {
// this(inputKeyEvent);
// this.longpress = longpress;
// }
//
// public void setLongPress(boolean longpress) {
// this.longpress = longpress;
// }
//
// @Override
// protected String getCommandPart() {
// StringBuilder stringBuilder = new StringBuilder("keyevent");
// if (longpress) {
// stringBuilder.append(" --longpress");
// }
// stringBuilder.append(' ').append(code);
// return stringBuilder.toString();
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/injector/KeyCodeConverter.java
// public final class KeyCodeConverter {
//
// private KeyCodeConverter() {
// }
//
// public static int getKeyCode(KeyEvent e) {
// log().debug("Getting key code for event: {}.", e);
// int code = InputKeyEvent.KEYCODE_UNKNOWN.getCode();
// char c = e.getKeyChar();
// int keyCode = e.getKeyCode();
// InputKeyEvent inputKeyEvent = InputKeyEvent.getByCharacterOrKeyCode(Character.toLowerCase(c), keyCode);
// if (inputKeyEvent != null) {
// code = inputKeyEvent.getCode();
// }
// log().debug("Received KeyEvent={}. Produced KeyCode={}", e, code);
// return code;
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(KeyCodeConverter.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java
// public final class MainComponentProvider {
// private static MainComponent INSTANCE;
//
// private MainComponentProvider() {
//
// }
//
// public static MainComponent mainComponent() {
// if (INSTANCE == null) {
// INSTANCE = DaggerMainComponent.create();
// }
// return INSTANCE;
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyEventDispatcherImpl.java
import com.github.xsavikx.androidscreencast.api.command.KeyCommand;
import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.api.injector.KeyCodeConverter;
import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.ui.interaction;
public final class KeyEventDispatcherImpl implements KeyEventDispatcher {
private final Window window;
private CommandExecutor commandExecutor;
private InputCommandFactory inputCommandFactory;
KeyEventDispatcherImpl(Window frame) {
this.window = frame;
}
@Override
public boolean dispatchKeyEvent(final KeyEvent e) {
if (!window.isActive())
return false;
if (e.getID() == KeyEvent.KEY_TYPED) {
final int code = KeyCodeConverter.getKeyCode(e);
SwingUtilities.invokeLater(() -> {
final KeyCommand command = getInputCommandFactory().getKeyCommand(code);
getCommandExecutor().execute(command);
});
}
return false;
}
private InputCommandFactory getInputCommandFactory() {
if (inputCommandFactory == null) { | inputCommandFactory = MainComponentProvider.mainComponent().inputCommandFactory(); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/dagger/AppModule.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java
// @Singleton
// public final class AndroidScreencastApplication extends SwingApplication {
//
// private final JFrameMain jFrameMain;
// private final Injector injector;
// private final IDevice iDevice;
// private final AndroidDebugBridgeWrapper wrapper;
// private transient boolean isStopped = false;
//
// @Inject
// public AndroidScreencastApplication(final Injector injector, final IDevice iDevice, final JFrameMain jFrameMain,
// final ApplicationConfiguration applicationConfiguration, AndroidDebugBridgeWrapper wrapper) {
// super(applicationConfiguration);
// this.injector = injector;
// this.iDevice = iDevice;
// this.jFrameMain = jFrameMain;
// this.wrapper = wrapper;
// }
//
// @Override
// public void stop() {
// log().info("Stopping application.");
// if (isStopped) {
// log().warn("Application is already stopped.");
// return;
// }
// injector.stop();
// wrapper.stop();
// for (final Frame frame : Frame.getFrames()) {
// frame.dispose();
// }
// isStopped = true;
// }
//
// @Override
// public void start() {
// log().info("Starting application.");
// if (iDevice == null) {
// log().warn("No valid device was chosen. Please try to chose correct one.");
// stop();
// }
// SwingUtilities.invokeLater(() -> {
// jFrameMain.initialize();
// // Start showing the iDevice screen
// jFrameMain.setTitle(iDevice.getSerialNumber());
// // Show window
// jFrameMain.setVisible(true);
//
// jFrameMain.launchInjector();
// });
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(AndroidScreencastApplication.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/app/Application.java
// public interface Application {
//
// void stop();
//
// void handleException(Thread thread, Throwable ex);
//
// void start();
//
// void init();
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java
// @Singleton
// public final class DeviceChooserApplication extends SwingApplication {
//
// private static final long WAIT_TIMEOUT = 100;
// private final AndroidDebugBridgeWrapper bridge;
// private final long adbWaitSleepCyclesAmount;
// private IDevice device;
//
// @Inject
// public DeviceChooserApplication(final AndroidDebugBridgeWrapper bridge,
// final ApplicationConfiguration applicationConfiguration) {
// super(applicationConfiguration);
// this.bridge = bridge;
// this.adbWaitSleepCyclesAmount = getAdbDeviceTimeout() * 10;
// }
//
// private long getAdbDeviceTimeout() {
// return Long.parseLong(applicationConfiguration.getProperty(ADB_DEVICE_TIMEOUT));
// }
//
// @Override
// public void stop() {
// bridge.stop();
// }
//
// @Override
// public void start() {
// log().info("Starting application");
//
// waitDeviceList(bridge);
//
// final IDevice[] devices = bridge.getDevices();
//
// // Let the user choose the device
// if (devices.length == 1) {
// device = devices[0];
// log().info("1 device was found by ADB");
// } else {
// final JDialogDeviceList jd = new JDialogDeviceList(devices);
// jd.setVisible(true);
// device = jd.getDevice();
// log().info("{} devices were found by ADB", devices.length);
// }
// if (device == null) {
// throw new NoDeviceChosenException();
// }
// log().info("{} was chosen", device.getName());
// }
//
// private void waitDeviceList(final AndroidDebugBridgeWrapper bridge) {
// int count = 0;
// while (!bridge.hasInitialDeviceList()) {
// try {
// Thread.sleep(WAIT_TIMEOUT);
// count++;
// } catch (InterruptedException e) {
// log().warn("waitDeviceList(AndroidDebugBridge) - exception ignored", e);
// }
// if (count > adbWaitSleepCyclesAmount) {
// throw new WaitDeviceListTimeoutException();
// }
// }
// }
//
// public IDevice getDevice() {
// return device;
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(DeviceChooserApplication.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
| import com.android.ddmlib.IDevice;
import com.github.xsavikx.androidscreencast.app.AndroidScreencastApplication;
import com.github.xsavikx.androidscreencast.app.Application;
import com.github.xsavikx.androidscreencast.app.DeviceChooserApplication;
import dagger.Module;
import dagger.Provides;
import javax.inject.Singleton; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.dagger;
@Module
public class AppModule {
@Singleton
@Provides | // Path: src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java
// @Singleton
// public final class AndroidScreencastApplication extends SwingApplication {
//
// private final JFrameMain jFrameMain;
// private final Injector injector;
// private final IDevice iDevice;
// private final AndroidDebugBridgeWrapper wrapper;
// private transient boolean isStopped = false;
//
// @Inject
// public AndroidScreencastApplication(final Injector injector, final IDevice iDevice, final JFrameMain jFrameMain,
// final ApplicationConfiguration applicationConfiguration, AndroidDebugBridgeWrapper wrapper) {
// super(applicationConfiguration);
// this.injector = injector;
// this.iDevice = iDevice;
// this.jFrameMain = jFrameMain;
// this.wrapper = wrapper;
// }
//
// @Override
// public void stop() {
// log().info("Stopping application.");
// if (isStopped) {
// log().warn("Application is already stopped.");
// return;
// }
// injector.stop();
// wrapper.stop();
// for (final Frame frame : Frame.getFrames()) {
// frame.dispose();
// }
// isStopped = true;
// }
//
// @Override
// public void start() {
// log().info("Starting application.");
// if (iDevice == null) {
// log().warn("No valid device was chosen. Please try to chose correct one.");
// stop();
// }
// SwingUtilities.invokeLater(() -> {
// jFrameMain.initialize();
// // Start showing the iDevice screen
// jFrameMain.setTitle(iDevice.getSerialNumber());
// // Show window
// jFrameMain.setVisible(true);
//
// jFrameMain.launchInjector();
// });
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(AndroidScreencastApplication.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/app/Application.java
// public interface Application {
//
// void stop();
//
// void handleException(Thread thread, Throwable ex);
//
// void start();
//
// void init();
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java
// @Singleton
// public final class DeviceChooserApplication extends SwingApplication {
//
// private static final long WAIT_TIMEOUT = 100;
// private final AndroidDebugBridgeWrapper bridge;
// private final long adbWaitSleepCyclesAmount;
// private IDevice device;
//
// @Inject
// public DeviceChooserApplication(final AndroidDebugBridgeWrapper bridge,
// final ApplicationConfiguration applicationConfiguration) {
// super(applicationConfiguration);
// this.bridge = bridge;
// this.adbWaitSleepCyclesAmount = getAdbDeviceTimeout() * 10;
// }
//
// private long getAdbDeviceTimeout() {
// return Long.parseLong(applicationConfiguration.getProperty(ADB_DEVICE_TIMEOUT));
// }
//
// @Override
// public void stop() {
// bridge.stop();
// }
//
// @Override
// public void start() {
// log().info("Starting application");
//
// waitDeviceList(bridge);
//
// final IDevice[] devices = bridge.getDevices();
//
// // Let the user choose the device
// if (devices.length == 1) {
// device = devices[0];
// log().info("1 device was found by ADB");
// } else {
// final JDialogDeviceList jd = new JDialogDeviceList(devices);
// jd.setVisible(true);
// device = jd.getDevice();
// log().info("{} devices were found by ADB", devices.length);
// }
// if (device == null) {
// throw new NoDeviceChosenException();
// }
// log().info("{} was chosen", device.getName());
// }
//
// private void waitDeviceList(final AndroidDebugBridgeWrapper bridge) {
// int count = 0;
// while (!bridge.hasInitialDeviceList()) {
// try {
// Thread.sleep(WAIT_TIMEOUT);
// count++;
// } catch (InterruptedException e) {
// log().warn("waitDeviceList(AndroidDebugBridge) - exception ignored", e);
// }
// if (count > adbWaitSleepCyclesAmount) {
// throw new WaitDeviceListTimeoutException();
// }
// }
// }
//
// public IDevice getDevice() {
// return device;
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(DeviceChooserApplication.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/AppModule.java
import com.android.ddmlib.IDevice;
import com.github.xsavikx.androidscreencast.app.AndroidScreencastApplication;
import com.github.xsavikx.androidscreencast.app.Application;
import com.github.xsavikx.androidscreencast.app.DeviceChooserApplication;
import dagger.Module;
import dagger.Provides;
import javax.inject.Singleton;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.dagger;
@Module
public class AppModule {
@Singleton
@Provides | public static Application application(AndroidScreencastApplication application) { |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/dagger/AppModule.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java
// @Singleton
// public final class AndroidScreencastApplication extends SwingApplication {
//
// private final JFrameMain jFrameMain;
// private final Injector injector;
// private final IDevice iDevice;
// private final AndroidDebugBridgeWrapper wrapper;
// private transient boolean isStopped = false;
//
// @Inject
// public AndroidScreencastApplication(final Injector injector, final IDevice iDevice, final JFrameMain jFrameMain,
// final ApplicationConfiguration applicationConfiguration, AndroidDebugBridgeWrapper wrapper) {
// super(applicationConfiguration);
// this.injector = injector;
// this.iDevice = iDevice;
// this.jFrameMain = jFrameMain;
// this.wrapper = wrapper;
// }
//
// @Override
// public void stop() {
// log().info("Stopping application.");
// if (isStopped) {
// log().warn("Application is already stopped.");
// return;
// }
// injector.stop();
// wrapper.stop();
// for (final Frame frame : Frame.getFrames()) {
// frame.dispose();
// }
// isStopped = true;
// }
//
// @Override
// public void start() {
// log().info("Starting application.");
// if (iDevice == null) {
// log().warn("No valid device was chosen. Please try to chose correct one.");
// stop();
// }
// SwingUtilities.invokeLater(() -> {
// jFrameMain.initialize();
// // Start showing the iDevice screen
// jFrameMain.setTitle(iDevice.getSerialNumber());
// // Show window
// jFrameMain.setVisible(true);
//
// jFrameMain.launchInjector();
// });
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(AndroidScreencastApplication.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/app/Application.java
// public interface Application {
//
// void stop();
//
// void handleException(Thread thread, Throwable ex);
//
// void start();
//
// void init();
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java
// @Singleton
// public final class DeviceChooserApplication extends SwingApplication {
//
// private static final long WAIT_TIMEOUT = 100;
// private final AndroidDebugBridgeWrapper bridge;
// private final long adbWaitSleepCyclesAmount;
// private IDevice device;
//
// @Inject
// public DeviceChooserApplication(final AndroidDebugBridgeWrapper bridge,
// final ApplicationConfiguration applicationConfiguration) {
// super(applicationConfiguration);
// this.bridge = bridge;
// this.adbWaitSleepCyclesAmount = getAdbDeviceTimeout() * 10;
// }
//
// private long getAdbDeviceTimeout() {
// return Long.parseLong(applicationConfiguration.getProperty(ADB_DEVICE_TIMEOUT));
// }
//
// @Override
// public void stop() {
// bridge.stop();
// }
//
// @Override
// public void start() {
// log().info("Starting application");
//
// waitDeviceList(bridge);
//
// final IDevice[] devices = bridge.getDevices();
//
// // Let the user choose the device
// if (devices.length == 1) {
// device = devices[0];
// log().info("1 device was found by ADB");
// } else {
// final JDialogDeviceList jd = new JDialogDeviceList(devices);
// jd.setVisible(true);
// device = jd.getDevice();
// log().info("{} devices were found by ADB", devices.length);
// }
// if (device == null) {
// throw new NoDeviceChosenException();
// }
// log().info("{} was chosen", device.getName());
// }
//
// private void waitDeviceList(final AndroidDebugBridgeWrapper bridge) {
// int count = 0;
// while (!bridge.hasInitialDeviceList()) {
// try {
// Thread.sleep(WAIT_TIMEOUT);
// count++;
// } catch (InterruptedException e) {
// log().warn("waitDeviceList(AndroidDebugBridge) - exception ignored", e);
// }
// if (count > adbWaitSleepCyclesAmount) {
// throw new WaitDeviceListTimeoutException();
// }
// }
// }
//
// public IDevice getDevice() {
// return device;
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(DeviceChooserApplication.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
| import com.android.ddmlib.IDevice;
import com.github.xsavikx.androidscreencast.app.AndroidScreencastApplication;
import com.github.xsavikx.androidscreencast.app.Application;
import com.github.xsavikx.androidscreencast.app.DeviceChooserApplication;
import dagger.Module;
import dagger.Provides;
import javax.inject.Singleton; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.dagger;
@Module
public class AppModule {
@Singleton
@Provides | // Path: src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java
// @Singleton
// public final class AndroidScreencastApplication extends SwingApplication {
//
// private final JFrameMain jFrameMain;
// private final Injector injector;
// private final IDevice iDevice;
// private final AndroidDebugBridgeWrapper wrapper;
// private transient boolean isStopped = false;
//
// @Inject
// public AndroidScreencastApplication(final Injector injector, final IDevice iDevice, final JFrameMain jFrameMain,
// final ApplicationConfiguration applicationConfiguration, AndroidDebugBridgeWrapper wrapper) {
// super(applicationConfiguration);
// this.injector = injector;
// this.iDevice = iDevice;
// this.jFrameMain = jFrameMain;
// this.wrapper = wrapper;
// }
//
// @Override
// public void stop() {
// log().info("Stopping application.");
// if (isStopped) {
// log().warn("Application is already stopped.");
// return;
// }
// injector.stop();
// wrapper.stop();
// for (final Frame frame : Frame.getFrames()) {
// frame.dispose();
// }
// isStopped = true;
// }
//
// @Override
// public void start() {
// log().info("Starting application.");
// if (iDevice == null) {
// log().warn("No valid device was chosen. Please try to chose correct one.");
// stop();
// }
// SwingUtilities.invokeLater(() -> {
// jFrameMain.initialize();
// // Start showing the iDevice screen
// jFrameMain.setTitle(iDevice.getSerialNumber());
// // Show window
// jFrameMain.setVisible(true);
//
// jFrameMain.launchInjector();
// });
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(AndroidScreencastApplication.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/app/Application.java
// public interface Application {
//
// void stop();
//
// void handleException(Thread thread, Throwable ex);
//
// void start();
//
// void init();
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java
// @Singleton
// public final class DeviceChooserApplication extends SwingApplication {
//
// private static final long WAIT_TIMEOUT = 100;
// private final AndroidDebugBridgeWrapper bridge;
// private final long adbWaitSleepCyclesAmount;
// private IDevice device;
//
// @Inject
// public DeviceChooserApplication(final AndroidDebugBridgeWrapper bridge,
// final ApplicationConfiguration applicationConfiguration) {
// super(applicationConfiguration);
// this.bridge = bridge;
// this.adbWaitSleepCyclesAmount = getAdbDeviceTimeout() * 10;
// }
//
// private long getAdbDeviceTimeout() {
// return Long.parseLong(applicationConfiguration.getProperty(ADB_DEVICE_TIMEOUT));
// }
//
// @Override
// public void stop() {
// bridge.stop();
// }
//
// @Override
// public void start() {
// log().info("Starting application");
//
// waitDeviceList(bridge);
//
// final IDevice[] devices = bridge.getDevices();
//
// // Let the user choose the device
// if (devices.length == 1) {
// device = devices[0];
// log().info("1 device was found by ADB");
// } else {
// final JDialogDeviceList jd = new JDialogDeviceList(devices);
// jd.setVisible(true);
// device = jd.getDevice();
// log().info("{} devices were found by ADB", devices.length);
// }
// if (device == null) {
// throw new NoDeviceChosenException();
// }
// log().info("{} was chosen", device.getName());
// }
//
// private void waitDeviceList(final AndroidDebugBridgeWrapper bridge) {
// int count = 0;
// while (!bridge.hasInitialDeviceList()) {
// try {
// Thread.sleep(WAIT_TIMEOUT);
// count++;
// } catch (InterruptedException e) {
// log().warn("waitDeviceList(AndroidDebugBridge) - exception ignored", e);
// }
// if (count > adbWaitSleepCyclesAmount) {
// throw new WaitDeviceListTimeoutException();
// }
// }
// }
//
// public IDevice getDevice() {
// return device;
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(DeviceChooserApplication.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/AppModule.java
import com.android.ddmlib.IDevice;
import com.github.xsavikx.androidscreencast.app.AndroidScreencastApplication;
import com.github.xsavikx.androidscreencast.app.Application;
import com.github.xsavikx.androidscreencast.app.DeviceChooserApplication;
import dagger.Module;
import dagger.Provides;
import javax.inject.Singleton;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.dagger;
@Module
public class AppModule {
@Singleton
@Provides | public static Application application(AndroidScreencastApplication application) { |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/dagger/AppModule.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java
// @Singleton
// public final class AndroidScreencastApplication extends SwingApplication {
//
// private final JFrameMain jFrameMain;
// private final Injector injector;
// private final IDevice iDevice;
// private final AndroidDebugBridgeWrapper wrapper;
// private transient boolean isStopped = false;
//
// @Inject
// public AndroidScreencastApplication(final Injector injector, final IDevice iDevice, final JFrameMain jFrameMain,
// final ApplicationConfiguration applicationConfiguration, AndroidDebugBridgeWrapper wrapper) {
// super(applicationConfiguration);
// this.injector = injector;
// this.iDevice = iDevice;
// this.jFrameMain = jFrameMain;
// this.wrapper = wrapper;
// }
//
// @Override
// public void stop() {
// log().info("Stopping application.");
// if (isStopped) {
// log().warn("Application is already stopped.");
// return;
// }
// injector.stop();
// wrapper.stop();
// for (final Frame frame : Frame.getFrames()) {
// frame.dispose();
// }
// isStopped = true;
// }
//
// @Override
// public void start() {
// log().info("Starting application.");
// if (iDevice == null) {
// log().warn("No valid device was chosen. Please try to chose correct one.");
// stop();
// }
// SwingUtilities.invokeLater(() -> {
// jFrameMain.initialize();
// // Start showing the iDevice screen
// jFrameMain.setTitle(iDevice.getSerialNumber());
// // Show window
// jFrameMain.setVisible(true);
//
// jFrameMain.launchInjector();
// });
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(AndroidScreencastApplication.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/app/Application.java
// public interface Application {
//
// void stop();
//
// void handleException(Thread thread, Throwable ex);
//
// void start();
//
// void init();
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java
// @Singleton
// public final class DeviceChooserApplication extends SwingApplication {
//
// private static final long WAIT_TIMEOUT = 100;
// private final AndroidDebugBridgeWrapper bridge;
// private final long adbWaitSleepCyclesAmount;
// private IDevice device;
//
// @Inject
// public DeviceChooserApplication(final AndroidDebugBridgeWrapper bridge,
// final ApplicationConfiguration applicationConfiguration) {
// super(applicationConfiguration);
// this.bridge = bridge;
// this.adbWaitSleepCyclesAmount = getAdbDeviceTimeout() * 10;
// }
//
// private long getAdbDeviceTimeout() {
// return Long.parseLong(applicationConfiguration.getProperty(ADB_DEVICE_TIMEOUT));
// }
//
// @Override
// public void stop() {
// bridge.stop();
// }
//
// @Override
// public void start() {
// log().info("Starting application");
//
// waitDeviceList(bridge);
//
// final IDevice[] devices = bridge.getDevices();
//
// // Let the user choose the device
// if (devices.length == 1) {
// device = devices[0];
// log().info("1 device was found by ADB");
// } else {
// final JDialogDeviceList jd = new JDialogDeviceList(devices);
// jd.setVisible(true);
// device = jd.getDevice();
// log().info("{} devices were found by ADB", devices.length);
// }
// if (device == null) {
// throw new NoDeviceChosenException();
// }
// log().info("{} was chosen", device.getName());
// }
//
// private void waitDeviceList(final AndroidDebugBridgeWrapper bridge) {
// int count = 0;
// while (!bridge.hasInitialDeviceList()) {
// try {
// Thread.sleep(WAIT_TIMEOUT);
// count++;
// } catch (InterruptedException e) {
// log().warn("waitDeviceList(AndroidDebugBridge) - exception ignored", e);
// }
// if (count > adbWaitSleepCyclesAmount) {
// throw new WaitDeviceListTimeoutException();
// }
// }
// }
//
// public IDevice getDevice() {
// return device;
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(DeviceChooserApplication.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
| import com.android.ddmlib.IDevice;
import com.github.xsavikx.androidscreencast.app.AndroidScreencastApplication;
import com.github.xsavikx.androidscreencast.app.Application;
import com.github.xsavikx.androidscreencast.app.DeviceChooserApplication;
import dagger.Module;
import dagger.Provides;
import javax.inject.Singleton; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.dagger;
@Module
public class AppModule {
@Singleton
@Provides
public static Application application(AndroidScreencastApplication application) {
return application;
}
@Singleton
@Provides | // Path: src/main/java/com/github/xsavikx/androidscreencast/app/AndroidScreencastApplication.java
// @Singleton
// public final class AndroidScreencastApplication extends SwingApplication {
//
// private final JFrameMain jFrameMain;
// private final Injector injector;
// private final IDevice iDevice;
// private final AndroidDebugBridgeWrapper wrapper;
// private transient boolean isStopped = false;
//
// @Inject
// public AndroidScreencastApplication(final Injector injector, final IDevice iDevice, final JFrameMain jFrameMain,
// final ApplicationConfiguration applicationConfiguration, AndroidDebugBridgeWrapper wrapper) {
// super(applicationConfiguration);
// this.injector = injector;
// this.iDevice = iDevice;
// this.jFrameMain = jFrameMain;
// this.wrapper = wrapper;
// }
//
// @Override
// public void stop() {
// log().info("Stopping application.");
// if (isStopped) {
// log().warn("Application is already stopped.");
// return;
// }
// injector.stop();
// wrapper.stop();
// for (final Frame frame : Frame.getFrames()) {
// frame.dispose();
// }
// isStopped = true;
// }
//
// @Override
// public void start() {
// log().info("Starting application.");
// if (iDevice == null) {
// log().warn("No valid device was chosen. Please try to chose correct one.");
// stop();
// }
// SwingUtilities.invokeLater(() -> {
// jFrameMain.initialize();
// // Start showing the iDevice screen
// jFrameMain.setTitle(iDevice.getSerialNumber());
// // Show window
// jFrameMain.setVisible(true);
//
// jFrameMain.launchInjector();
// });
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(AndroidScreencastApplication.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/app/Application.java
// public interface Application {
//
// void stop();
//
// void handleException(Thread thread, Throwable ex);
//
// void start();
//
// void init();
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/app/DeviceChooserApplication.java
// @Singleton
// public final class DeviceChooserApplication extends SwingApplication {
//
// private static final long WAIT_TIMEOUT = 100;
// private final AndroidDebugBridgeWrapper bridge;
// private final long adbWaitSleepCyclesAmount;
// private IDevice device;
//
// @Inject
// public DeviceChooserApplication(final AndroidDebugBridgeWrapper bridge,
// final ApplicationConfiguration applicationConfiguration) {
// super(applicationConfiguration);
// this.bridge = bridge;
// this.adbWaitSleepCyclesAmount = getAdbDeviceTimeout() * 10;
// }
//
// private long getAdbDeviceTimeout() {
// return Long.parseLong(applicationConfiguration.getProperty(ADB_DEVICE_TIMEOUT));
// }
//
// @Override
// public void stop() {
// bridge.stop();
// }
//
// @Override
// public void start() {
// log().info("Starting application");
//
// waitDeviceList(bridge);
//
// final IDevice[] devices = bridge.getDevices();
//
// // Let the user choose the device
// if (devices.length == 1) {
// device = devices[0];
// log().info("1 device was found by ADB");
// } else {
// final JDialogDeviceList jd = new JDialogDeviceList(devices);
// jd.setVisible(true);
// device = jd.getDevice();
// log().info("{} devices were found by ADB", devices.length);
// }
// if (device == null) {
// throw new NoDeviceChosenException();
// }
// log().info("{} was chosen", device.getName());
// }
//
// private void waitDeviceList(final AndroidDebugBridgeWrapper bridge) {
// int count = 0;
// while (!bridge.hasInitialDeviceList()) {
// try {
// Thread.sleep(WAIT_TIMEOUT);
// count++;
// } catch (InterruptedException e) {
// log().warn("waitDeviceList(AndroidDebugBridge) - exception ignored", e);
// }
// if (count > adbWaitSleepCyclesAmount) {
// throw new WaitDeviceListTimeoutException();
// }
// }
// }
//
// public IDevice getDevice() {
// return device;
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(DeviceChooserApplication.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/AppModule.java
import com.android.ddmlib.IDevice;
import com.github.xsavikx.androidscreencast.app.AndroidScreencastApplication;
import com.github.xsavikx.androidscreencast.app.Application;
import com.github.xsavikx.androidscreencast.app.DeviceChooserApplication;
import dagger.Module;
import dagger.Provides;
import javax.inject.Singleton;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.dagger;
@Module
public class AppModule {
@Singleton
@Provides
public static Application application(AndroidScreencastApplication application) {
return application;
}
@Singleton
@Provides | public static IDevice iDevice(final DeviceChooserApplication application) { |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/ui/explorer/JFrameExplorer.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDevice.java
// public interface AndroidDevice {
//
// String executeCommand(String command);
//
// List<FileInfo> list(String path);
//
// void openUrl(String url);
//
// void pullFile(String remoteFrom, File localTo);
//
// void pushFile(File localFrom, String remoteTo);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java
// @Singleton
// public final class FileInfo {
//
// public AndroidDeviceImpl device;
// public String path;
// public String attribs;
// public boolean directory;
// public String name;
//
// @Inject
// public FileInfo() {
// }
//
// public File downloadTemporary() {
// try {
// File tempFile = File.createTempFile("android", name);
// device.pullFile(path + name, tempFile);
// tempFile.deleteOnExit();
// return tempFile;
// } catch (IOException ex) {
// throw new IORuntimeException(ex);
// }
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
| import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.github.xsavikx.androidscreencast.api.AndroidDevice;
import com.github.xsavikx.androidscreencast.api.file.FileInfo;
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import javax.inject.Inject;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.ui.explorer;
public final class JFrameExplorer extends JFrame {
private static final long serialVersionUID = -5209265873286028854L; | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDevice.java
// public interface AndroidDevice {
//
// String executeCommand(String command);
//
// List<FileInfo> list(String path);
//
// void openUrl(String url);
//
// void pullFile(String remoteFrom, File localTo);
//
// void pushFile(File localFrom, String remoteTo);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java
// @Singleton
// public final class FileInfo {
//
// public AndroidDeviceImpl device;
// public String path;
// public String attribs;
// public boolean directory;
// public String name;
//
// @Inject
// public FileInfo() {
// }
//
// public File downloadTemporary() {
// try {
// File tempFile = File.createTempFile("android", name);
// device.pullFile(path + name, tempFile);
// tempFile.deleteOnExit();
// return tempFile;
// } catch (IOException ex) {
// throw new IORuntimeException(ex);
// }
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/ui/explorer/JFrameExplorer.java
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.github.xsavikx.androidscreencast.api.AndroidDevice;
import com.github.xsavikx.androidscreencast.api.file.FileInfo;
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import javax.inject.Inject;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.ui.explorer;
public final class JFrameExplorer extends JFrame {
private static final long serialVersionUID = -5209265873286028854L; | private final AndroidDevice androidDevice; |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/ui/explorer/JFrameExplorer.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDevice.java
// public interface AndroidDevice {
//
// String executeCommand(String command);
//
// List<FileInfo> list(String path);
//
// void openUrl(String url);
//
// void pullFile(String remoteFrom, File localTo);
//
// void pushFile(File localFrom, String remoteTo);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java
// @Singleton
// public final class FileInfo {
//
// public AndroidDeviceImpl device;
// public String path;
// public String attribs;
// public boolean directory;
// public String name;
//
// @Inject
// public FileInfo() {
// }
//
// public File downloadTemporary() {
// try {
// File tempFile = File.createTempFile("android", name);
// device.pullFile(path + name, tempFile);
// tempFile.deleteOnExit();
// return tempFile;
// } catch (IOException ex) {
// throw new IORuntimeException(ex);
// }
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
| import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.github.xsavikx.androidscreencast.api.AndroidDevice;
import com.github.xsavikx.androidscreencast.api.file.FileInfo;
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import javax.inject.Inject;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.ui.explorer;
public final class JFrameExplorer extends JFrame {
private static final long serialVersionUID = -5209265873286028854L;
private final AndroidDevice androidDevice;
private final JTree jt;
private JList<Object> jListFichiers; | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDevice.java
// public interface AndroidDevice {
//
// String executeCommand(String command);
//
// List<FileInfo> list(String path);
//
// void openUrl(String url);
//
// void pullFile(String remoteFrom, File localTo);
//
// void pushFile(File localFrom, String remoteTo);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java
// @Singleton
// public final class FileInfo {
//
// public AndroidDeviceImpl device;
// public String path;
// public String attribs;
// public boolean directory;
// public String name;
//
// @Inject
// public FileInfo() {
// }
//
// public File downloadTemporary() {
// try {
// File tempFile = File.createTempFile("android", name);
// device.pullFile(path + name, tempFile);
// tempFile.deleteOnExit();
// return tempFile;
// } catch (IOException ex) {
// throw new IORuntimeException(ex);
// }
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/ui/explorer/JFrameExplorer.java
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.github.xsavikx.androidscreencast.api.AndroidDevice;
import com.github.xsavikx.androidscreencast.api.file.FileInfo;
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import javax.inject.Inject;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.ui.explorer;
public final class JFrameExplorer extends JFrame {
private static final long serialVersionUID = -5209265873286028854L;
private final AndroidDevice androidDevice;
private final JTree jt;
private JList<Object> jListFichiers; | private final Map<String, List<FileInfo>> cache = new LinkedHashMap<>(); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/ui/explorer/JFrameExplorer.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDevice.java
// public interface AndroidDevice {
//
// String executeCommand(String command);
//
// List<FileInfo> list(String path);
//
// void openUrl(String url);
//
// void pullFile(String remoteFrom, File localTo);
//
// void pushFile(File localFrom, String remoteTo);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java
// @Singleton
// public final class FileInfo {
//
// public AndroidDeviceImpl device;
// public String path;
// public String attribs;
// public boolean directory;
// public String name;
//
// @Inject
// public FileInfo() {
// }
//
// public File downloadTemporary() {
// try {
// File tempFile = File.createTempFile("android", name);
// device.pullFile(path + name, tempFile);
// tempFile.deleteOnExit();
// return tempFile;
// } catch (IOException ex) {
// throw new IORuntimeException(ex);
// }
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
| import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.github.xsavikx.androidscreencast.api.AndroidDevice;
import com.github.xsavikx.androidscreencast.api.file.FileInfo;
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import javax.inject.Inject;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File; | if (e.getClickCount() == 2) {
int index = jListFichiers.locationToIndex(e.getPoint());
ListModel<Object> dlm = jListFichiers.getModel();
FileInfo item = (FileInfo) dlm.getElementAt(index);
launchFile(item);
}
}
});
}
private void displayFolder(String path) {
List<FileInfo> fileInfos = cache.get(path);
if (fileInfos == null)
fileInfos = androidDevice.list(path);
List<FileInfo> files = new ArrayList<>();
for (FileInfo fi2 : fileInfos) {
if (fi2.directory)
continue;
files.add(fi2);
}
jListFichiers.setListData(files.toArray());
}
private void launchFile(FileInfo node) {
try {
File tempFile = node.downloadTemporary();
Desktop.getDesktop().open(tempFile);
} catch (Exception ex) { | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDevice.java
// public interface AndroidDevice {
//
// String executeCommand(String command);
//
// List<FileInfo> list(String path);
//
// void openUrl(String url);
//
// void pullFile(String remoteFrom, File localTo);
//
// void pushFile(File localFrom, String remoteTo);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java
// @Singleton
// public final class FileInfo {
//
// public AndroidDeviceImpl device;
// public String path;
// public String attribs;
// public boolean directory;
// public String name;
//
// @Inject
// public FileInfo() {
// }
//
// public File downloadTemporary() {
// try {
// File tempFile = File.createTempFile("android", name);
// device.pullFile(path + name, tempFile);
// tempFile.deleteOnExit();
// return tempFile;
// } catch (IOException ex) {
// throw new IORuntimeException(ex);
// }
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/ui/explorer/JFrameExplorer.java
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.github.xsavikx.androidscreencast.api.AndroidDevice;
import com.github.xsavikx.androidscreencast.api.file.FileInfo;
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import javax.inject.Inject;
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreePath;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.File;
if (e.getClickCount() == 2) {
int index = jListFichiers.locationToIndex(e.getPoint());
ListModel<Object> dlm = jListFichiers.getModel();
FileInfo item = (FileInfo) dlm.getElementAt(index);
launchFile(item);
}
}
});
}
private void displayFolder(String path) {
List<FileInfo> fileInfos = cache.get(path);
if (fileInfos == null)
fileInfos = androidDevice.list(path);
List<FileInfo> files = new ArrayList<>();
for (FileInfo fi2 : fileInfos) {
if (fi2.directory)
continue;
files.add(fi2);
}
jListFichiers.setListData(files.toArray());
}
private void launchFile(FileInfo node) {
try {
File tempFile = node.downloadTemporary();
Desktop.getDesktop().open(tempFile);
} catch (Exception ex) { | throw new AndroidScreenCastRuntimeException(ex); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponent.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/app/Application.java
// public interface Application {
//
// void stop();
//
// void handleException(Thread thread, Throwable ex);
//
// void start();
//
// void init();
// }
| import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.app.Application;
import dagger.Component;
import javax.inject.Singleton; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.dagger;
@Singleton
@Component(modules = {ApiModule.class, AppModule.class, UiModule.class})
public interface MainComponent { | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/app/Application.java
// public interface Application {
//
// void stop();
//
// void handleException(Thread thread, Throwable ex);
//
// void start();
//
// void init();
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponent.java
import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.app.Application;
import dagger.Component;
import javax.inject.Singleton;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.dagger;
@Singleton
@Component(modules = {ApiModule.class, AppModule.class, UiModule.class})
public interface MainComponent { | Application application(); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponent.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/app/Application.java
// public interface Application {
//
// void stop();
//
// void handleException(Thread thread, Throwable ex);
//
// void start();
//
// void init();
// }
| import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.app.Application;
import dagger.Component;
import javax.inject.Singleton; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.dagger;
@Singleton
@Component(modules = {ApiModule.class, AppModule.class, UiModule.class})
public interface MainComponent {
Application application();
| // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/app/Application.java
// public interface Application {
//
// void stop();
//
// void handleException(Thread thread, Throwable ex);
//
// void start();
//
// void init();
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponent.java
import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.app.Application;
import dagger.Component;
import javax.inject.Singleton;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.dagger;
@Singleton
@Component(modules = {ApiModule.class, AppModule.class, UiModule.class})
public interface MainComponent {
Application application();
| CommandExecutor commandExecutor(); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponent.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/app/Application.java
// public interface Application {
//
// void stop();
//
// void handleException(Thread thread, Throwable ex);
//
// void start();
//
// void init();
// }
| import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.app.Application;
import dagger.Component;
import javax.inject.Singleton; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.dagger;
@Singleton
@Component(modules = {ApiModule.class, AppModule.class, UiModule.class})
public interface MainComponent {
Application application();
CommandExecutor commandExecutor();
| // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/app/Application.java
// public interface Application {
//
// void stop();
//
// void handleException(Thread thread, Throwable ex);
//
// void start();
//
// void init();
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponent.java
import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.app.Application;
import dagger.Component;
import javax.inject.Singleton;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.dagger;
@Singleton
@Component(modules = {ApiModule.class, AppModule.class, UiModule.class})
public interface MainComponent {
Application application();
CommandExecutor commandExecutor();
| InputCommandFactory inputCommandFactory(); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyboardActionListener.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/KeyCommand.java
// public final class KeyCommand extends InputCommand {
//
// private final int code;
// private boolean longpress;
//
// public KeyCommand(int keyCode) {
// this.code = keyCode;
// }
//
// private KeyCommand(InputKeyEvent inputKeyEvent) {
// code = inputKeyEvent.getCode();
// }
//
// public KeyCommand(int keyCode, boolean longpress) {
// this(keyCode);
// this.longpress = longpress;
// }
//
// public KeyCommand(InputKeyEvent inputKeyEvent, boolean longpress) {
// this(inputKeyEvent);
// this.longpress = longpress;
// }
//
// public void setLongPress(boolean longpress) {
// this.longpress = longpress;
// }
//
// @Override
// protected String getCommandPart() {
// StringBuilder stringBuilder = new StringBuilder("keyevent");
// if (longpress) {
// stringBuilder.append(" --longpress");
// }
// stringBuilder.append(' ').append(code);
// return stringBuilder.toString();
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java
// public final class MainComponentProvider {
// private static MainComponent INSTANCE;
//
// private MainComponentProvider() {
//
// }
//
// public static MainComponent mainComponent() {
// if (INSTANCE == null) {
// INSTANCE = DaggerMainComponent.create();
// }
// return INSTANCE;
// }
// }
| import com.github.xsavikx.androidscreencast.api.command.KeyCommand;
import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.ui.interaction;
public final class KeyboardActionListener implements ActionListener {
private InputCommandFactory inputCommandFactory; | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/KeyCommand.java
// public final class KeyCommand extends InputCommand {
//
// private final int code;
// private boolean longpress;
//
// public KeyCommand(int keyCode) {
// this.code = keyCode;
// }
//
// private KeyCommand(InputKeyEvent inputKeyEvent) {
// code = inputKeyEvent.getCode();
// }
//
// public KeyCommand(int keyCode, boolean longpress) {
// this(keyCode);
// this.longpress = longpress;
// }
//
// public KeyCommand(InputKeyEvent inputKeyEvent, boolean longpress) {
// this(inputKeyEvent);
// this.longpress = longpress;
// }
//
// public void setLongPress(boolean longpress) {
// this.longpress = longpress;
// }
//
// @Override
// protected String getCommandPart() {
// StringBuilder stringBuilder = new StringBuilder("keyevent");
// if (longpress) {
// stringBuilder.append(" --longpress");
// }
// stringBuilder.append(' ').append(code);
// return stringBuilder.toString();
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java
// public final class MainComponentProvider {
// private static MainComponent INSTANCE;
//
// private MainComponentProvider() {
//
// }
//
// public static MainComponent mainComponent() {
// if (INSTANCE == null) {
// INSTANCE = DaggerMainComponent.create();
// }
// return INSTANCE;
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyboardActionListener.java
import com.github.xsavikx.androidscreencast.api.command.KeyCommand;
import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.ui.interaction;
public final class KeyboardActionListener implements ActionListener {
private InputCommandFactory inputCommandFactory; | private CommandExecutor commandExecutor; |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyboardActionListener.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/KeyCommand.java
// public final class KeyCommand extends InputCommand {
//
// private final int code;
// private boolean longpress;
//
// public KeyCommand(int keyCode) {
// this.code = keyCode;
// }
//
// private KeyCommand(InputKeyEvent inputKeyEvent) {
// code = inputKeyEvent.getCode();
// }
//
// public KeyCommand(int keyCode, boolean longpress) {
// this(keyCode);
// this.longpress = longpress;
// }
//
// public KeyCommand(InputKeyEvent inputKeyEvent, boolean longpress) {
// this(inputKeyEvent);
// this.longpress = longpress;
// }
//
// public void setLongPress(boolean longpress) {
// this.longpress = longpress;
// }
//
// @Override
// protected String getCommandPart() {
// StringBuilder stringBuilder = new StringBuilder("keyevent");
// if (longpress) {
// stringBuilder.append(" --longpress");
// }
// stringBuilder.append(' ').append(code);
// return stringBuilder.toString();
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java
// public final class MainComponentProvider {
// private static MainComponent INSTANCE;
//
// private MainComponentProvider() {
//
// }
//
// public static MainComponent mainComponent() {
// if (INSTANCE == null) {
// INSTANCE = DaggerMainComponent.create();
// }
// return INSTANCE;
// }
// }
| import com.github.xsavikx.androidscreencast.api.command.KeyCommand;
import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.ui.interaction;
public final class KeyboardActionListener implements ActionListener {
private InputCommandFactory inputCommandFactory;
private CommandExecutor commandExecutor;
private final int key;
KeyboardActionListener(int key) {
this.key = key;
}
@Override
public void actionPerformed(final ActionEvent e) {
SwingUtilities.invokeLater(() -> { | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/KeyCommand.java
// public final class KeyCommand extends InputCommand {
//
// private final int code;
// private boolean longpress;
//
// public KeyCommand(int keyCode) {
// this.code = keyCode;
// }
//
// private KeyCommand(InputKeyEvent inputKeyEvent) {
// code = inputKeyEvent.getCode();
// }
//
// public KeyCommand(int keyCode, boolean longpress) {
// this(keyCode);
// this.longpress = longpress;
// }
//
// public KeyCommand(InputKeyEvent inputKeyEvent, boolean longpress) {
// this(inputKeyEvent);
// this.longpress = longpress;
// }
//
// public void setLongPress(boolean longpress) {
// this.longpress = longpress;
// }
//
// @Override
// protected String getCommandPart() {
// StringBuilder stringBuilder = new StringBuilder("keyevent");
// if (longpress) {
// stringBuilder.append(" --longpress");
// }
// stringBuilder.append(' ').append(code);
// return stringBuilder.toString();
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java
// public final class MainComponentProvider {
// private static MainComponent INSTANCE;
//
// private MainComponentProvider() {
//
// }
//
// public static MainComponent mainComponent() {
// if (INSTANCE == null) {
// INSTANCE = DaggerMainComponent.create();
// }
// return INSTANCE;
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyboardActionListener.java
import com.github.xsavikx.androidscreencast.api.command.KeyCommand;
import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.ui.interaction;
public final class KeyboardActionListener implements ActionListener {
private InputCommandFactory inputCommandFactory;
private CommandExecutor commandExecutor;
private final int key;
KeyboardActionListener(int key) {
this.key = key;
}
@Override
public void actionPerformed(final ActionEvent e) {
SwingUtilities.invokeLater(() -> { | final KeyCommand command = getInputCommandFactory().getKeyCommand(key); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyboardActionListener.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/KeyCommand.java
// public final class KeyCommand extends InputCommand {
//
// private final int code;
// private boolean longpress;
//
// public KeyCommand(int keyCode) {
// this.code = keyCode;
// }
//
// private KeyCommand(InputKeyEvent inputKeyEvent) {
// code = inputKeyEvent.getCode();
// }
//
// public KeyCommand(int keyCode, boolean longpress) {
// this(keyCode);
// this.longpress = longpress;
// }
//
// public KeyCommand(InputKeyEvent inputKeyEvent, boolean longpress) {
// this(inputKeyEvent);
// this.longpress = longpress;
// }
//
// public void setLongPress(boolean longpress) {
// this.longpress = longpress;
// }
//
// @Override
// protected String getCommandPart() {
// StringBuilder stringBuilder = new StringBuilder("keyevent");
// if (longpress) {
// stringBuilder.append(" --longpress");
// }
// stringBuilder.append(' ').append(code);
// return stringBuilder.toString();
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java
// public final class MainComponentProvider {
// private static MainComponent INSTANCE;
//
// private MainComponentProvider() {
//
// }
//
// public static MainComponent mainComponent() {
// if (INSTANCE == null) {
// INSTANCE = DaggerMainComponent.create();
// }
// return INSTANCE;
// }
// }
| import com.github.xsavikx.androidscreencast.api.command.KeyCommand;
import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.ui.interaction;
public final class KeyboardActionListener implements ActionListener {
private InputCommandFactory inputCommandFactory;
private CommandExecutor commandExecutor;
private final int key;
KeyboardActionListener(int key) {
this.key = key;
}
@Override
public void actionPerformed(final ActionEvent e) {
SwingUtilities.invokeLater(() -> {
final KeyCommand command = getInputCommandFactory().getKeyCommand(key);
getCommandExecutor().execute(command);
});
}
private InputCommandFactory getInputCommandFactory() {
if (inputCommandFactory == null) { | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/KeyCommand.java
// public final class KeyCommand extends InputCommand {
//
// private final int code;
// private boolean longpress;
//
// public KeyCommand(int keyCode) {
// this.code = keyCode;
// }
//
// private KeyCommand(InputKeyEvent inputKeyEvent) {
// code = inputKeyEvent.getCode();
// }
//
// public KeyCommand(int keyCode, boolean longpress) {
// this(keyCode);
// this.longpress = longpress;
// }
//
// public KeyCommand(InputKeyEvent inputKeyEvent, boolean longpress) {
// this(inputKeyEvent);
// this.longpress = longpress;
// }
//
// public void setLongPress(boolean longpress) {
// this.longpress = longpress;
// }
//
// @Override
// protected String getCommandPart() {
// StringBuilder stringBuilder = new StringBuilder("keyevent");
// if (longpress) {
// stringBuilder.append(" --longpress");
// }
// stringBuilder.append(' ').append(code);
// return stringBuilder.toString();
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/executor/CommandExecutor.java
// public interface CommandExecutor {
//
// void execute(Command command);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/command/factory/InputCommandFactory.java
// public interface InputCommandFactory {
//
// KeyCommand getKeyCommand(int keyCode);
//
// KeyCommand getKeyCommand(InputKeyEvent inputKeyEvent, boolean longpress);
//
// SwipeCommand getSwipeCommand(int x1, int y1, int x2, int y2, long duration);
//
// TapCommand getTapCommand(int x, int y);
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/dagger/MainComponentProvider.java
// public final class MainComponentProvider {
// private static MainComponent INSTANCE;
//
// private MainComponentProvider() {
//
// }
//
// public static MainComponent mainComponent() {
// if (INSTANCE == null) {
// INSTANCE = DaggerMainComponent.create();
// }
// return INSTANCE;
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/ui/interaction/KeyboardActionListener.java
import com.github.xsavikx.androidscreencast.api.command.KeyCommand;
import com.github.xsavikx.androidscreencast.api.command.executor.CommandExecutor;
import com.github.xsavikx.androidscreencast.api.command.factory.InputCommandFactory;
import com.github.xsavikx.androidscreencast.dagger.MainComponentProvider;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.ui.interaction;
public final class KeyboardActionListener implements ActionListener {
private InputCommandFactory inputCommandFactory;
private CommandExecutor commandExecutor;
private final int key;
KeyboardActionListener(int key) {
this.key = key;
}
@Override
public void actionPerformed(final ActionEvent e) {
SwingUtilities.invokeLater(() -> {
final KeyCommand command = getInputCommandFactory().getKeyCommand(key);
getCommandExecutor().execute(command);
});
}
private InputCommandFactory getInputCommandFactory() {
if (inputCommandFactory == null) { | inputCommandFactory = MainComponentProvider.mainComponent().inputCommandFactory(); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/api/injector/OutputStreamShellOutputReceiver.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IORuntimeException.java
// public final class IORuntimeException extends AndroidScreenCastRuntimeException {
//
// public IORuntimeException(String message, IOException cause) {
// super(message, cause);
// }
//
// public IORuntimeException(IOException cause) {
// super(cause);
// }
//
// public IORuntimeException(String message, IOException cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
| import com.android.ddmlib.IShellOutputReceiver;
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
import java.io.IOException;
import java.io.OutputStream; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api.injector;
public final class OutputStreamShellOutputReceiver implements IShellOutputReceiver {
private final OutputStream os;
public OutputStreamShellOutputReceiver(OutputStream os) {
this.os = os;
}
@Override
public void addOutput(byte[] buf, int off, int len) {
try {
os.write(buf, off, len);
} catch (IOException e) { | // Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IORuntimeException.java
// public final class IORuntimeException extends AndroidScreenCastRuntimeException {
//
// public IORuntimeException(String message, IOException cause) {
// super(message, cause);
// }
//
// public IORuntimeException(IOException cause) {
// super(cause);
// }
//
// public IORuntimeException(String message, IOException cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/injector/OutputStreamShellOutputReceiver.java
import com.android.ddmlib.IShellOutputReceiver;
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
import java.io.IOException;
import java.io.OutputStream;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api.injector;
public final class OutputStreamShellOutputReceiver implements IShellOutputReceiver {
private final OutputStream os;
public OutputStreamShellOutputReceiver(OutputStream os) {
this.os = os;
}
@Override
public void addOutput(byte[] buf, int off, int len) {
try {
os.write(buf, off, len);
} catch (IOException e) { | throw new IORuntimeException(e); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java
// @Singleton
// public final class FileInfo {
//
// public AndroidDeviceImpl device;
// public String path;
// public String attribs;
// public boolean directory;
// public String name;
//
// @Inject
// public FileInfo() {
// }
//
// public File downloadTemporary() {
// try {
// File tempFile = File.createTempFile("android", name);
// device.pullFile(path + name, tempFile);
// tempFile.deleteOnExit();
// return tempFile;
// } catch (IOException ex) {
// throw new IORuntimeException(ex);
// }
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/injector/OutputStreamShellOutputReceiver.java
// public final class OutputStreamShellOutputReceiver implements IShellOutputReceiver {
//
// private final OutputStream os;
//
// public OutputStreamShellOutputReceiver(OutputStream os) {
// this.os = os;
// }
//
// @Override
// public void addOutput(byte[] buf, int off, int len) {
// try {
// os.write(buf, off, len);
// } catch (IOException e) {
// throw new IORuntimeException(e);
// }
// }
//
// @Override
// public void flush() {
// try {
// os.flush();
// } catch (IOException e) {
// throw new IORuntimeException(e);
// }
// }
//
// @Override
// public boolean isCancelled() {
// return false;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/ExecuteCommandException.java
// public final class ExecuteCommandException extends AndroidScreenCastRuntimeException {
//
// public ExecuteCommandException(String command) {
// super(String.format("Cannot execute command '%s'.", command));
// }
// }
| import java.util.ArrayList;
import java.util.List;
import static org.slf4j.LoggerFactory.getLogger;
import com.android.ddmlib.IDevice;
import com.android.ddmlib.SyncService;
import com.github.xsavikx.androidscreencast.api.file.FileInfo;
import com.github.xsavikx.androidscreencast.api.injector.OutputStreamShellOutputReceiver;
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import com.github.xsavikx.androidscreencast.exception.ExecuteCommandException;
import org.slf4j.Logger;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.nio.charset.StandardCharsets; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api;
@Singleton
public final class AndroidDeviceImpl implements AndroidDevice {
private final IDevice device;
@Inject
public AndroidDeviceImpl(final IDevice device) {
this.device = device;
}
@Override
public String executeCommand(final String cmd) {
log().debug("Executing command: `{}`.", cmd);
try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) { | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java
// @Singleton
// public final class FileInfo {
//
// public AndroidDeviceImpl device;
// public String path;
// public String attribs;
// public boolean directory;
// public String name;
//
// @Inject
// public FileInfo() {
// }
//
// public File downloadTemporary() {
// try {
// File tempFile = File.createTempFile("android", name);
// device.pullFile(path + name, tempFile);
// tempFile.deleteOnExit();
// return tempFile;
// } catch (IOException ex) {
// throw new IORuntimeException(ex);
// }
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/injector/OutputStreamShellOutputReceiver.java
// public final class OutputStreamShellOutputReceiver implements IShellOutputReceiver {
//
// private final OutputStream os;
//
// public OutputStreamShellOutputReceiver(OutputStream os) {
// this.os = os;
// }
//
// @Override
// public void addOutput(byte[] buf, int off, int len) {
// try {
// os.write(buf, off, len);
// } catch (IOException e) {
// throw new IORuntimeException(e);
// }
// }
//
// @Override
// public void flush() {
// try {
// os.flush();
// } catch (IOException e) {
// throw new IORuntimeException(e);
// }
// }
//
// @Override
// public boolean isCancelled() {
// return false;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/ExecuteCommandException.java
// public final class ExecuteCommandException extends AndroidScreenCastRuntimeException {
//
// public ExecuteCommandException(String command) {
// super(String.format("Cannot execute command '%s'.", command));
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java
import java.util.ArrayList;
import java.util.List;
import static org.slf4j.LoggerFactory.getLogger;
import com.android.ddmlib.IDevice;
import com.android.ddmlib.SyncService;
import com.github.xsavikx.androidscreencast.api.file.FileInfo;
import com.github.xsavikx.androidscreencast.api.injector.OutputStreamShellOutputReceiver;
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import com.github.xsavikx.androidscreencast.exception.ExecuteCommandException;
import org.slf4j.Logger;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.nio.charset.StandardCharsets;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api;
@Singleton
public final class AndroidDeviceImpl implements AndroidDevice {
private final IDevice device;
@Inject
public AndroidDeviceImpl(final IDevice device) {
this.device = device;
}
@Override
public String executeCommand(final String cmd) {
log().debug("Executing command: `{}`.", cmd);
try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) { | device.executeShellCommand(cmd, new OutputStreamShellOutputReceiver(bos)); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java
// @Singleton
// public final class FileInfo {
//
// public AndroidDeviceImpl device;
// public String path;
// public String attribs;
// public boolean directory;
// public String name;
//
// @Inject
// public FileInfo() {
// }
//
// public File downloadTemporary() {
// try {
// File tempFile = File.createTempFile("android", name);
// device.pullFile(path + name, tempFile);
// tempFile.deleteOnExit();
// return tempFile;
// } catch (IOException ex) {
// throw new IORuntimeException(ex);
// }
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/injector/OutputStreamShellOutputReceiver.java
// public final class OutputStreamShellOutputReceiver implements IShellOutputReceiver {
//
// private final OutputStream os;
//
// public OutputStreamShellOutputReceiver(OutputStream os) {
// this.os = os;
// }
//
// @Override
// public void addOutput(byte[] buf, int off, int len) {
// try {
// os.write(buf, off, len);
// } catch (IOException e) {
// throw new IORuntimeException(e);
// }
// }
//
// @Override
// public void flush() {
// try {
// os.flush();
// } catch (IOException e) {
// throw new IORuntimeException(e);
// }
// }
//
// @Override
// public boolean isCancelled() {
// return false;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/ExecuteCommandException.java
// public final class ExecuteCommandException extends AndroidScreenCastRuntimeException {
//
// public ExecuteCommandException(String command) {
// super(String.format("Cannot execute command '%s'.", command));
// }
// }
| import java.util.ArrayList;
import java.util.List;
import static org.slf4j.LoggerFactory.getLogger;
import com.android.ddmlib.IDevice;
import com.android.ddmlib.SyncService;
import com.github.xsavikx.androidscreencast.api.file.FileInfo;
import com.github.xsavikx.androidscreencast.api.injector.OutputStreamShellOutputReceiver;
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import com.github.xsavikx.androidscreencast.exception.ExecuteCommandException;
import org.slf4j.Logger;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.nio.charset.StandardCharsets; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api;
@Singleton
public final class AndroidDeviceImpl implements AndroidDevice {
private final IDevice device;
@Inject
public AndroidDeviceImpl(final IDevice device) {
this.device = device;
}
@Override
public String executeCommand(final String cmd) {
log().debug("Executing command: `{}`.", cmd);
try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
device.executeShellCommand(cmd, new OutputStreamShellOutputReceiver(bos));
final String result = new String(bos.toByteArray(), StandardCharsets.UTF_8);
log().debug("Command `{}` executed with result: `{}`.", cmd, result);
return result;
} catch (final Exception ex) {
log().error("Unable to execute command `{}`.", cmd, ex); | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java
// @Singleton
// public final class FileInfo {
//
// public AndroidDeviceImpl device;
// public String path;
// public String attribs;
// public boolean directory;
// public String name;
//
// @Inject
// public FileInfo() {
// }
//
// public File downloadTemporary() {
// try {
// File tempFile = File.createTempFile("android", name);
// device.pullFile(path + name, tempFile);
// tempFile.deleteOnExit();
// return tempFile;
// } catch (IOException ex) {
// throw new IORuntimeException(ex);
// }
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/injector/OutputStreamShellOutputReceiver.java
// public final class OutputStreamShellOutputReceiver implements IShellOutputReceiver {
//
// private final OutputStream os;
//
// public OutputStreamShellOutputReceiver(OutputStream os) {
// this.os = os;
// }
//
// @Override
// public void addOutput(byte[] buf, int off, int len) {
// try {
// os.write(buf, off, len);
// } catch (IOException e) {
// throw new IORuntimeException(e);
// }
// }
//
// @Override
// public void flush() {
// try {
// os.flush();
// } catch (IOException e) {
// throw new IORuntimeException(e);
// }
// }
//
// @Override
// public boolean isCancelled() {
// return false;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/ExecuteCommandException.java
// public final class ExecuteCommandException extends AndroidScreenCastRuntimeException {
//
// public ExecuteCommandException(String command) {
// super(String.format("Cannot execute command '%s'.", command));
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java
import java.util.ArrayList;
import java.util.List;
import static org.slf4j.LoggerFactory.getLogger;
import com.android.ddmlib.IDevice;
import com.android.ddmlib.SyncService;
import com.github.xsavikx.androidscreencast.api.file.FileInfo;
import com.github.xsavikx.androidscreencast.api.injector.OutputStreamShellOutputReceiver;
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import com.github.xsavikx.androidscreencast.exception.ExecuteCommandException;
import org.slf4j.Logger;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.nio.charset.StandardCharsets;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api;
@Singleton
public final class AndroidDeviceImpl implements AndroidDevice {
private final IDevice device;
@Inject
public AndroidDeviceImpl(final IDevice device) {
this.device = device;
}
@Override
public String executeCommand(final String cmd) {
log().debug("Executing command: `{}`.", cmd);
try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
device.executeShellCommand(cmd, new OutputStreamShellOutputReceiver(bos));
final String result = new String(bos.toByteArray(), StandardCharsets.UTF_8);
log().debug("Command `{}` executed with result: `{}`.", cmd, result);
return result;
} catch (final Exception ex) {
log().error("Unable to execute command `{}`.", cmd, ex); | throw new ExecuteCommandException(cmd); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java
// @Singleton
// public final class FileInfo {
//
// public AndroidDeviceImpl device;
// public String path;
// public String attribs;
// public boolean directory;
// public String name;
//
// @Inject
// public FileInfo() {
// }
//
// public File downloadTemporary() {
// try {
// File tempFile = File.createTempFile("android", name);
// device.pullFile(path + name, tempFile);
// tempFile.deleteOnExit();
// return tempFile;
// } catch (IOException ex) {
// throw new IORuntimeException(ex);
// }
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/injector/OutputStreamShellOutputReceiver.java
// public final class OutputStreamShellOutputReceiver implements IShellOutputReceiver {
//
// private final OutputStream os;
//
// public OutputStreamShellOutputReceiver(OutputStream os) {
// this.os = os;
// }
//
// @Override
// public void addOutput(byte[] buf, int off, int len) {
// try {
// os.write(buf, off, len);
// } catch (IOException e) {
// throw new IORuntimeException(e);
// }
// }
//
// @Override
// public void flush() {
// try {
// os.flush();
// } catch (IOException e) {
// throw new IORuntimeException(e);
// }
// }
//
// @Override
// public boolean isCancelled() {
// return false;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/ExecuteCommandException.java
// public final class ExecuteCommandException extends AndroidScreenCastRuntimeException {
//
// public ExecuteCommandException(String command) {
// super(String.format("Cannot execute command '%s'.", command));
// }
// }
| import java.util.ArrayList;
import java.util.List;
import static org.slf4j.LoggerFactory.getLogger;
import com.android.ddmlib.IDevice;
import com.android.ddmlib.SyncService;
import com.github.xsavikx.androidscreencast.api.file.FileInfo;
import com.github.xsavikx.androidscreencast.api.injector.OutputStreamShellOutputReceiver;
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import com.github.xsavikx.androidscreencast.exception.ExecuteCommandException;
import org.slf4j.Logger;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.nio.charset.StandardCharsets; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api;
@Singleton
public final class AndroidDeviceImpl implements AndroidDevice {
private final IDevice device;
@Inject
public AndroidDeviceImpl(final IDevice device) {
this.device = device;
}
@Override
public String executeCommand(final String cmd) {
log().debug("Executing command: `{}`.", cmd);
try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
device.executeShellCommand(cmd, new OutputStreamShellOutputReceiver(bos));
final String result = new String(bos.toByteArray(), StandardCharsets.UTF_8);
log().debug("Command `{}` executed with result: `{}`.", cmd, result);
return result;
} catch (final Exception ex) {
log().error("Unable to execute command `{}`.", cmd, ex);
throw new ExecuteCommandException(cmd);
}
}
@Override | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java
// @Singleton
// public final class FileInfo {
//
// public AndroidDeviceImpl device;
// public String path;
// public String attribs;
// public boolean directory;
// public String name;
//
// @Inject
// public FileInfo() {
// }
//
// public File downloadTemporary() {
// try {
// File tempFile = File.createTempFile("android", name);
// device.pullFile(path + name, tempFile);
// tempFile.deleteOnExit();
// return tempFile;
// } catch (IOException ex) {
// throw new IORuntimeException(ex);
// }
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/injector/OutputStreamShellOutputReceiver.java
// public final class OutputStreamShellOutputReceiver implements IShellOutputReceiver {
//
// private final OutputStream os;
//
// public OutputStreamShellOutputReceiver(OutputStream os) {
// this.os = os;
// }
//
// @Override
// public void addOutput(byte[] buf, int off, int len) {
// try {
// os.write(buf, off, len);
// } catch (IOException e) {
// throw new IORuntimeException(e);
// }
// }
//
// @Override
// public void flush() {
// try {
// os.flush();
// } catch (IOException e) {
// throw new IORuntimeException(e);
// }
// }
//
// @Override
// public boolean isCancelled() {
// return false;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/ExecuteCommandException.java
// public final class ExecuteCommandException extends AndroidScreenCastRuntimeException {
//
// public ExecuteCommandException(String command) {
// super(String.format("Cannot execute command '%s'.", command));
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java
import java.util.ArrayList;
import java.util.List;
import static org.slf4j.LoggerFactory.getLogger;
import com.android.ddmlib.IDevice;
import com.android.ddmlib.SyncService;
import com.github.xsavikx.androidscreencast.api.file.FileInfo;
import com.github.xsavikx.androidscreencast.api.injector.OutputStreamShellOutputReceiver;
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import com.github.xsavikx.androidscreencast.exception.ExecuteCommandException;
import org.slf4j.Logger;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.nio.charset.StandardCharsets;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api;
@Singleton
public final class AndroidDeviceImpl implements AndroidDevice {
private final IDevice device;
@Inject
public AndroidDeviceImpl(final IDevice device) {
this.device = device;
}
@Override
public String executeCommand(final String cmd) {
log().debug("Executing command: `{}`.", cmd);
try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
device.executeShellCommand(cmd, new OutputStreamShellOutputReceiver(bos));
final String result = new String(bos.toByteArray(), StandardCharsets.UTF_8);
log().debug("Command `{}` executed with result: `{}`.", cmd, result);
return result;
} catch (final Exception ex) {
log().error("Unable to execute command `{}`.", cmd, ex);
throw new ExecuteCommandException(cmd);
}
}
@Override | public List<FileInfo> list(final String path) { |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java
// @Singleton
// public final class FileInfo {
//
// public AndroidDeviceImpl device;
// public String path;
// public String attribs;
// public boolean directory;
// public String name;
//
// @Inject
// public FileInfo() {
// }
//
// public File downloadTemporary() {
// try {
// File tempFile = File.createTempFile("android", name);
// device.pullFile(path + name, tempFile);
// tempFile.deleteOnExit();
// return tempFile;
// } catch (IOException ex) {
// throw new IORuntimeException(ex);
// }
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/injector/OutputStreamShellOutputReceiver.java
// public final class OutputStreamShellOutputReceiver implements IShellOutputReceiver {
//
// private final OutputStream os;
//
// public OutputStreamShellOutputReceiver(OutputStream os) {
// this.os = os;
// }
//
// @Override
// public void addOutput(byte[] buf, int off, int len) {
// try {
// os.write(buf, off, len);
// } catch (IOException e) {
// throw new IORuntimeException(e);
// }
// }
//
// @Override
// public void flush() {
// try {
// os.flush();
// } catch (IOException e) {
// throw new IORuntimeException(e);
// }
// }
//
// @Override
// public boolean isCancelled() {
// return false;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/ExecuteCommandException.java
// public final class ExecuteCommandException extends AndroidScreenCastRuntimeException {
//
// public ExecuteCommandException(String command) {
// super(String.format("Cannot execute command '%s'.", command));
// }
// }
| import java.util.ArrayList;
import java.util.List;
import static org.slf4j.LoggerFactory.getLogger;
import com.android.ddmlib.IDevice;
import com.android.ddmlib.SyncService;
import com.github.xsavikx.androidscreencast.api.file.FileInfo;
import com.github.xsavikx.androidscreencast.api.injector.OutputStreamShellOutputReceiver;
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import com.github.xsavikx.androidscreencast.exception.ExecuteCommandException;
import org.slf4j.Logger;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.nio.charset.StandardCharsets; | }
@Override
public List<FileInfo> list(final String path) {
log().debug("Listing files under path: `{}`.", path);
try {
final String s = executeCommand("ls -l " + path);
final String[] entries = s.split("\r\n");
final List<FileInfo> fileInfos = new ArrayList<>();
for (final String entry : entries) {
String[] data = entry.split(" ");
if (data.length < 4)
continue;
String attributes = data[0];
boolean directory = attributes.charAt(0) == 'd';
String name = data[data.length - 1];
final FileInfo fi = new FileInfo();
fi.attribs = attributes;
fi.directory = directory;
fi.name = name;
fi.path = path;
fi.device = this;
fileInfos.add(fi);
}
log().debug("Found `{}` files under path `{}`.", fileInfos.size(), path);
return fileInfos;
} catch (final Exception ex) {
log().error("Unable to list files under path `{}`.", path, ex); | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java
// @Singleton
// public final class FileInfo {
//
// public AndroidDeviceImpl device;
// public String path;
// public String attribs;
// public boolean directory;
// public String name;
//
// @Inject
// public FileInfo() {
// }
//
// public File downloadTemporary() {
// try {
// File tempFile = File.createTempFile("android", name);
// device.pullFile(path + name, tempFile);
// tempFile.deleteOnExit();
// return tempFile;
// } catch (IOException ex) {
// throw new IORuntimeException(ex);
// }
// }
//
// @Override
// public String toString() {
// return name;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/injector/OutputStreamShellOutputReceiver.java
// public final class OutputStreamShellOutputReceiver implements IShellOutputReceiver {
//
// private final OutputStream os;
//
// public OutputStreamShellOutputReceiver(OutputStream os) {
// this.os = os;
// }
//
// @Override
// public void addOutput(byte[] buf, int off, int len) {
// try {
// os.write(buf, off, len);
// } catch (IOException e) {
// throw new IORuntimeException(e);
// }
// }
//
// @Override
// public void flush() {
// try {
// os.flush();
// } catch (IOException e) {
// throw new IORuntimeException(e);
// }
// }
//
// @Override
// public boolean isCancelled() {
// return false;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/AndroidScreenCastRuntimeException.java
// public class AndroidScreenCastRuntimeException extends RuntimeException {
//
// private String additionalInformation;
//
// public AndroidScreenCastRuntimeException() {
// }
//
// public AndroidScreenCastRuntimeException(String message) {
// super(message);
// }
//
//
// public AndroidScreenCastRuntimeException(String message, String additionalInformation) {
// super(message);
// this.additionalInformation = additionalInformation;
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause) {
// super(message, cause);
// }
//
// public AndroidScreenCastRuntimeException(Throwable cause) {
// super(cause);
// }
//
// public AndroidScreenCastRuntimeException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
//
// public String getAdditionalInformation() {
// return additionalInformation;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/ExecuteCommandException.java
// public final class ExecuteCommandException extends AndroidScreenCastRuntimeException {
//
// public ExecuteCommandException(String command) {
// super(String.format("Cannot execute command '%s'.", command));
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java
import java.util.ArrayList;
import java.util.List;
import static org.slf4j.LoggerFactory.getLogger;
import com.android.ddmlib.IDevice;
import com.android.ddmlib.SyncService;
import com.github.xsavikx.androidscreencast.api.file.FileInfo;
import com.github.xsavikx.androidscreencast.api.injector.OutputStreamShellOutputReceiver;
import com.github.xsavikx.androidscreencast.exception.AndroidScreenCastRuntimeException;
import com.github.xsavikx.androidscreencast.exception.ExecuteCommandException;
import org.slf4j.Logger;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.nio.charset.StandardCharsets;
}
@Override
public List<FileInfo> list(final String path) {
log().debug("Listing files under path: `{}`.", path);
try {
final String s = executeCommand("ls -l " + path);
final String[] entries = s.split("\r\n");
final List<FileInfo> fileInfos = new ArrayList<>();
for (final String entry : entries) {
String[] data = entry.split(" ");
if (data.length < 4)
continue;
String attributes = data[0];
boolean directory = attributes.charAt(0) == 'd';
String name = data[data.length - 1];
final FileInfo fi = new FileInfo();
fi.attribs = attributes;
fi.directory = directory;
fi.name = name;
fi.path = path;
fi.device = this;
fileInfos.add(fi);
}
log().debug("Found `{}` files under path `{}`.", fileInfos.size(), path);
return fileInfos;
} catch (final Exception ex) {
log().error("Unable to list files under path `{}`.", path, ex); | throw new AndroidScreenCastRuntimeException(ex); |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java
// @Singleton
// public final class AndroidDeviceImpl implements AndroidDevice {
//
// private final IDevice device;
//
// @Inject
// public AndroidDeviceImpl(final IDevice device) {
// this.device = device;
// }
//
// @Override
// public String executeCommand(final String cmd) {
// log().debug("Executing command: `{}`.", cmd);
// try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
// device.executeShellCommand(cmd, new OutputStreamShellOutputReceiver(bos));
// final String result = new String(bos.toByteArray(), StandardCharsets.UTF_8);
// log().debug("Command `{}` executed with result: `{}`.", cmd, result);
// return result;
// } catch (final Exception ex) {
// log().error("Unable to execute command `{}`.", cmd, ex);
// throw new ExecuteCommandException(cmd);
// }
// }
//
// @Override
// public List<FileInfo> list(final String path) {
// log().debug("Listing files under path: `{}`.", path);
// try {
// final String s = executeCommand("ls -l " + path);
// final String[] entries = s.split("\r\n");
// final List<FileInfo> fileInfos = new ArrayList<>();
// for (final String entry : entries) {
// String[] data = entry.split(" ");
// if (data.length < 4)
// continue;
// String attributes = data[0];
// boolean directory = attributes.charAt(0) == 'd';
// String name = data[data.length - 1];
//
// final FileInfo fi = new FileInfo();
// fi.attribs = attributes;
// fi.directory = directory;
// fi.name = name;
// fi.path = path;
// fi.device = this;
//
// fileInfos.add(fi);
// }
// log().debug("Found `{}` files under path `{}`.", fileInfos.size(), path);
// return fileInfos;
// } catch (final Exception ex) {
// log().error("Unable to list files under path `{}`.", path, ex);
// throw new AndroidScreenCastRuntimeException(ex);
// }
// }
//
// @Override
// public void openUrl(final String url) {
// log().debug("Opening URL: `{}`.", url);
// executeCommand("am start " + url);
// }
//
// @Override
// public void pullFile(final String remote, final File local) {
// log().debug("Pulling remote file `{}` to the local destination: `{}`.", remote, local);
// // ugly hack to call the method without FileEntry
// try {
// if (device.getSyncService() == null)
// throw new AndroidScreenCastRuntimeException("SyncService is null, ADB crashed ?");
// device.getSyncService().pullFile(remote, local.getAbsolutePath(), SyncService.getNullProgressMonitor());
// log().debug("Remote file `{}` pulled to the local destination: `{}`.", remote, local);
// } catch (final Exception ex) {
// log().error("Unable to pull remote file `{}` to the local destination: `{}`.", remote, local, ex);
// throw new AndroidScreenCastRuntimeException(ex);
// }
// }
//
// @Override
// public void pushFile(final File local, final String remote) {
// log().debug("Pushing local file `{}` to the remote destination: `{}`.", local, remote);
// try {
// if (device.getSyncService() == null)
// throw new AndroidScreenCastRuntimeException("SyncService is null, ADB crashed ?");
// device.getSyncService().pushFile(local.getAbsolutePath(), remote, SyncService.getNullProgressMonitor());
// log().debug("Local file `{}` pushed to the remote destination: `{}`.", local, remote);
// } catch (final Exception ex) {
// log().error("Unable to push local file `{}` to the remote destination: `{}`.", local, remote, ex);
// throw new AndroidScreenCastRuntimeException(ex);
// }
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(AndroidDeviceImpl.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IORuntimeException.java
// public final class IORuntimeException extends AndroidScreenCastRuntimeException {
//
// public IORuntimeException(String message, IOException cause) {
// super(message, cause);
// }
//
// public IORuntimeException(IOException cause) {
// super(cause);
// }
//
// public IORuntimeException(String message, IOException cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
| import com.github.xsavikx.androidscreencast.api.AndroidDeviceImpl;
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.File;
import java.io.IOException; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api.file;
@Singleton
public final class FileInfo {
| // Path: src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java
// @Singleton
// public final class AndroidDeviceImpl implements AndroidDevice {
//
// private final IDevice device;
//
// @Inject
// public AndroidDeviceImpl(final IDevice device) {
// this.device = device;
// }
//
// @Override
// public String executeCommand(final String cmd) {
// log().debug("Executing command: `{}`.", cmd);
// try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
// device.executeShellCommand(cmd, new OutputStreamShellOutputReceiver(bos));
// final String result = new String(bos.toByteArray(), StandardCharsets.UTF_8);
// log().debug("Command `{}` executed with result: `{}`.", cmd, result);
// return result;
// } catch (final Exception ex) {
// log().error("Unable to execute command `{}`.", cmd, ex);
// throw new ExecuteCommandException(cmd);
// }
// }
//
// @Override
// public List<FileInfo> list(final String path) {
// log().debug("Listing files under path: `{}`.", path);
// try {
// final String s = executeCommand("ls -l " + path);
// final String[] entries = s.split("\r\n");
// final List<FileInfo> fileInfos = new ArrayList<>();
// for (final String entry : entries) {
// String[] data = entry.split(" ");
// if (data.length < 4)
// continue;
// String attributes = data[0];
// boolean directory = attributes.charAt(0) == 'd';
// String name = data[data.length - 1];
//
// final FileInfo fi = new FileInfo();
// fi.attribs = attributes;
// fi.directory = directory;
// fi.name = name;
// fi.path = path;
// fi.device = this;
//
// fileInfos.add(fi);
// }
// log().debug("Found `{}` files under path `{}`.", fileInfos.size(), path);
// return fileInfos;
// } catch (final Exception ex) {
// log().error("Unable to list files under path `{}`.", path, ex);
// throw new AndroidScreenCastRuntimeException(ex);
// }
// }
//
// @Override
// public void openUrl(final String url) {
// log().debug("Opening URL: `{}`.", url);
// executeCommand("am start " + url);
// }
//
// @Override
// public void pullFile(final String remote, final File local) {
// log().debug("Pulling remote file `{}` to the local destination: `{}`.", remote, local);
// // ugly hack to call the method without FileEntry
// try {
// if (device.getSyncService() == null)
// throw new AndroidScreenCastRuntimeException("SyncService is null, ADB crashed ?");
// device.getSyncService().pullFile(remote, local.getAbsolutePath(), SyncService.getNullProgressMonitor());
// log().debug("Remote file `{}` pulled to the local destination: `{}`.", remote, local);
// } catch (final Exception ex) {
// log().error("Unable to pull remote file `{}` to the local destination: `{}`.", remote, local, ex);
// throw new AndroidScreenCastRuntimeException(ex);
// }
// }
//
// @Override
// public void pushFile(final File local, final String remote) {
// log().debug("Pushing local file `{}` to the remote destination: `{}`.", local, remote);
// try {
// if (device.getSyncService() == null)
// throw new AndroidScreenCastRuntimeException("SyncService is null, ADB crashed ?");
// device.getSyncService().pushFile(local.getAbsolutePath(), remote, SyncService.getNullProgressMonitor());
// log().debug("Local file `{}` pushed to the remote destination: `{}`.", local, remote);
// } catch (final Exception ex) {
// log().error("Unable to push local file `{}` to the remote destination: `{}`.", local, remote, ex);
// throw new AndroidScreenCastRuntimeException(ex);
// }
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(AndroidDeviceImpl.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IORuntimeException.java
// public final class IORuntimeException extends AndroidScreenCastRuntimeException {
//
// public IORuntimeException(String message, IOException cause) {
// super(message, cause);
// }
//
// public IORuntimeException(IOException cause) {
// super(cause);
// }
//
// public IORuntimeException(String message, IOException cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java
import com.github.xsavikx.androidscreencast.api.AndroidDeviceImpl;
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.File;
import java.io.IOException;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api.file;
@Singleton
public final class FileInfo {
| public AndroidDeviceImpl device; |
xSAVIKx/AndroidScreencast | src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java
// @Singleton
// public final class AndroidDeviceImpl implements AndroidDevice {
//
// private final IDevice device;
//
// @Inject
// public AndroidDeviceImpl(final IDevice device) {
// this.device = device;
// }
//
// @Override
// public String executeCommand(final String cmd) {
// log().debug("Executing command: `{}`.", cmd);
// try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
// device.executeShellCommand(cmd, new OutputStreamShellOutputReceiver(bos));
// final String result = new String(bos.toByteArray(), StandardCharsets.UTF_8);
// log().debug("Command `{}` executed with result: `{}`.", cmd, result);
// return result;
// } catch (final Exception ex) {
// log().error("Unable to execute command `{}`.", cmd, ex);
// throw new ExecuteCommandException(cmd);
// }
// }
//
// @Override
// public List<FileInfo> list(final String path) {
// log().debug("Listing files under path: `{}`.", path);
// try {
// final String s = executeCommand("ls -l " + path);
// final String[] entries = s.split("\r\n");
// final List<FileInfo> fileInfos = new ArrayList<>();
// for (final String entry : entries) {
// String[] data = entry.split(" ");
// if (data.length < 4)
// continue;
// String attributes = data[0];
// boolean directory = attributes.charAt(0) == 'd';
// String name = data[data.length - 1];
//
// final FileInfo fi = new FileInfo();
// fi.attribs = attributes;
// fi.directory = directory;
// fi.name = name;
// fi.path = path;
// fi.device = this;
//
// fileInfos.add(fi);
// }
// log().debug("Found `{}` files under path `{}`.", fileInfos.size(), path);
// return fileInfos;
// } catch (final Exception ex) {
// log().error("Unable to list files under path `{}`.", path, ex);
// throw new AndroidScreenCastRuntimeException(ex);
// }
// }
//
// @Override
// public void openUrl(final String url) {
// log().debug("Opening URL: `{}`.", url);
// executeCommand("am start " + url);
// }
//
// @Override
// public void pullFile(final String remote, final File local) {
// log().debug("Pulling remote file `{}` to the local destination: `{}`.", remote, local);
// // ugly hack to call the method without FileEntry
// try {
// if (device.getSyncService() == null)
// throw new AndroidScreenCastRuntimeException("SyncService is null, ADB crashed ?");
// device.getSyncService().pullFile(remote, local.getAbsolutePath(), SyncService.getNullProgressMonitor());
// log().debug("Remote file `{}` pulled to the local destination: `{}`.", remote, local);
// } catch (final Exception ex) {
// log().error("Unable to pull remote file `{}` to the local destination: `{}`.", remote, local, ex);
// throw new AndroidScreenCastRuntimeException(ex);
// }
// }
//
// @Override
// public void pushFile(final File local, final String remote) {
// log().debug("Pushing local file `{}` to the remote destination: `{}`.", local, remote);
// try {
// if (device.getSyncService() == null)
// throw new AndroidScreenCastRuntimeException("SyncService is null, ADB crashed ?");
// device.getSyncService().pushFile(local.getAbsolutePath(), remote, SyncService.getNullProgressMonitor());
// log().debug("Local file `{}` pushed to the remote destination: `{}`.", local, remote);
// } catch (final Exception ex) {
// log().error("Unable to push local file `{}` to the remote destination: `{}`.", local, remote, ex);
// throw new AndroidScreenCastRuntimeException(ex);
// }
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(AndroidDeviceImpl.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IORuntimeException.java
// public final class IORuntimeException extends AndroidScreenCastRuntimeException {
//
// public IORuntimeException(String message, IOException cause) {
// super(message, cause);
// }
//
// public IORuntimeException(IOException cause) {
// super(cause);
// }
//
// public IORuntimeException(String message, IOException cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
| import com.github.xsavikx.androidscreencast.api.AndroidDeviceImpl;
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.File;
import java.io.IOException; | /*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api.file;
@Singleton
public final class FileInfo {
public AndroidDeviceImpl device;
public String path;
public String attribs;
public boolean directory;
public String name;
@Inject
public FileInfo() {
}
public File downloadTemporary() {
try {
File tempFile = File.createTempFile("android", name);
device.pullFile(path + name, tempFile);
tempFile.deleteOnExit();
return tempFile;
} catch (IOException ex) { | // Path: src/main/java/com/github/xsavikx/androidscreencast/api/AndroidDeviceImpl.java
// @Singleton
// public final class AndroidDeviceImpl implements AndroidDevice {
//
// private final IDevice device;
//
// @Inject
// public AndroidDeviceImpl(final IDevice device) {
// this.device = device;
// }
//
// @Override
// public String executeCommand(final String cmd) {
// log().debug("Executing command: `{}`.", cmd);
// try (final ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
// device.executeShellCommand(cmd, new OutputStreamShellOutputReceiver(bos));
// final String result = new String(bos.toByteArray(), StandardCharsets.UTF_8);
// log().debug("Command `{}` executed with result: `{}`.", cmd, result);
// return result;
// } catch (final Exception ex) {
// log().error("Unable to execute command `{}`.", cmd, ex);
// throw new ExecuteCommandException(cmd);
// }
// }
//
// @Override
// public List<FileInfo> list(final String path) {
// log().debug("Listing files under path: `{}`.", path);
// try {
// final String s = executeCommand("ls -l " + path);
// final String[] entries = s.split("\r\n");
// final List<FileInfo> fileInfos = new ArrayList<>();
// for (final String entry : entries) {
// String[] data = entry.split(" ");
// if (data.length < 4)
// continue;
// String attributes = data[0];
// boolean directory = attributes.charAt(0) == 'd';
// String name = data[data.length - 1];
//
// final FileInfo fi = new FileInfo();
// fi.attribs = attributes;
// fi.directory = directory;
// fi.name = name;
// fi.path = path;
// fi.device = this;
//
// fileInfos.add(fi);
// }
// log().debug("Found `{}` files under path `{}`.", fileInfos.size(), path);
// return fileInfos;
// } catch (final Exception ex) {
// log().error("Unable to list files under path `{}`.", path, ex);
// throw new AndroidScreenCastRuntimeException(ex);
// }
// }
//
// @Override
// public void openUrl(final String url) {
// log().debug("Opening URL: `{}`.", url);
// executeCommand("am start " + url);
// }
//
// @Override
// public void pullFile(final String remote, final File local) {
// log().debug("Pulling remote file `{}` to the local destination: `{}`.", remote, local);
// // ugly hack to call the method without FileEntry
// try {
// if (device.getSyncService() == null)
// throw new AndroidScreenCastRuntimeException("SyncService is null, ADB crashed ?");
// device.getSyncService().pullFile(remote, local.getAbsolutePath(), SyncService.getNullProgressMonitor());
// log().debug("Remote file `{}` pulled to the local destination: `{}`.", remote, local);
// } catch (final Exception ex) {
// log().error("Unable to pull remote file `{}` to the local destination: `{}`.", remote, local, ex);
// throw new AndroidScreenCastRuntimeException(ex);
// }
// }
//
// @Override
// public void pushFile(final File local, final String remote) {
// log().debug("Pushing local file `{}` to the remote destination: `{}`.", local, remote);
// try {
// if (device.getSyncService() == null)
// throw new AndroidScreenCastRuntimeException("SyncService is null, ADB crashed ?");
// device.getSyncService().pushFile(local.getAbsolutePath(), remote, SyncService.getNullProgressMonitor());
// log().debug("Local file `{}` pushed to the remote destination: `{}`.", local, remote);
// } catch (final Exception ex) {
// log().error("Unable to push local file `{}` to the remote destination: `{}`.", local, remote, ex);
// throw new AndroidScreenCastRuntimeException(ex);
// }
// }
//
// private enum LogSingleton {
// INSTANCE;
//
// @SuppressWarnings({"NonSerializableFieldInSerializableClass", "ImmutableEnumChecker"})
// private final Logger value = getLogger(AndroidDeviceImpl.class);
// }
//
// private static Logger log() {
// return LogSingleton.INSTANCE.value;
// }
// }
//
// Path: src/main/java/com/github/xsavikx/androidscreencast/exception/IORuntimeException.java
// public final class IORuntimeException extends AndroidScreenCastRuntimeException {
//
// public IORuntimeException(String message, IOException cause) {
// super(message, cause);
// }
//
// public IORuntimeException(IOException cause) {
// super(cause);
// }
//
// public IORuntimeException(String message, IOException cause, boolean enableSuppression, boolean writableStackTrace) {
// super(message, cause, enableSuppression, writableStackTrace);
// }
// }
// Path: src/main/java/com/github/xsavikx/androidscreencast/api/file/FileInfo.java
import com.github.xsavikx.androidscreencast.api.AndroidDeviceImpl;
import com.github.xsavikx.androidscreencast.exception.IORuntimeException;
import javax.inject.Inject;
import javax.inject.Singleton;
import java.io.File;
import java.io.IOException;
/*
* Copyright 2020 Yurii Serhiichuk
*
* 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.xsavikx.androidscreencast.api.file;
@Singleton
public final class FileInfo {
public AndroidDeviceImpl device;
public String path;
public String attribs;
public boolean directory;
public String name;
@Inject
public FileInfo() {
}
public File downloadTemporary() {
try {
File tempFile = File.createTempFile("android", name);
device.pullFile(path + name, tempFile);
tempFile.deleteOnExit();
return tempFile;
} catch (IOException ex) { | throw new IORuntimeException(ex); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.