code
stringlengths
73
34.1k
label
stringclasses
1 value
protected boolean validateCondition(String key,String value) { boolean valid=false; FaxClientSpiConfigurationConstants condition=FaxClientSpiConfigurationConstants.getEnum(key); String propertyValue=null; switch(condition) { case PROPERTY_CONDITION: ...
java
protected void createFaxClientSpi(String type) { //setup fax client SPI configuration Properties configuration=this.createFaxClientSpiConfiguration(); //create fax client SPI this.faxClientSpi=FaxClientSpiFactory.createChildFaxClientSpi(type,configuration); }
java
protected Properties createFaxClientSpiConfiguration() { //get configuration Map<String,String> configuration=this.getConfiguration(); //create new configuration Properties internalSPIConfiguration=new Properties(); Properties overrideConfiguration=new Properties(); ...
java
@ReadOnly public List<String> getSupportedCipherSuites() throws SslException { try { final SSLEngine engine = getDefaultSslEngine(); return ImmutableList.copyOf(engine.getSupportedCipherSuites()); } catch (NoSuchAlgorithmException | KeyManagementException e) { ...
java
protected Transport createTransport(Session session) { Transport transport=null; try { //get the transport transport=session.getTransport(this.transportProtocol); //connect if(this.transportPort>0) { transport.conne...
java
private static File getFax4jInternalTemporaryDirectoryImpl() { File temporaryFile=null; try { //create temporary file temporaryFile=File.createTempFile("temp_",".temp"); } catch(IOException exception) { throw new FaxException("Unabl...
java
private static String getEncodingToUse(String encoding) { //get encoding String updatedEncoding=encoding; if(updatedEncoding==null) { updatedEncoding=IOHelper.getDefaultEncoding(); } return updatedEncoding; }
java
public static byte[] convertStringToBinary(String text,String encoding) { byte[] data=null; if(text!=null) { if(text.length()==0) { data=new byte[0]; } else { //get logger LoggerManage...
java
public static Reader createReader(InputStream inputStream,String encoding) { //get encoding String updatedEncoding=IOHelper.getEncodingToUse(encoding); //create reader Reader reader=null; try { reader=new InputStreamReader(inputStream,updatedEncod...
java
public static Writer createWriter(OutputStream outputStream,String encoding) { //get encoding String updatedEncoding=IOHelper.getEncodingToUse(encoding); //create writer Writer writer=null; try { writer=new OutputStreamWriter(outputStream,updatedE...
java
public static String readTextStream(Reader reader) throws IOException { char[] buffer=new char[5000]; Writer stringWriter=new StringWriter(); int read=-1; try { do { //read next buffer read=reader.read(buffer); ...
java
public static String readTextFile(File file) throws IOException { //create reader to file (with default encoding) InputStream inputStream=new FileInputStream(file); Reader reader=IOHelper.createReader(inputStream,null); //read text String text=IOHelper.readTextStream(reader)...
java
public static void writeTextFile(String text,File file) throws IOException { Writer writer=null; try { //create writer to file (with default encoding) OutputStream outputStream=new FileOutputStream(file); writer=IOHelper.createWriter(outputStream,null); ...
java
public static void readAndWriteStreams(InputStream inputStream,OutputStream outputStream) throws IOException { byte[] buffer=new byte[5000]; int read=-1; try { do { //read next buffer read=inputStream.read(buffer); ...
java
public static byte[] readStream(InputStream inputStream) throws IOException { //create output stream ByteArrayOutputStream outputStream=new ByteArrayOutputStream(5000); //read/write IOHelper.readAndWriteStreams(inputStream,outputStream); //get data b...
java
public static byte[] readFile(File file) throws IOException { //create stream to file InputStream inputStream=new FileInputStream(file); //read data byte[] data=IOHelper.readStream(inputStream); return data; }
java
public static void writeFile(byte[] content,File file) throws IOException { OutputStream outputStream=null; try { //create output stream to file outputStream=new FileOutputStream(file); //write to file outputStream.write(content); ...
java
public static File getFileFromPathList(String fileNameWithNoPath,String[] pathList) { File foundFile=null; if(pathList!=null) { //get amount int amount=pathList.length; String directoryPath=null; File file=null; for(int...
java
public static File getFileFromNativePath(String fileNameWithNoPath) { //get system path String systemPath=System.getProperty("java.library.path"); String pathSeperator=System.getProperty("path.separator"); String[] systemPathElements=systemPath.split(pathSeperator); ...
java
public FaxJob submitFaxJob(T inputData) { if(inputData==null) { throw new FaxException("Input data not provided."); } //create fax job FaxJob faxJob=this.createFaxJob(); //update fax job info this.requestParser.updateFaxJobFromInp...
java
protected String getTargetAddress(Message mailMessage) throws MessagingException { //by default the target address is taken from the mail subject which //is expected to be in the format of: fax:<number> String subject=mailMessage.getSubject(); String targetAddress=null; if((s...
java
protected String getSenderEmail(Message mailMessage) throws MessagingException { Address[] addresses=mailMessage.getFrom(); String senderEmail=null; if((addresses!=null)&&(addresses.length>0)) { //get sender mail address (only first from is used) Address addre...
java
protected Map<String,String> initializeAdditionalParameters() { //get configuration Map<String,String> configuration=this.getConfiguration(); //get property part String propertyPart=this.getPropertyPart(); //get prefix String prefix=FaxJob2HTTPRequestConvert...
java
protected HTTPRequest createCommonHTTPRequest(HTTPFaxClientSpi faxClientSpi,FaxActionType faxActionType) { //setup common request data HTTPRequest httpRequest=new HTTPRequest(); String resource=faxClientSpi.getHTTPResource(faxActionType); httpRequest.setResource(resource); St...
java
protected final void addContentPart(List<ContentPart<?>> contentList,String key,String value) { if((key!=null)&&(value!=null)&&(value.length()>0)) { if(this.shouldAddContentPart(key)) { contentList.add(new ContentPart<String>(key,value,ContentPartType.STRING))...
java
protected final void addAdditionalParameters(List<ContentPart<?>> contentList) { //add additional parameters if(this.additionalParameters!=null) { Iterator<Entry<String,String>> iterator=this.additionalParameters.entrySet().iterator(); Entry<String,String> entry=null;...
java
protected void addAdditionalContentParts(HTTPFaxClientSpi faxClientSpi,FaxActionType faxActionType,FaxJob faxJob,List<ContentPart<?>> contentList) { //empty hook for extending classes }
java
public FileInfo getFileInfoFromInputData(T inputData) { if(!this.initialized) { throw new FaxException("Fax bridge not initialized."); } //get file info FileInfo fileInfo=this.getFileInfoFromInputDataImpl(inputData); return fileInfo; }
java
protected FaxJobStatus getFaxJobStatusFromWindowsFaxJobStatusString(String faxJobStatusStr) { FaxJobStatus faxJobStatus=FaxJobStatus.UNKNOWN; if((faxJobStatusStr!=null)&&(faxJobStatusStr.length()>0)) { if((faxJobStatusStr.equalsIgnoreCase("Pending"))||(faxJobStatusStr.equalsIgnor...
java
protected void updateFaxJob(FaxJob faxJob,HTTPResponse httpResponse,FaxActionType faxActionType) { this.httpResponseHandler.updateFaxJob(faxJob,httpResponse,faxActionType); }
java
public final synchronized void initialize(String type,Properties configuration,Object flowOwner) { if(this.initialized) { throw new FaxException("Fax bridge already initialized."); } //set flag this.initialized=true; //get configuration M...
java
public static void copyPropertiesToMap(Properties source,Map<String,String> target) { if(source!=null) { //convert to map Iterator<Entry<Object,Object>> iterator=source.entrySet().iterator(); Entry<Object,Object> entry=null; String key=null; ...
java
public static String replaceTemplateParameter(String template,String parameter,String value,TemplateParameterEncoder encoder) { String text=template; if((text!=null)&&(parameter!=null)) { String updatedValue=value; if(updatedValue==null) { ...
java
public static String urlEncode(String text) { String urlEncodedString=text; if(text!=null) { try { urlEncodedString=URLEncoder.encode(text,SpiUtil.UTF_8_ENCODING_NAME); } catch(UnsupportedEncodingException exception) ...
java
public static String urlDecode(String text) { String urlEncodedString=text; if(text!=null) { try { urlEncodedString=URLDecoder.decode(text,SpiUtil.UTF_8_ENCODING_NAME); } catch(UnsupportedEncodingException exception) ...
java
private static String getFileParameterValue(FaxJob faxJob) { String value=null; File file=faxJob.getFile(); if(file!=null) { try { //read file (only text files supported) value=IOHelper.readTextFile(faxJob.getFile()); ...
java
@Override protected void initializeImpl() { //init data structures this.data=new HashMap<FaxClientSpi,Map<FaxJob,FaxJobStatus>>(20); //get polling interval String value=this.getConfigurationValue(FaxJobMonitorImpl.POLLING_INTERVAL_IN_MILLIES_PROPERTY_KEY); this.pollingIn...
java
protected void runPollingCycle() { synchronized(this.LOCK) { Set<Entry<FaxClientSpi,Map<FaxJob,FaxJobStatus>>> entrySet=this.data.entrySet(); Iterator<Entry<FaxClientSpi,Map<FaxJob,FaxJobStatus>>> faxClientSpiIterator=entrySet.iterator(); Entry<FaxClientSpi,Map<Fa...
java
protected final String getConfigurationValue(String key) { //get value String value=this.monitorConfiguration.get(key); //trim value if(value!=null) { value=value.trim(); //set as null if empty string if(value.length()...
java
public static void loadNativeLibrary(Logger logger) { synchronized(WindowsFaxClientSpiHelper.NATIVE_LOCK) { if(!WindowsFaxClientSpiHelper.nativeLibraryLoaded) { try { //get temporary directory File direct...
java
public static String getServerNameFromConfiguration(FaxClientSpi faxClientSpi) { //get logger Logger logger=faxClientSpi.getLogger(); //get fax server name String faxServerName=faxClientSpi.getConfigurationValue(FaxClientSpiConfigurationConstants.FAX_SERVER_NAME_PROPERTY_KEY...
java
public static String getOutputPart(ProcessOutput processOutput,String prefix) { //get output String output=processOutput.getOutputText(); if(output!=null) { //set flag boolean validOutput=false; int index=output.indexOf(prefix); if(in...
java
public InputStream getInputStream() { InputStream stream=null; try { stream=this.commPort.getInputStream(); } catch(IOException exception) { throw new FaxException("Unable to extract input stream.",exception); } return ...
java
public OutputStream getOutputStream() { OutputStream stream=null; try { stream=this.commPort.getOutputStream(); } catch(IOException exception) { throw new FaxException("Unable to extract output stream.",exception); } re...
java
private static Logger getLogger() { if(FaxClientSpiFactory.logger==null) { synchronized(FaxClientSpiFactory.class) { if(FaxClientSpiFactory.logger==null) { //get logger manager LoggerManager loggerManager...
java
private static FaxJobMonitor getFaxJobMonitor() { //get system configuration Map<String,String> systemConfig=LibraryConfigurationLoader.getSystemConfiguration(); if(FaxClientSpiFactory.faxJobMonitor==null) { synchronized(FaxClientSpiFactory.class) { ...
java
private static FaxJobMonitor createFaxJobMonitor(Map<String,String> systemConfig) { //get class name String className=systemConfig.get(FaxClientSpiFactory.FAX_JOB_MONITOR_CLASS_NAME_PROPERTY_KEY); if((className==null)||(className.length()==0)) { className=FaxJobMonitorImp...
java
private static FaxClientSpiProxy createFaxClientSpiProxy(FaxClientSpi faxClientSpi) { //create fax client SPI interceptors FaxClientSpiInterceptor[] interceptors=FaxClientSpiFactory.createFaxClientSpiInterceptors(faxClientSpi); //get class name String className=faxClientSpi....
java
private static FaxClientSpiInterceptor[] createFaxClientSpiInterceptors(FaxClientSpi faxClientSpi) { //get type list String typeListStr=faxClientSpi.getConfigurationValue(FaxClientSpiFactory.SPI_INTERCEPTOR_LIST_PROPERTY_KEY); FaxClientSpiInterceptor[] interceptors=null; if(typeListS...
java
protected void preNativeCall() { //get logger Logger logger=this.getLogger(); //get log level LogLevel logLevel=logger.getLogLevel(); boolean debugMode=false; if(logLevel.equals(LogLevel.DEBUG)) { debugMode=true; } ...
java
private String winGetFaxJobStatus(String serverName,int faxJobID) { String status=null; synchronized(WindowsFaxClientSpiHelper.NATIVE_LOCK) { //pre native call this.preNativeCall(); //invoke native status=WindowsJNIFaxClientSpi.get...
java
protected String getContentPartAsString(Map<String,ContentPart<?>> contentPartsMap,String parameter) { //get part String stringValue=null; ContentPart<?> contentPart=contentPartsMap.get(parameter); if(contentPart!=null) { ContentPartType contentPartType=contentPar...
java
protected Map<String,ContentPart<?>> getContentPartsAsMap(HTTPRequest httpRequest) { Map<String,ContentPart<?>> contentPartsMap=null; ContentType contentType=httpRequest.getContentType(); switch(contentType) { case MULTI_PART: //init map co...
java
public static String getProductInfoPrintout() { //read properties Properties properties=LibraryConfigurationLoader.readInternalConfiguration(); //get values String name=properties.getProperty("org.fax4j.product.name"); String version=properties.getProperty("org.fax4j.product...
java
protected List<String> parseCommand(ConfigurationHolder configurationHolder,String command) { //init list List<String> commandList=new LinkedList<String>(); StringBuilder buffer=new StringBuilder(command); String part=null; int quoteIndex=-1; int spaceIndex=-1; ...
java
public void initialize(FaxClientSpi faxClientSpi) { if(this.initialized) { throw new FaxException("Fax Modem Adapter already initialized."); } //set flag this.initialized=true; //get logger Logger logger=faxClientSpi.getLogger(); ...
java
protected final MailConnectionFactory createMailConnectionFactoryImpl(String className) { String factoryClassName=className; if(factoryClassName==null) { factoryClassName=MailConnectionFactoryImpl.class.getName(); } //create new instance MailConnectionFac...
java
protected Connection<MailResourcesHolder> createMailConnection() { //create new connection Connection<MailResourcesHolder> mailConnection=this.connectionFactory.createConnection(); //log debug Logger logger=this.getLogger(); logger.logInfo(new Object[]{"Created mail connecti...
java
protected void closeMailConnection(Connection<MailResourcesHolder> mailConnection) throws IOException { if(mailConnection!=null) { //get logger Logger logger=this.getLogger(); //release connection logger.logInfo(new Object[]{"Closing mail ...
java
protected Connection<MailResourcesHolder> getMailConnection() { Connection<MailResourcesHolder> mailConnection=null; if(this.usePersistentConnection) { synchronized(this) { if(this.connection==null) { //create new co...
java
protected void sendMail(FaxJob faxJob,Connection<MailResourcesHolder> mailConnection,Message message) { if(message==null) { this.throwUnsupportedException(); } else { //get holder MailResourcesHolder mailResourcesHolder=mailConnection.getRe...
java
@Override protected void updateFaxJobWithFileInfo(FaxJob faxJob,FileInfo fileInfo) { //get file File file=fileInfo.getFile(); if(file==null) { //get file name String fileName=fileInfo.getName(); //get file content byte...
java
protected Map<String,String> convertParametersTextToMap(HTTPRequest request) { //init data structure Map<String,String> map=new HashMap<String,String>(); //get parameters text String parametersText=request.getParametersText(); if(parametersText!=null) { ...
java
protected String createSubmitFaxCommand(FaxJob faxJob) { //init buffer StringBuilder buffer=new StringBuilder(); //create command buffer.append(this.submitCommand); buffer.append(" "); buffer.append(this.printQueueParameter); buffer.append(" "); ...
java
protected ProcessOutput executeProcess(String command,FaxActionType faxActionType) { //execute process ProcessOutput processOutput=ProcessExecutorHelper.executeProcess(this,command); //validate process output this.processOutputValidator.validateProcessOutput(this,processOutput,faxAc...
java
protected String formatLogMessage(LogLevel level,Object[] message,Throwable throwable) { //get text String messageText=this.format(message); String throwableText=this.format(throwable); //init buffer StringBuilder buffer=new StringBuilder(); //append prefix ...
java
protected String format(Object[] message) { String text=null; if(message!=null) { //init buffer StringBuilder buffer=new StringBuilder(); //get array size int amount=message.length; Object object=null; ...
java
protected String format(Throwable throwable) { String text=null; if(throwable!=null) { //init writer StringWriter writer=new StringWriter(1500); //write throwable throwable.printStackTrace(new PrintWriter(writer)); ...
java
public final void setLogLevel(LogLevel logLevel) { LogLevel updatedLogLevel=logLevel; if(updatedLogLevel==null) { updatedLogLevel=LogLevel.NONE; } this.logLevel=updatedLogLevel; }
java
public void logDebug(Object[] message,Throwable throwable) { this.log(LogLevel.DEBUG,message,throwable); }
java
public void logInfo(Object[] message,Throwable throwable) { this.log(LogLevel.INFO,message,throwable); }
java
public void logError(Object[] message,Throwable throwable) { this.log(LogLevel.ERROR,message,throwable); }
java
public final void fireFaxMonitorEvent(FaxMonitorEventID id,FaxJob faxJob,FaxJobStatus faxJobStatus) { this.fireFaxEvent(id,faxJob,faxJobStatus); }
java
protected void invokeFaxJobIDValidation(FaxJob faxJob) { //validate fax job is not null this.invokeFaxJobNullValidation(faxJob); //validate fax job ID String faxJobID=faxJob.getID(); if((faxJobID==null)||(faxJobID.length()==0)) { throw new FaxException("F...
java
public final void setHeaderProperties(Properties headerProperties) { this.headerProperties=null; if(headerProperties!=null) { this.headerProperties=new Properties(); this.headerProperties.putAll(headerProperties); } }
java
public HTTPClientConfiguration createHTTPClientConfiguration(ConfigurationHolder configurationHolder) { //get server values String hostName=configurationHolder.getConfigurationValue(HTTPClientConfigurationConstants.HOST_NAME_PROPERTY_KEY); if(hostName==null) { throw new F...
java
public static File findAbsoluteAndRelative(final String fileLocation) { final File file = new File(fileLocation); if (file.isAbsolute()) { return file; } else { return new File(getHiveMQHomeFolder(), fileLocation); } }
java
protected HttpMethodBase createMethod(String url,HTTPMethod httpMethod) { if(httpMethod==null) { throw new FaxException("HTTP method not provided."); } if((url==null)||(url.length()==0)) { throw new FaxException("HTTP URL not provided."); } ...
java
protected HTTPResponse createHTTPResponse(int statusCode,String responseContent) { //create HTTP response HTTPResponse httpResponse=new HTTPResponse(); httpResponse.setStatusCode(statusCode); httpResponse.setContent(responseContent); return httpResponse; }
java
protected void appendParameters(StringBuilder buffer,String parameters) { if((parameters!=null)&&(parameters.length()>0)) { String updatedParameters=parameters; if(parameters.startsWith("?")) { updatedParameters=parameters.substring(1); ...
java
protected String createURL(HTTPRequest httpRequest,HTTPClientConfiguration configuration) { //init buffer StringBuilder buffer=new StringBuilder(100); //create URL String resource=httpRequest.getResource(); this.appendBaseURL(buffer,resource,configuration); String pa...
java
protected void setupHTTPRequestHeaderProperties(HTTPRequest httpRequest,HttpMethodBase httpMethodClient) { //setup header properties Properties headerProperties=httpRequest.getHeaderProperties(); if(headerProperties!=null) { Iterator<Entry<Object,Object>> iterator=headerP...
java
protected RequestEntity createStringRequestContent(HTTPRequest httpRequest) { RequestEntity requestEntity=null; String contentString=httpRequest.getContentAsString(); if(contentString!=null) { try { requestEntity=new StringRequestEntity(content...
java
protected RequestEntity createBinaryRequestContent(HTTPRequest httpRequest) { RequestEntity requestEntity=null; byte[] contentBinary=httpRequest.getContentAsBinary(); if(contentBinary!=null) { requestEntity=new ByteArrayRequestEntity(contentBinary,"binary/octet-stream"); ...
java
protected RequestEntity createMultiPartRequestContent(HTTPRequest httpRequest,HttpMethodBase httpMethodClient) { RequestEntity requestEntity=null; ContentPart<?>[] contentParts=httpRequest.getContentAsParts(); if(contentParts!=null) { int partsAmount=contentParts.length; ...
java
protected void setRequestContent(HTTPRequest httpRequest,HttpMethodBase httpMethodClient) { //set content if(httpMethodClient instanceof EntityEnclosingMethod) { EntityEnclosingMethod pushMethod=(EntityEnclosingMethod)httpMethodClient; RequestEntity reque...
java
public void releaseConnection(Connection<T> connection) { if(connection!=null) { try { //log info this.LOGGER.logInfo(new Object[]{"Closing connection using factory type: ",this.getClass().getName()},null); //get resource ...
java
protected final HylaFAXClientConnectionFactory createHylaFAXClientConnectionFactory(String className) { //create new instance HylaFAXClientConnectionFactory factory=(HylaFAXClientConnectionFactory)ReflectionHelper.createInstance(className); //initialize factory.initializ...
java
protected synchronized HylaFAXClient getHylaFAXClient() { HylaFAXClient client=null; if(this.connection==null) { //create new connection this.connection=this.connectionFactory.createConnection(); } //get client client=this.connection.g...
java
public static ClassLoader getThreadContextClassLoader() { Thread thread=Thread.currentThread(); ClassLoader classLoader=thread.getContextClassLoader(); return classLoader; }
java
public static Class<?> getType(String className) { ClassLoader classLoader=ReflectionHelper.getThreadContextClassLoader(); Class<?> type=null; try { //load class definition type=classLoader.loadClass(className); } catch(ClassNotFoundException e...
java
public static Object invokeMethod(Class<?> type,Object instance,String methodName,Class<?>[] inputTypes,Object[] input) { Method method=null; try { //get method method=type.getDeclaredMethod(methodName,inputTypes); } catch(Exception exception) ...
java
public static Field getField(Class<?> type,String fieldName) { Field field=null; try { //get field field=type.getDeclaredField(fieldName); } catch(Exception exception) { throw new FaxException("Unable to extract field: "+fieldName+"...
java
protected ProcessOutputValidator createProcessOutputValidator() { //get process output validator String className=this.getConfigurationValue(FaxClientSpiConfigurationConstants.PROCESS_OUTPUT_VALIDATOR_PRE_FORMAT_PROPERTY_KEY); ProcessOutputValidator validator=null; if(className==null...
java
protected ProcessOutputHandler createProcessOutputHandler() { //get process output handler String className=this.getConfigurationValue(FaxClientSpiConfigurationConstants.PROCESS_OUTPUT_HANDLER_PRE_FORMAT_PROPERTY_KEY); ProcessOutputHandler handler=null; if(className!=null) { ...
java
protected ProcessOutput executeProcess(FaxJob faxJob,String command,FaxActionType faxActionType) { if(command==null) { this.throwUnsupportedException(); } //update command String updatedCommand=command; if(this.useWindowsCommandPrefix) { ...
java
public String getFilePath() { //get file File fileInstance=this.getFile(); String filePath=null; if(fileInstance!=null) { filePath=fileInstance.getPath(); } return filePath; }
java
public void setFilePath(String filePath) { //create a new file File fileInstance=null; if(filePath!=null) { fileInstance=new File(filePath); } //set file this.setFile(fileInstance); }
java
protected StringBuilder addToStringAttributes(String faxJobType) { //init buffer StringBuilder buffer=new StringBuilder(500); buffer.append(faxJobType); buffer.append(":"); //append values buffer.append(Logger.SYSTEM_EOL); buffer.append("ID: "); buffe...
java
protected final CommPortConnectionFactory createCommPortConnectionFactory() { //create new instance CommPortConnectionFactory factory=(CommPortConnectionFactory)ReflectionHelper.createInstance(this.commConnectionFactoryClassName); //initialize factory.initialize(this); ...
java