Skip to content

Commit

Permalink
Fix inclusion of croftsoft source code
Browse files Browse the repository at this point in the history
  • Loading branch information
gfinocchiaro committed Mar 29, 2024
1 parent caec0fa commit ae754de
Show file tree
Hide file tree
Showing 97 changed files with 9,582 additions and 0 deletions.
110 changes: 110 additions & 0 deletions src/main/java/com/croftsfot/core/applet/AppletLib.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package com.croftsoft.core.applet;

import java.applet.*;
import java.io.*;

import com.croftsoft.core.io.SerializableLib;
import com.croftsoft.core.lang.NullArgumentException;

/*********************************************************************
* Static library methods for manipulating Applets.
*
* @version
* $Id: AppletLib.java,v 1.3 2008/09/28 21:50:42 croft Exp $
* @since
* 2002-12-22
* @author
* <a href="http://www.CroftSoft.com/">David Wallace Croft</a>
*********************************************************************/

public final class AppletLib
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
{

/*********************************************************************
* Loads GZIP compressed data.
*********************************************************************/
public static Serializable loadSerializableUsingAppletPersistence (
Applet applet,
String key )
throws ClassNotFoundException, IOException,
UnsupportedOperationException
//////////////////////////////////////////////////////////////////////
{
NullArgumentException.check ( applet, "null applet" );

NullArgumentException.check ( key, "null key" );

AppletContext appletContext = null;

try
{
appletContext = applet.getAppletContext ( );
}
catch ( NullPointerException ex )
{
// ignore
}

if ( appletContext == null )
{
throw new UnsupportedOperationException ( "null AppletContext" );
}

InputStream inputStream = appletContext.getStream ( key );

if ( inputStream == null )
{
return null;
}

return SerializableLib.load ( inputStream );
}

/*********************************************************************
* Saves data using GZIP compression.
*********************************************************************/
public static void saveSerializableUsingAppletPersistence (
Applet applet,
String key,
Serializable serializable )
throws IOException, UnsupportedOperationException
//////////////////////////////////////////////////////////////////////
{
NullArgumentException.check ( applet, "null applet" );

NullArgumentException.check ( key, "null key" );

NullArgumentException.check ( serializable, "null serializable" );

AppletContext appletContext = null;

try
{
appletContext = applet.getAppletContext ( );
}
catch ( NullPointerException ex )
{
// ignore
}

if ( appletContext == null )
{
throw new UnsupportedOperationException ( "null AppletContext" );
}

InputStream inputStream = new ByteArrayInputStream (
SerializableLib.compress ( serializable ) );

appletContext.setStream ( key, inputStream );
}

//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

private AppletLib ( ) { /* empty */ }

//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
}
7 changes: 7 additions & 0 deletions src/main/java/com/croftsfot/core/applet/package.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<html>
<head>
</head>
<body>
Applet manipulation code.
</body>
</html>
116 changes: 116 additions & 0 deletions src/main/java/com/croftsfot/core/io/EchoReader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package com.croftsoft.core.io;

import java.io.*;

import com.croftsoft.core.lang.NullArgumentException;

/*********************************************************************
* A FilterReader that echoes characters read to a Writer.
*
* <p />
*
* @version
* 2002-09-19
* @since
* 2002-09-19
* @author
* <a href="http://www.CroftSoft.com/">David Wallace Croft</a>
*********************************************************************/

public final class EchoReader
extends FilterReader
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
{

private final Writer echoWriter;

//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

/*********************************************************************
* Main constructor.
*********************************************************************/
public EchoReader (
Reader in,
Writer echoWriter )
//////////////////////////////////////////////////////////////////////
{
super ( in );

NullArgumentException.check ( this.echoWriter = echoWriter );
}

/*********************************************************************
* Echoes to the standard output.
* <code><pre>this ( in, new PrintWriter ( System.out ) );</pre></code>
*********************************************************************/
public EchoReader ( Reader in )
//////////////////////////////////////////////////////////////////////
{
this ( in, new PrintWriter ( System.out ) );
}

//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////

public int read ( )
throws IOException
//////////////////////////////////////////////////////////////////////
{
int ch = super.read ( );

if ( ch > -1 )
{
echoWriter.write ( ch );
}

return ch;
}

public int read (
char [ ] cbuf,
int off,
int len )
throws IOException
//////////////////////////////////////////////////////////////////////
{
int count = super.read ( cbuf, off, len );

if ( count > -1 )
{
echoWriter.write ( cbuf, off, count );
}

return count;
}

public int read ( char [ ] cbuf )
throws IOException
//////////////////////////////////////////////////////////////////////
{
int count = super.read ( cbuf );

if ( count > -1 )
{
echoWriter.write ( cbuf, 0, count );
}

return count;
}

/*********************************************************************
* Flushes the echoWriter in addition to closing the input.
*********************************************************************/
public void close ( )
throws IOException
//////////////////////////////////////////////////////////////////////
{
super.close ( );

echoWriter.flush ( );
}

//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
}
28 changes: 28 additions & 0 deletions src/main/java/com/croftsfot/core/io/Encoder.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.croftsoft.core.io;

import java.io.*;

/*********************************************************************
* A generic interface for Object encoders.
*
* @see
* Parser
* @version
* 2003-05-13
* @since
* 2000-03-23
* @author
* <a href="http://www.CroftSoft.com/">David Wallace Croft</a>
*********************************************************************/

public interface Encoder
//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
{

public byte [ ] encode ( Object object )
throws IOException;

//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
}
Loading

0 comments on commit ae754de

Please sign in to comment.