code stringlengths 25 201k | docstring stringlengths 19 96.2k | func_name stringlengths 0 235 | language stringclasses 1 value | repo stringlengths 8 51 | path stringlengths 11 314 | url stringlengths 62 377 | license stringclasses 7 values |
|---|---|---|---|---|---|---|---|
private String substituteDatetime (String varName)
throws ConfigurationException
{
String value = "";
Date now = new Date();
if (varName.equals (PROGRAM_NOW_VAR))
{
value = now.toString();
}
else
{
char delim = varName.charAt (PROGRAM_NOW_VAR.length());
String[] tokens = TextUtil.split (varName, delim);
if ((tokens.length != 2) && (tokens.length != 4))
{
throw new ConfigurationException
(Package.BUNDLE_NAME, "ProgramSection.badNowFieldCount",
"Section \"{0}\", variable reference \"{1}\": " +
"Incorrect number of fields in extended version of " +
"\"{2}\" variable. Found {3} fields, expected either " +
"{4} or {5}.",
new Object[]
{
this.getName(),
varName,
PROGRAM_NOW_VAR,
String.valueOf (tokens.length),
"2",
"4"
});
}
Locale locale = null;
if (tokens.length == 2)
locale = Locale.getDefault();
else
locale = new Locale (tokens[2], tokens[3]);
try
{
SimpleDateFormat fmt = new SimpleDateFormat (tokens[1],
locale);
value = fmt.format (now);
}
catch (IllegalArgumentException ex)
{
throw new ConfigurationException (ex.toString());
}
}
return value;
} | Handle substitution of a date variable in the [program] section.
@param varName the variable name
@return the formatted date/time value
@throws ConfigurationException bad date format, or something | substituteDatetime | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/config/ProgramSection.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/config/ProgramSection.java | MIT |
int getID()
{
return id;
} | Get this section's unique numeric ID.
@return the ID | getID | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/config/Section.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/config/Section.java | MIT |
String getName()
{
return name;
} | Get this section's name
@return the name | getName | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/config/Section.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/config/Section.java | MIT |
Collection<String> getVariableNames()
{
return Collections.unmodifiableList (variableNames);
} | Get the names of all variables defined in this section, in the order
they were encountered in the file.
@return an unmodifiable <tt>Collection</tt> of <tt>String</tt> variable
names | getVariableNames | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/config/Section.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/config/Section.java | MIT |
Variable addVariable (String varName, String value)
{
Variable variable = new Variable (varName, value, this);
valueMap.put (varName, variable);
variableNames.add (varName);
return variable;
} | Add a variable to this section, replacing any existing instance
of the variable.
@param varName the variable name
@param value its (presumably unexpanded) value | addVariable | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/config/Section.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/config/Section.java | MIT |
Variable addVariable (String varName, String value, int lineDefined)
{
Variable variable = addVariable (varName, value);
variable.setLineWhereDefined (lineDefined);
return variable;
} | Add a variable to this section, replacing any existing instance
of the variable.
@param varName the variable name
@param value its (presumably unexpanded) value
@param lineDefined line number in the file where it was defined | addVariable | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/config/Section.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/config/Section.java | MIT |
void addVariables (Map<String, String> map)
{
for (String varName : map.keySet())
{
String value = map.get (varName);
addVariable (varName, value);
}
} | Add all the name/value pairs in a <tt>Map</tt> to this section,
overwriting any existing variables with the same names.
@param map the map | addVariables | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/config/Section.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/config/Section.java | MIT |
protected Map<String,String>
escapeEmbeddedBackslashes (Map<String,String> map)
{
XStringBuilder buf = new XStringBuilder();
for (Iterator<String> it = map.keySet().iterator(); it.hasNext();)
{
String varName = it.next();
String varValue = map.get (varName);
if (varValue.indexOf ('\\') != -1)
{
// Have to map each backslash to four backslashes due to a
// double-parse issue.
buf.clear();
buf.append(varValue);
buf.replaceAll("\\", "\\\\\\\\");
map.put (varName, buf.toString());
}
}
return map;
} | Double any backslashes found in the values of a map, returning the
possibly altered map.
@param map the map
@return the <tt>map</tt> parameter | escapeEmbeddedBackslashes | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/config/Section.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/config/Section.java | MIT |
Section getSection()
{
return parentSection;
} | Get the parent section that contains this variable.
@return the variable's section | getSection | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/config/Variable.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/config/Variable.java | MIT |
String getRawValue()
{
return rawValue;
} | Get the raw value for the variable. The raw value is the value
before any metacharacter expansion or variable substitution.
@return the raw value
@see #getCookedValue
@see #setCookedValue
@see #setValue | getRawValue | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/config/Variable.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/config/Variable.java | MIT |
String getCookedValue()
{
return cookedValue;
} | Get the cooked value for the variable. The cooked value is the value
after any metacharacter expansion and variable substitution.
@return the cooked value
@see #getRawValue
@see #getCookedTokens
@see #setCookedValue
@see #setValue | getCookedValue | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/config/Variable.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/config/Variable.java | MIT |
void setCookedValue (String value)
{
this.cookedValue = value;
} | Set the cooked value to the specified string, leaving the raw value
unmodified.
@param value the value to set
@see #getRawValue
@see #getCookedValue
@see #getCookedSegments
@see #setValue | setCookedValue | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/config/Variable.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/config/Variable.java | MIT |
ValueSegment[] getCookedSegments()
throws ConfigurationException
{
segmentValue();
return cookedSegments;
} | Get the cooked value, broken into separate segments. The segments
are stored internally. The cooked value is not updated until a call
to {@link #reassembleCookedValueFromSegments}. Calling this method
multiple times will not hamper efficiency. If the internal list of
segments is null (as it will be after construction or after a call
to <tt>reassembleCookedValueFromSegments()</tt>), then this method
creates the segments; otherwise, it just returns the existing ones.
@return the segments
@throws ConfigurationException on parsing error
@see #segmentValue
@see #reassembleCookedValueFromSegments | getCookedSegments | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/config/Variable.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/config/Variable.java | MIT |
ValueSegment[] getRawSegments()
throws ConfigurationException
{
segmentValue();
return rawSegments;
} | Get the raw value, broken into separate segments. The segments
are stored internally. The cooked value is not updated until a call
to {@link #reassembleCookedValueFromSegments}. Calling this method
multiple times will not hamper efficiency. If the internal list of
segments is null (as it will be after construction or after a call
to <tt>reassembleCookedValueFromSegments()</tt>), then this method
creates the segments; otherwise, it just returns the existing ones.
@return the segments
@throws ConfigurationException on parsing error
@see #segmentValue
@see #reassembleCookedValueFromSegments | getRawSegments | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/config/Variable.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/config/Variable.java | MIT |
void segmentValue()
throws ConfigurationException
{
if (rawSegments == null)
{
Collection<ValueSegment> segments = new ArrayList<ValueSegment>();
char ch;
char last;
char[] chars;
ValueSegment currentSegment = new ValueSegment();
int i;
chars = rawValue.toCharArray();
last = '\0';
currentSegment.isLiteral = false;
currentSegment.isWhiteSpaceEscaped = false;
for (i = 0; i < chars.length; i++)
{
ch = chars[i];
switch (ch) // NOPMD
{
case LITERAL_QUOTE:
if ((last == XStringBufBase.METACHAR_SEQUENCE_START) ||
(currentSegment.isWhiteSpaceEscaped))
{
// Escaped quote. Pass as literal.
currentSegment.append (ch);
}
else if (currentSegment.isLiteral)
{
// End of literal sequence. Thus, end of segment.
if (currentSegment.length() > 0)
{
segments.add (currentSegment);
currentSegment = new ValueSegment();
}
currentSegment.isLiteral = false;
}
else
{
// Start of literal sequence. Any previously
// buffered characters are part of the previous
// sequence and must be saved.
if (currentSegment.length() > 0)
{
segments.add (currentSegment);
currentSegment = new ValueSegment();
}
currentSegment.isLiteral = true;
}
break;
case SUBST_QUOTE:
if ((last == XStringBufBase.METACHAR_SEQUENCE_START) ||
(currentSegment.isLiteral))
{
// Escaped quote. Pass as literal.
currentSegment.append (ch);
}
else if (currentSegment.isWhiteSpaceEscaped)
{
// End of white-space escaped sequence. Thus,
// end of segment.
if (currentSegment.length() > 0)
{
segments.add (currentSegment);
currentSegment = new ValueSegment();
}
currentSegment.isWhiteSpaceEscaped = false;
}
else
{
// Start of literal sequence. Any previously
// buffered characters are part of the previous
// sequence and must be saved.
if (currentSegment.length() > 0)
{
segments.add (currentSegment);
currentSegment = new ValueSegment();
}
currentSegment.isWhiteSpaceEscaped = true;
}
break;
default:
currentSegment.append (ch);
}
last = ch;
}
if (currentSegment.isLiteral)
{
throw new ConfigurationException ("Unmatched " +
LITERAL_QUOTE +
" in variable \"" +
this.name +
"\"");
}
else if (currentSegment.isWhiteSpaceEscaped)
{
throw new ConfigurationException ("Unmatched " +
SUBST_QUOTE +
" in variable \"" +
this.name +
"\"");
}
if (currentSegment.length() > 0)
segments.add (currentSegment);
if (segments.size() > 0)
{
// Initially, the raw and cooked segments are identical.
// The main parser will "cook" the cooked segments.
rawSegments = new ValueSegment[segments.size()];
cookedSegments = new ValueSegment[segments.size()];
i = 0;
for (ValueSegment vs : segments)
{
rawSegments[i] = vs;
cookedSegments[i] = vs.makeCopy();
i++;
}
}
}
} | Segment the raw value into literal and non-literal pieces, storing the
resulting <tt>ValueSegment</tt> objects internally.
@throws ConfigurationException on parsing error
@see #getCookedSegments
@see #reassembleCookedValueFromSegments | segmentValue | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/config/Variable.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/config/Variable.java | MIT |
void reassembleCookedValueFromSegments()
{
if (cookedSegments != null)
{
StringBuilder buf = new StringBuilder();
cookedTokens = new String[cookedSegments.length];
int i = 0;
for (ValueSegment segment : cookedSegments)
{
String s = segment.segmentBuf.toString();
buf.append (s);
cookedTokens[i++] = s;
// valueSegments[i] = null;
}
cookedValue = buf.toString();
// valueSegments = null;
}
} | Reassemble the cooked value from the stored segments, zeroing out the
segments.
@see #getCookedSegments
@see #getCookedValue
@see #setCookedValue | reassembleCookedValueFromSegments | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/config/Variable.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/config/Variable.java | MIT |
final void setValue (String value)
{
this.rawValue = value;
this.cookedValue = value;
} | Set both the raw and cooked values to the specified string.
@param value the value to set
@see #getRawValue
@see #getCookedValue
@see #setCookedValue | setValue | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/config/Variable.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/config/Variable.java | MIT |
int getLineWhereDefined()
{
return this.lineWhereDefined;
} | Retrieve the line number where the variable was defined.
@return the line number, or 0 for unknown
@see #setLineWhereDefined | getLineWhereDefined | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/config/Variable.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/config/Variable.java | MIT |
void setLineWhereDefined (int lineNumber)
{
this.lineWhereDefined = lineNumber;
} | Set the line number where the variable was defined.
@param lineNumber the line number, or 0 for unknown
@see #getLineWhereDefined | setLineWhereDefined | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/config/Variable.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/config/Variable.java | MIT |
public static String stripHTMLTags (String s)
{
char[] ch = s.toCharArray();
boolean inElement = false;
XStringBuilder buf = new XStringBuilder();
for (int i = 0; i < ch.length; i++)
{
switch (ch[i])
{
case '<':
inElement = true;
break;
case '>':
if (inElement)
inElement = false;
else
buf.append (ch[i]);
break;
default:
if (! inElement)
buf.append (ch[i]);
break;
}
}
return buf.toString();
} | Removes all HTML element tags from a string, leaving just the character
data. This method does <b>not</b> touch any inline HTML character
entity codes. Use
{@link #convertCharacterEntities convertCharacterEntities()}
to convert HTML character entity codes.
@param s the string to adjust
@return the resulting, possibly modified, string
@see #convertCharacterEntities | stripHTMLTags | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/html/HTMLUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/html/HTMLUtil.java | MIT |
public static String escapeHTML(String s)
{
StringBuilder buf = new StringBuilder();
for (char c : s.toCharArray())
{
switch (c)
{
case '&':
buf.append("&");
break;
case '<':
buf.append("<");
break;
case '>':
buf.append(">");
break;
default:
buf.append(c);
}
}
return buf.toString();
} | Escape characters that are special in HTML, so that the resulting
string can be included in HTML (or XML). For instance, this method
will convert an embedded "&" to "&amp;".
@param s the string to convert
@return the converted string | escapeHTML | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/html/HTMLUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/html/HTMLUtil.java | MIT |
public static String convertCharacterEntities(String s)
{
// The resource bundle contains the mappings for symbolic entity
// names like "amp". Note: Must protect matching and MatchResult in
// a critical section, for thread-safety. See javadocs for
// Perl5Util.
synchronized (HTMLUtil.class)
{
try
{
if (entityPattern == null)
entityPattern = Pattern.compile ("&(#?[^;\\s&]+);?");
}
catch (PatternSyntaxException ex)
{
// Should not happen unless I've screwed up the pattern.
// Throw a runtime error.
assert (false);
}
}
XStringBuffer buf = new XStringBuffer();
Matcher matcher = null;
synchronized (HTMLUtil.class)
{
matcher = entityPattern.matcher (s);
}
for (;;)
{
String match = null;
String preMatch = null;
String postMatch = null;
if (! matcher.find())
break;
match = matcher.group(1);
preMatch = s.substring (0, matcher.start (1) - 1);
if (preMatch != null)
buf.append(preMatch);
if (s.charAt(matcher.end() - 1) != ';')
{
// Not a well-formed entity. Copy into the buffer.
buf.append(s.substring(matcher.start(), matcher.end()));
postMatch = s.substring(matcher.end(1));
}
else
{
// Well-formed entity.
postMatch = s.substring(matcher.end(1) + 1);
buf.append(convertEntity(match));
}
if (postMatch == null)
break;
s = postMatch;
matcher.reset (s);
}
if (s.length() > 0)
buf.append (s);
return buf.toString();
} | Converts all inline HTML character entities (c.f.,
<a href="http://www.w3.org/TR/REC-html40/sgml/entities.html">http://www.w3.org/TR/REC-html40/sgml/entities.html</a>)
to their Unicode character counterparts, if possible.
@param s the string to convert
@return the resulting, possibly modified, string
@see #stripHTMLTags
@see #makeCharacterEntities | convertCharacterEntities | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/html/HTMLUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/html/HTMLUtil.java | MIT |
public static String makeCharacterEntities (String s)
{
// First, make a character-to-entity-name map from the resource bundle.
ResourceBundle bundle = getResourceBundle();
Map<Character,String> charToEntityName =
new HashMap<Character,String>();
Enumeration<String> keys = bundle.getKeys();
XStringBuffer buf = new XStringBuffer();
while (keys.hasMoreElements())
{
String key = keys.nextElement();
String sChar = bundle.getString (key);
char c = sChar.charAt (0);
// Transform the bundle key into an entity name by removing the
// "html_" prefix.
buf.clear();
buf.append (key);
buf.delete ("html_");
charToEntityName.put (c, buf.toString());
}
char[] chars = s.toCharArray();
buf.clear();
for (int i = 0; i < chars.length; i++)
{
char c = chars[i];
String entity = charToEntityName.get (c);
if (entity == null)
{
if (! TextUtil.isPrintable(c))
{
buf.append("&#");
buf.append(Integer.valueOf(c));
buf.append(';');
}
else
{
buf.append(c);
}
}
else
{
buf.append ('&');
buf.append(entity);
buf.append(';');
}
}
return buf.toString();
} | Converts appropriate Unicode characters to their HTML character entity
counterparts (c.f.,
<a href="http://www.w3.org/TR/REC-html40/sgml/entities.html">http://www.w3.org/TR/REC-html40/sgml/entities.html</a>).
@param s the string to convert
@return the resulting, possibly modified, string
@see #stripHTMLTags
@see #convertCharacterEntities | makeCharacterEntities | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/html/HTMLUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/html/HTMLUtil.java | MIT |
public static String textFromHTML(String s)
{
String stripped = convertCharacterEntities (stripHTMLTags (s));
char[] ch = stripped.toCharArray();
StringBuilder buf = new StringBuilder();
for (int i = 0; i < ch.length; i++)
{
switch (ch[i])
{
case Unicode.LEFT_SINGLE_QUOTE:
case Unicode.RIGHT_SINGLE_QUOTE:
buf.append ('\'');
break;
case Unicode.LEFT_DOUBLE_QUOTE:
case Unicode.RIGHT_DOUBLE_QUOTE:
buf.append ('"');
break;
case Unicode.EM_DASH:
buf.append ("--");
break;
case Unicode.EN_DASH:
case Unicode.NON_BREAKING_HYPHEN:
buf.append ('-');
break;
case Unicode.ZERO_WIDTH_JOINER:
case Unicode.ZERO_WIDTH_NON_JOINER:
break;
case Unicode.TRADEMARK:
buf.append ("[TM]");
break;
case Unicode.NBSP:
case Unicode.THIN_SPACE:
case Unicode.HAIR_SPACE:
case Unicode.EM_SPACE:
case Unicode.EN_SPACE:
buf.append(' ');
break;
default:
buf.append (ch[i]);
break;
}
}
return buf.toString();
} | Convenience method to convert embedded HTML to text. This method:
<ul>
<li> Strips embedded HTML tags via a call to
{@link #stripHTMLTags #stripHTMLTags()}
<li> Uses {@link #convertCharacterEntities convertCharacterEntities()}
to convert HTML entity codes to appropriate Unicode characters.
<li> Converts certain Unicode characters in a string to plain text
sequences.
</ul>
@param s the string to parse
@return the resulting, possibly modified, string
@see #convertCharacterEntities
@see #stripHTMLTags | textFromHTML | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/html/HTMLUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/html/HTMLUtil.java | MIT |
private static String convertEntity(String s)
{
StringBuilder buf = new StringBuilder();
ResourceBundle bundle = getResourceBundle();
if (s.charAt(0) == '#')
{
if (s.length() == 1)
buf.append('#');
else
{
// It might be a numeric entity code. Try to parse it as a
// number. If the parse fails, just put the whole string in the
// result, as is. Be sure to handle both the decimal form
// (e.g., ™) and the hexadecimal form (e.g., ™).
int cc;
boolean isHex = (s.length() > 2) && (s.charAt(1) == 'x');
boolean isLegal = false;
try
{
if (isHex)
cc = Integer.parseInt(s.substring(2), 16);
else
cc = Integer.parseInt(s.substring(1));
// It parsed. Is it a valid Unicode character?
if (Character.isDefined((char) cc))
{
buf.append((char) cc);
isLegal = true;
}
}
catch (NumberFormatException ex)
{
}
if (! isLegal)
{
buf.append("&#");
if (isHex)
buf.append('x');
buf.append(s + ";");
}
}
}
else
{
// Not a numeric entity. Try to find a matching symbolic
// entity.
try
{
buf.append(bundle.getString("html_" + s));
}
catch (MissingResourceException ex)
{
buf.append("&" + s + ";");
}
}
return buf.toString();
} | Match an entity, minus the leading "&" and ";" characters. | convertEntity | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/html/HTMLUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/html/HTMLUtil.java | MIT |
private static ResourceBundle getResourceBundle()
{
synchronized (HTMLUtil.class)
{
if (resourceBundle == null)
resourceBundle = ResourceBundle.getBundle (BUNDLE_NAME);
}
return resourceBundle;
} | Load the resource bundle, if it hasn't already been loaded. | getResourceBundle | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/html/HTMLUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/html/HTMLUtil.java | MIT |
public boolean accept (File dir, String name)
{
boolean accepted = true;
for (FilenameFilter filter : filters)
{
accepted = filter.accept (dir, name);
if (! accepted)
break;
}
return accepted;
} | <p>Determine whether a file is to be accepted or not, based on the
contained filters. The file is accepted if any one of the contained
filters accepts it. This method stops looping over the contained
filters as soon as it encounters one whose <tt>accept()</tt> method
returns <tt>false</tt> (implementing a "short-circuited AND"
operation.)</p>
<p>If the set of contained filters is empty, then this method
returns <tt>true</tt>.</p>
@param dir The directory containing the file.
@param name the file name
@return <tt>true</tt> if the file matches, <tt>false</tt> if it doesn't | accept | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/AndFilenameFilter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/AndFilenameFilter.java | MIT |
public CombinationFilterMode getMode()
{
return mode;
} | Get the combination mode of this <tt>CombinationFileFilter</tt>
object.
@return {@link #AND_FILTERS} if a filename must be accepted by all
contained filters. {@link #OR_FILTERS} if a filename only
needs to be accepted by one of the contained filters.
@see #setMode | getMode | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/CombinationFileFilter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/CombinationFileFilter.java | MIT |
public void setMode (CombinationFilterMode mode)
{
this.mode = mode;
} | Change the combination mode of this <tt>CombinationFileFilter</tt>
object.
@param mode {@link #AND_FILTERS} if a filename must be accepted
by all contained filters. {@link #OR_FILTERS} if a
filename only needs to be accepted by one of the
contained filters.
@see #getMode | setMode | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/CombinationFileFilter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/CombinationFileFilter.java | MIT |
public void addFilter (FileFilter filter)
{
filters.add (filter);
} | Add a filter to the set of contained filters.
@param filter the <tt>FileFilter</tt> to add.
@see #removeFilter | addFilter | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/CombinationFileFilter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/CombinationFileFilter.java | MIT |
public boolean accept (File file)
{
boolean accepted = false;
Iterator<FileFilter> it = filters.iterator();
FileFilter filter;
if (mode == AND_FILTERS)
{
accepted = true;
while (accepted && it.hasNext())
{
filter = it.next();
accepted = filter.accept (file);
}
}
else
{
accepted = false;
while ((! accepted) && it.hasNext())
{
filter = it.next();
accepted = filter.accept (file);
}
}
return accepted;
} | Determine whether a file is to be accepted or not, based on the
contained filters and the mode. If this object's mode mode is set to
{@link #AND_FILTERS}, then a file must be accepted by all contained
filters to be accepted. If this object's mode is set to
{@link #OR_FILTERS}, then a file name is accepted if any one of the
contained filters accepts it. If the set of contained filters is
empty, then this method returns <tt>false</tt>.
@param file The file to check for acceptance
@return <tt>true</tt> if the file matches, <tt>false</tt> if it doesn't | accept | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/CombinationFileFilter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/CombinationFileFilter.java | MIT |
public void addFilter (FilenameFilter filter)
{
filters.add (filter);
} | Add a filter to the set of contained filters.
@param filter the <tt>FilenameFilter</tt> to add.
@see #removeFilter | addFilter | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/CombinationFilenameFilter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/CombinationFilenameFilter.java | MIT |
public boolean accept (File dir, String name)
{
boolean accepted = false;
Iterator it = filters.iterator();
FilenameFilter filter;
if (mode == AND_FILTERS)
{
accepted = true;
while (accepted && it.hasNext())
{
filter = (FilenameFilter) it.next();
accepted = filter.accept (dir, name);
}
}
else
{
accepted = false;
while ((! accepted) && it.hasNext())
{
filter = (FilenameFilter) it.next();
accepted = filter.accept (dir, name);
}
}
return accepted;
} | Determine whether a file is to be accepted or not, based on the
contained filters and the mode. If this object's mode mode is set to
{@link #AND_FILTERS}, then a file must be accepted by all contained
filters to be accepted. If this object's mode is set to
{@link #OR_FILTERS}, then a file name is accepted if any one of the
contained filters accepts it. If the set of contained filters is
empty, then this method returns <tt>false</tt>.
@param dir The directory containing the file.
@param name the file name
@return <tt>true</tt> if the file matches, <tt>false</tt> if it doesn't | accept | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/CombinationFilenameFilter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/CombinationFilenameFilter.java | MIT |
public int compare (Object o1, Object o2)
{
String s1 = getFileName (o1);
String s2 = getFileName (o2);
int cmp = 0;
if (foldCase)
cmp = s1.compareToIgnoreCase (s2);
else
cmp = s1.compareTo (s2);
return cmp;
} | Compares its two arguments for order. Returns a negative integer,
zero, or a positive integer as the first argument is less than,
equal to, or greater than the second.
@param o1 the first object to be compared
@param o2 the second object to be compared
@return a negative integer, zero, or a positive integer as the first
argument is less than, equal to, or greater than the second. | compare | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/FileNameComparator.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/FileNameComparator.java | MIT |
public boolean equals (Object o)
{
boolean eq = false;
if (o instanceof FileNameComparator)
{
FileNameComparator other = (FileNameComparator) o;
eq = (other.foldCase == this.foldCase) &&
(other.entirePath == this.entirePath);
}
return eq;
} | <p>Indicates whether some other object is "equal to" this
<tt>Comparator</tt>.</p>
@param o the object to compare
@return <tt>true</tt> only if the pecified object is also a comparator
and it imposes the same ordering as this comparator. | equals | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/FileNameComparator.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/FileNameComparator.java | MIT |
public static boolean isAbsolutePath(String path)
throws IOException
{
// It's important not to use java.util.File.listRoots(), for two
// reasons:
//
// 1. On Windows, the floppy can be one of the roots. If there isn't
// a disk in the floppy drive, some versions of Windows will issue
// an "Abort/Continue/Retry" pop-up.
// 2. If a security manager is installed, listRoots() can return
// a null or empty array.
//
// So, this version analyzes the pathname textually.
boolean isAbsolute = false;
String fileSep = System.getProperty("file.separator");
if (fileSep.equals("/"))
{
// Unix.
isAbsolute = path.startsWith("/");
}
else if (fileSep.equals("\\"))
{
// Windows. Must start with something that looks like a drive
// letter.
isAbsolute = (Character.isLetter(path.charAt(0))) &&
(path.charAt(1) == ':') &&
(path.charAt(2) == '\\');
}
else
{
throw new IOException("Can't determine operating system from " +
"file separator \"" + fileSep + "\"");
}
return isAbsolute;
} | Determine whether a string represents an absolute path. On Unix, an
absolute path must start with a "/". On Windows, it must begin
with one of the machine's valid drive letters.
@param path the path to check
@return <tt>true</tt> if it's absolute, <tt>false</tt> if not
@throws IOException on error | isAbsolutePath | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/FileUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/FileUtil.java | MIT |
public static int copyStream(InputStream is, OutputStream os)
throws IOException
{
return copyStream(is, os, -1);
} | Copy an <tt>InputStream</tt> to an <tt>OutputStream</tt>. If either
stream is not already buffered, then it's wrapped in the corresponding
buffered stream (i.e., <tt>BufferedInputStream</tt> or
<tt>BufferedOutputStream</tt>) before copying. Calling this method
is equivalent to:
<blockquote><pre>copyStream (src, dst, 8192);</pre></blockquote>
@param is the source <tt>InputStream</tt>
@param os the destination <tt>OutputStream</tt>
@return total number of bytes copied
@throws IOException on error
@see #copyStream(InputStream,OutputStream,int)
@see #copyReader(Reader,Writer)
@see #copyFile(File,File) | copyStream | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/FileUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/FileUtil.java | MIT |
public static int copyStream(InputStream src,
OutputStream dst,
int bufferSize)
throws IOException
{
int totalCopied = 0;
if (! (src instanceof BufferedInputStream))
{
if (bufferSize > 0)
src = new BufferedInputStream(src, bufferSize);
else
src = new BufferedInputStream(src);
}
if (! (dst instanceof BufferedOutputStream))
{
if (bufferSize > 0)
dst = new BufferedOutputStream(dst, bufferSize);
else
dst = new BufferedOutputStream(dst);
}
int b;
while ((b = src.read()) != -1)
{
dst.write(b);
totalCopied++;
}
dst.flush();
return totalCopied;
} | Copy an <tt>InputStream</tt> to an <tt>OutputStream</tt>. If either
stream is not already buffered, then it's wrapped in the corresponding
buffered stream (i.e., <tt>BufferedInputStream</tt> or
<tt>BufferedOutputStream</tt>) before copying.
@param src the source <tt>InputStream</tt>
@param dst the destination <tt>OutputStream</tt>
@param bufferSize the buffer size to use, or -1 for a default
@return total number of bytes copied
@throws IOException on error
@see #copyReader(Reader,Writer,int)
@see #copyStream(InputStream,OutputStream)
@see #copyFile(File,File) | copyStream | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/FileUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/FileUtil.java | MIT |
public static int copyReader(Reader reader, Writer writer, int bufferSize)
throws IOException
{
if (! (reader instanceof BufferedReader))
{
if (bufferSize > 0)
reader = new BufferedReader(reader, bufferSize);
else
reader = new BufferedReader(reader);
}
if (! (writer instanceof BufferedWriter))
{
if (bufferSize > 0)
writer = new BufferedWriter(writer, bufferSize);
else
writer = new BufferedWriter(writer);
}
int ch;
int total = 0;
while ((ch = reader.read()) != -1)
{
writer.write(ch);
total++;
}
writer.flush();
return total;
} | Copy characters from a reader to a writer. If the reader is not
already buffered, then it's wrapped in a <tt>BufferedReader</tt>,
using the specified buffer size. Similarly, buffered stream (i.e.,
<tt>BufferedInputStream</tt> or If the writer is not already
buffered, then it's wrapped in a <tt>BufferedWriter</tt>, using the
specified buffer size.
@param reader where to read from
@param writer where to write to
@param bufferSize buffer size to use, if reader and writer are not
already buffered, or -1 to use a default size.
@return total number of characters copied
@throws IOException on error
@see #copyReader(Reader,Writer)
@see #copyStream(InputStream,OutputStream,int)
@see #copyStream(InputStream,OutputStream)
@see #copyFile(File,File) | copyReader | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/FileUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/FileUtil.java | MIT |
public static int copyReader(Reader reader, Writer writer)
throws IOException
{
return copyReader(reader, writer, -1);
} | Copy characters from a reader to a writer, using a default buffer size.
@param reader where to read from
@param writer where to write to
@return total number of characters copied
@throws IOException on error
@see #copyReader(Reader,Writer)
@see #copyStream(InputStream,OutputStream,int)
@see #copyStream(InputStream,OutputStream)
@see #copyFile(File,File) | copyReader | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/FileUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/FileUtil.java | MIT |
public static int copyFile(File src, File dst) throws IOException
{
int totalCopied = 0;
if (dst.isDirectory())
dst = new File(dst, src.getName());
InputStream from = null;
OutputStream to = null;
try
{
from = new FileInputStream(src);
to = new FileOutputStream(dst);
totalCopied = copyStream(from, to);
}
finally
{
if (from != null)
from.close();
if (to != null)
to.close();
}
return totalCopied;
} | Copy one file to another. This method simply copies bytes and
performs no character set conversion. If you want character set
conversions, use {@link #copyTextFile(File,String,File,String)}.
@param src The file to copy
@param dst Where to copy it. Can be a directory or a file.
@return total number of bytes copied
@throws IOException on error
@see #copyTextFile(File,String,File,String)
@see #copyReader(Reader,Writer,int)
@see #copyReader(Reader,Writer)
@see #copyStream(InputStream,OutputStream,int)
@see #copyStream(InputStream,OutputStream) | copyFile | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/FileUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/FileUtil.java | MIT |
public static int copyTextFile(File src,
String srcEncoding,
File dst,
String dstEncoding)
throws IOException
{
if (dst.isDirectory())
dst = new File(dst, src.getName());
Reader reader;
Writer writer;
if (srcEncoding != null)
{
reader = new InputStreamReader(new FileInputStream(src),
srcEncoding);
}
else
{
reader = new FileReader(src);
}
if (dstEncoding != null)
{
writer = new OutputStreamWriter(new FileOutputStream(dst),
dstEncoding);
}
else
{
writer = new FileWriter(dst);
}
int total = copyReader(reader, writer);
reader.close();
writer.close();
return total;
} | Copy one file to another, character by character, possibly doing
character set conversions
@param src the file to copy
@param srcEncoding the character set encoding for the source file,
or null to assume the default
@param dst Where to copy it. Can be a directory or a file.
@param dstEncoding the character set encoding for the destination file,
or null to assume the default
@return total number of characters copied
@throws IOException on error
@see #copyFile(File,File)
@see #copyReader(Reader,Writer,int)
@see #copyReader(Reader,Writer)
@see #copyStream(InputStream,OutputStream,int)
@see #copyStream(InputStream,OutputStream) | copyTextFile | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/FileUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/FileUtil.java | MIT |
public static String getDefaultEncoding()
{
return java.nio.charset.Charset.defaultCharset().name();
} | Get the virtual machine's default encoding.
@return the default encoding | getDefaultEncoding | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/FileUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/FileUtil.java | MIT |
public static String getFileNameExtension(File file)
{
return getFileNameExtension(file.getName());
} | Get the extension for a path or file name. Does not include the ".".
@param file the file
@return the extension, or null if there isn't one | getFileNameExtension | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/FileUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/FileUtil.java | MIT |
public static String getFileNameExtension(String path)
{
String ext = null;
int i = path.lastIndexOf('.');
if ((i != -1) && (i != (path.length() - 1)))
ext = path.substring(i + 1);
return ext;
} | Get the extension for a path or file name. Does not include the ".".
@param path the file or path name
@return the extension, or null if there isn't one | getFileNameExtension | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/FileUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/FileUtil.java | MIT |
public static String getFileNameNoExtension(File file)
{
return getFileNameNoExtension(file.getAbsolutePath());
} | Get the name of a file without its extension. Does not remove
any parent directory components. Uses <tt>File.getAbsolutePath()</tt>,
not <tt>File.getCanonicalPath()</tt> to get the path.
@param file the file
@return the path without the extension | getFileNameNoExtension | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/FileUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/FileUtil.java | MIT |
public static String getFileNameNoExtension(String path)
{
int i = path.lastIndexOf('.');
if (i != -1)
path = path.substring(0, i);
return path;
} | Get the name of a file without its extension. Does not remove
any parent directory components.
@param path the path
@return the path without the extension | getFileNameNoExtension | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/FileUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/FileUtil.java | MIT |
public static String dirname(String fileName)
{
return dirname(new File(fileName));
} | Get the name of a file's parent directory. This is the directory
part of the filename. For instance, "/home/foo.zip" would return
"/home". This method uses the file's absolute path.
@param fileName the file name
@return directory name part of the file's absolute pathname
@see #dirname(File)
@see #basename(String) | dirname | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/FileUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/FileUtil.java | MIT |
public static String dirname(File file)
{
String absName = file.getAbsolutePath();
String fileSep = System.getProperty("file.separator");
int lastSep = absName.lastIndexOf(fileSep);
return absName.substring(0, lastSep);
} | Get the name of a file's parent directory. This is the directory
part of the filename. For instance, "/home/foo.zip" would return
"/home". This method uses the file's absolute path.
@param file the file whose parent directory is to be returned
@return directory name part of the file's absolute pathname
@see #dirname(String)
@see #basename(File) | dirname | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/FileUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/FileUtil.java | MIT |
public static String basename(String fileName)
{
String fileSep = System.getProperty("file.separator");
int lastSep = fileName.lastIndexOf(fileSep);
return (lastSep == -1) ? fileName
: fileName.substring(lastSep + 1);
} | Get the base (i.e., simple file) name of a file. This is the file
name stripped of any directory information. For instance,
"/home/foo.zip" would return "foo.zip".
@param fileName name of the file to get the basename for
@return file name part of the file
@see #dirname(String) | basename | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/FileUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/FileUtil.java | MIT |
public static String basename (File file)
{
return basename(file.getName());
} | Get the base (i.e., simple file) name of a file. This is the file
name stripped of any directory information. For instance,
"/home/foo.zip" would return "foo.zip".
@param file the file to get the basename for
@return file name part of the file
@see #basename(String)
@see #dirname(File) | basename | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/FileUtil.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/FileUtil.java | MIT |
public JustifyStyle getJustification()
{
return justification;
} | Retrieve the current justification style.
@return The current justification style
@see #setJustification | getJustification | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/JustifyTextWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/JustifyTextWriter.java | MIT |
public void setJustification (JustifyStyle style)
{
justification = style;
} | Set or change the current justification style.
@param style The new justification style
@see #setJustification | setJustification | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/JustifyTextWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/JustifyTextWriter.java | MIT |
private synchronized void flushBufferedLine()
{
if (buffer.length() > 0)
{
String s = buffer.toString();
switch (justification)
{
case LEFT_JUSTIFY:
writer.print (s);
break;
case RIGHT_JUSTIFY:
writer.print (TextUtil.rightJustifyString (s, lineLength));
break;
case CENTER:
writer.print (TextUtil.centerString (s, lineLength));
break;
}
buffer.setLength (0);
}
} | Flushes any characters in the buffered output line, then clears the
buffer. | flushBufferedLine | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/JustifyTextWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/JustifyTextWriter.java | MIT |
public void addAcceptPattern (String pattern)
throws PatternSyntaxException
{
acceptPatterns.add (Pattern.compile (pattern, regexOptions));
} | Add an "accept" pattern to this filter. For a file to be accepted:
<ul>
<li> it must not match one of the <i>reject</i> patterns, and
<li> either the <i>accept</i> pattern list must be empty, or the
file name must match one of the <i>accept</i> patterns
</ul>
@param pattern the regular expression to add
@throws PatternSyntaxException bad regular expression
@see #addRejectPattern | addAcceptPattern | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/MultipleRegexFilenameFilter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/MultipleRegexFilenameFilter.java | MIT |
public void addRejectPattern (String pattern)
throws PatternSyntaxException
{
rejectPatterns.add (Pattern.compile (pattern, regexOptions));
} | Add an "accept" pattern to this filter. For a file to be accepted:
<ul>
<li> it must not match one of the <i>reject</i> patterns, and
<li> either the <i>accept</i> pattern list must be empty, or the
file name must match one of the <i>accept</i> patterns
</ul>
@param pattern the regular expression to add
@throws PatternSyntaxException bad regular expression
@see #addAcceptPattern | addRejectPattern | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/MultipleRegexFilenameFilter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/MultipleRegexFilenameFilter.java | MIT |
public boolean accept (File dir, String name)
{
Iterator it;
boolean match = false;
boolean found = false;
if (matchType == MatchType.PATH)
{
name = dir.getPath()
+ System.getProperty ("file.separator")
+ name;
}
// Check for rejects first.
for (Pattern pattern : rejectPatterns)
{
Matcher matcher = pattern.matcher (name);
if (matcher.matches())
{
match = false;
found = true;
break;
}
}
if (! found)
{
// Check for accepts.
if (acceptPatterns.size() == 0)
match = true;
else
{
for (Pattern pattern : acceptPatterns)
{
Matcher matcher = pattern.matcher (name);
if (matcher.matches())
{
match = true;
break;
}
}
}
}
return match;
} | Determine whether a file is to be accepted or not, based on the
regular expressions in the <i>reject</i> and <i>accept</i> lists.
@param dir The directory containing the file. Ignored if
the match type is <tt>MatchType.FILENAME</tt>. Used to
build the path to match when the match type is
<tt>MatchType.PATH</tt>
@param name the file name
@return <tt>true</tt> if the file matches, <tt>false</tt> if it doesn't | accept | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/MultipleRegexFilenameFilter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/MultipleRegexFilenameFilter.java | MIT |
public boolean accept (File file)
{
return ! this.filter.accept (file);
} | Tests whether a file should be included in a file list.
@param file The file to check for acceptance
@return <tt>true</tt> if the file matches, <tt>false</tt> if it doesn't | accept | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/NotFileFilter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/NotFileFilter.java | MIT |
public boolean accept (File dir, String name)
{
return ! this.filter.accept (dir, name);
} | Tests whether a file should be included in a file list.
@param dir The directory containing the file.
@param name the file name
@return <tt>true</tt> if the file matches, <tt>false</tt> if it doesn't | accept | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/NotFilenameFilter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/NotFilenameFilter.java | MIT |
public boolean accept (File dir, String name)
{
boolean accepted = false;
if (filters.size() == 0)
accepted = true;
else
{
for (FilenameFilter filter : filters)
{
accepted = filter.accept (dir, name);
if (accepted)
break;
}
}
return accepted;
} | <p>Determine whether a file is to be accepted or not, based on the
contained filters. The file is accepted if any one of the contained
filters accepts it. This method stops looping over the contained
filters as soon as it encounters one whose <tt>accept()</tt> method
returns <tt>true</tt> (implementing a "short-circuited OR"
operation.)</p>
<p>If the set of contained filters is empty, then this method
returns <tt>true</tt>.</p>
@param dir The directory containing the file.
@param name the file name
@return <tt>true</tt> if the file matches, <tt>false</tt> if it doesn't | accept | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/OrFilenameFilter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/OrFilenameFilter.java | MIT |
public int findFiles (File directory, Collection<File> collection)
{
return findFiles (directory, (FileFilter) null, collection);
} | Find all files beneath a given directory. This version of
<tt>find()</tt> takes no filter, so every file and directory is
matched.
@param directory the starting directory
@param collection where to store the found <tt>File</tt> objects
@return the number of <tt>File</tt> objects found | findFiles | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RecursiveFileFinder.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RecursiveFileFinder.java | MIT |
public boolean accept (File file)
{
String name = null;
switch (matchType)
{
case PATH:
name = file.getPath();
break;
case FILENAME:
name = file.getName();
break;
default:
assert (false);
}
return pattern.matcher (name).find();
} | Determine whether a file is to be accepted or not, based on the
regular expressions in the <i>reject</i> and <i>accept</i> lists.
@param file The file to test. If the match type is
<tt>FileFilterMatchType.FILENAME</tt>, then the value
of <tt>file.getPath()</tt> is compared to the regular
expression. If the match type is
<tt>FileFilterMatchType.PATH</tt>, then the value of
<tt>file.getName()</tt> is compared to the regular
expression.
@return <tt>true</tt> if the file matches, <tt>false</tt> if it doesn't | accept | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RegexFileFilter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RegexFileFilter.java | MIT |
public boolean accept (File dir, String name)
{
if (matchType == FileFilterMatchType.PATH)
name = new File (dir, name).getPath();
return pattern.matcher (name).find();
} | Determine whether a file is to be accepted or not, based on the
regular expressions in the <i>reject</i> and <i>accept</i> lists.
@param dir The directory containing the file. Ignored if
the match type is <tt>FileFilterMatchType.FILENAME</tt>.
Used to build the path to match when the match type is
<tt>FileFilterMatchType.PATH</tt>
@param name the file name
@return <tt>true</tt> if the file matches, <tt>false</tt> if it doesn't | accept | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RegexFilenameFilter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RegexFilenameFilter.java | MIT |
public String getPathName()
{
return this.primaryFile.getPath();
} | Get the path name of the file being written to.
@return The file's name | getPathName | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RollingFileWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RollingFileWriter.java | MIT |
public synchronized void flush()
{
super.flush();
} | Flush the stream. If the stream has saved any characters from the
various write() methods in a buffer, write them immediately to their
intended destination. Then, if that destination is another character
or byte stream, flush it. Thus one flush() invocation will flush all
the buffers in a chain of Writers and OutputStreams. This method
does not check for roll-over, because it's possible to flush the
object in the middle of a line, and roll-over should only occur at
the end of a line. | flush | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RollingFileWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RollingFileWriter.java | MIT |
public synchronized void println()
{
super.println();
try
{
checkForRollOver();
}
catch (Exception ex)
{
}
} | Finish the current line, rolling the file if necessary. | println | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RollingFileWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RollingFileWriter.java | MIT |
public synchronized void println (boolean b)
{
print (b);
println();
} | Print a boolean and finish the line, rolling the file if necessary.
@param b The boolean to print | println | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RollingFileWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RollingFileWriter.java | MIT |
public synchronized void println (char c)
{
print (c);
println();
} | Print a character and finish the line, rolling the file if necessary.
@param c The character to print | println | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RollingFileWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RollingFileWriter.java | MIT |
public synchronized void println (char s[])
{
print (s);
println();
} | Print an array of characters and finish the line, rolling the file
if necessary.
@param s The array of characters to print | println | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RollingFileWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RollingFileWriter.java | MIT |
public synchronized void println (double d)
{
print (d);
println();
} | Print a double and finish the line, rolling the file if necessary.
@param d The double floating point number to print | println | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RollingFileWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RollingFileWriter.java | MIT |
public synchronized void println (float f)
{
print (f);
println();
} | Print a float and finish the line, rolling the file if necessary.
@param f The floating point number to print | println | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RollingFileWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RollingFileWriter.java | MIT |
public synchronized void println (int i)
{
print (i);
println();
} | Print an integer and finish the line, rolling the file if necessary.
@param i The integer to print | println | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RollingFileWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RollingFileWriter.java | MIT |
public synchronized void println (long l)
{
super.print (l);
println();
} | Print a long and finish the line, rolling the file if necessary.
@param l The long to print | println | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RollingFileWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RollingFileWriter.java | MIT |
public synchronized void println (short s)
{
super.print (s);
println();
} | Print a short and finish the line, rolling the file if necessary.
@param s The short to print | println | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RollingFileWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RollingFileWriter.java | MIT |
public synchronized void println (String s)
{
super.print (s);
println();
} | Print a String and finish the line, rolling the file if necessary.
@param s The String to print. | println | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RollingFileWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RollingFileWriter.java | MIT |
public synchronized void println (Object o)
{
super.print (o);
println();
} | Print an Object and finish the line, rolling the file if necessary.
@param o The object to print. | println | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RollingFileWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RollingFileWriter.java | MIT |
private synchronized void checkForRollOver() throws IOExceptionExt
{
if ( (maxRolledFileSize > 0) && (maxRolledOverFiles > 0) )
{
// Rollover is enabled. If the log file is empty, we don't
// roll it over (obviously), even if writing the message would
// cause the log file to exceed the maximum size. (That's one big
// message...)
long fileSize = this.primaryFile.length();
if (fileSize >= maxRolledFileSize)
{
// Must roll over.
log.debug ("fileSize=" +
fileSize +
", maxSize=" +
maxRolledFileSize +
" -> must roll files over.");
super.out = rollFilesOver (this.primaryFile,
this.filePattern,
this.charsetName,
this.maxRolledOverFiles,
this.compressionType,
this,
this.callback);
}
}
} | Determines whether the log file needs to be rolled over and, if so,
rolls it over. If roll-over isn't enabled, this method returns without
doing anything.
@throws IOExceptionExt On error | checkForRollOver | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RollingFileWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RollingFileWriter.java | MIT |
private static void renameFile (File sourceFile, File targetFile)
throws IOExceptionExt
{
log.debug ("Moving file \"" +
sourceFile.getName() +
"\" to \"" +
targetFile.getName() +
"\"");
try
{
if (! sourceFile.renameTo (targetFile))
{
throw new IOExceptionExt (Package.BUNDLE_NAME,
"RollingFileWriter.cantMoveFile",
"Unable to move file \"{0}\" to " +
"\"{1}\"",
new Object[]
{
sourceFile.getPath(),
targetFile.getPath()
});
}
}
catch (SecurityException ex)
{
throw new IOExceptionExt (Package.BUNDLE_NAME,
"RollingFileWriter.cantMoveFile",
"Unable to move file \"{0}\" to \"{1}\"",
new Object[]
{
sourceFile.getPath(),
targetFile.getPath()
},
ex);
}
} | Move a file, converting any IOExceptions into IOExceptions.
@param sourceFile the file to move
@param targetFile where it should go
@throws IOExceptionExt on error | renameFile | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RollingFileWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RollingFileWriter.java | MIT |
private static Writer openPrimaryFile (String fileNamePattern,
String charsetName,
int maxRolledOverFiles,
Compression compressionType,
RolloverCallback callback)
throws IOExceptionExt
{
File primaryFile = resolveFilePattern (fileNamePattern,
null,
maxRolledOverFiles,
null);
log.debug ("primaryFile=" + primaryFile.getPath());
Writer w = null;
if (primaryFile.exists())
{
log.debug ("Primary file exists. Rolling...");
w = rollFilesOver (primaryFile,
fileNamePattern,
charsetName,
maxRolledOverFiles,
compressionType,
null,
callback);
}
else
{
log.debug ("Primary file does not exist.");
w = openFile (primaryFile, charsetName);
}
return w;
} | Resolve the primary file name pattern, save the resulting File
object in the primaryFile instance variable, and open the file.
If the primary file exists, it's rolled over (backed up) and
a new one is opened.
@param fileNamePattern the file name pattern
@param charsetName the name of the encoding to use, or null
@param maxRolledOverFiles max number of rolled-over files
@param compressionType {@link Compression#COMPRESS_BACKUPS} to
compress backups,
{@link Compression#DONT_COMPRESS_BACKUPS} to
leave backups uncompressed
@param callback callback to invoke on roll-over, or null
@return an open Writer object
@throws IOExceptionExt on error | openPrimaryFile | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RollingFileWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RollingFileWriter.java | MIT |
private static Writer openFile (File file, String charsetName)
throws IOExceptionExt
{
Writer result = null;
try
{
if (charsetName != null)
{
result = new OutputStreamWriter (new FileOutputStream (file),
charsetName);
}
else
{
result = new FileWriter (file);
}
}
catch (IOException ex)
{
throw new IOExceptionExt (Package.BUNDLE_NAME,
"RollingFileWriter.cantOpenFile",
"Unable to open file \"{0}\"",
new Object[] {file.getPath()});
}
return result;
} | Open the specified log file for writing. Sets the "writer"
instance variable on success.
@param file The file to open
@param charsetName the name of the encoding to use, or null
@return the open file
@throws IOExceptionExt Failed to open file | openFile | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RollingFileWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RollingFileWriter.java | MIT |
private static File resolveFilePattern (String fileNamePattern,
Integer index,
int maxRolledOverFiles,
Compression compressionType)
throws IOExceptionExt
{
try
{
// Validate the pattern by expanding it to its primary file name.
BackupIndexDereferencer deref =
new BackupIndexDereferencer (index, maxRolledOverFiles);
UnixShellVariableSubstituter sub =
new UnixShellVariableSubstituter();
sub.setHonorEscapes(false);
String fileName = sub.substitute(fileNamePattern,
deref,
null,
fileNamePattern);
if (! deref.patternIsLegal())
{
throw new IOExceptionExt(Package.BUNDLE_NAME,
"RollingFileWriter.badPattern",
"File pattern \"{0}\" is missing " +
"the \"$'{n}'\" marker.",
new Object[] {fileNamePattern});
}
if (compressionType == Compression.COMPRESS_BACKUPS)
fileName = fileName + GZIP_EXTENSION;
return new File (fileName);
}
catch (VariableSubstitutionException ex)
{
throw new IOExceptionExt (ex);
}
} | Resolve a file pattern into a file.
@param fileNamePattern the pattern
@param index the file index, or null for the primary file
@param maxRolledOverFiles max number of rolled-over files
@param compressionType compression type, or null
@return the File object
@throws IOExceptionExt on error | resolveFilePattern | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RollingFileWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RollingFileWriter.java | MIT |
private static Writer rollFilesOver (File primaryFile,
String fileNamePattern,
String charsetName,
int maxRolledOverFiles,
Compression compressionType,
RollingFileWriter rollingFileWriter,
RolloverCallback callback)
throws IOExceptionExt
{
log.debug ("rolling \"" + primaryFile.getPath() + "\"");
// Ultimately, we're looking to roll over the current file, so
// we may need to shift other rolled-over files out of the way.
// It's possible to have gaps in the sequence (e.g., if someone
// removed a file). For instance:
//
// error.log error.log-0 error.log-1 error.log-3 error.log-5 ...
//
// We don't coalesce all the gaps at once. Instead, we just roll
// files over until we fill the nearest gap. In the example above,
// we'd move "error.log-1" to "error.log-2" (filling in the gap),
// then move "error.log-0" to "error.log-1" and "error.log" to
// "error.log-0". This is the most efficient approach, especially
// if the number of saved files is large. Eventually, all the gaps
// will fill in.
int firstGap = -1;
int lastLegalIndex = maxRolledOverFiles - 1;
int i;
for (i = 0; i < maxRolledOverFiles; i++)
{
File f = resolveFilePattern (fileNamePattern,
i,
maxRolledOverFiles,
compressionType);
if (! f.exists())
{
firstGap = i;
break;
}
}
log.debug ("firstGap(1)=" + firstGap);
// At this point, we know whether there are any gaps. If there aren't,
// we have to shift all files down by one (possibly tossing the
// last one). If there are gaps, we just have to shift the files
// ahead of the first gap.
if (firstGap == -1)
firstGap = lastLegalIndex;
log.debug ("firstGap(2)=" + firstGap);
for (i = firstGap - 1; i >= 0; i--)
{
File targetFile = resolveFilePattern (fileNamePattern,
i + 1,
maxRolledOverFiles,
compressionType);
File sourceFile = resolveFilePattern (fileNamePattern,
i,
maxRolledOverFiles,
compressionType);
// Target file can exist if there was no gap (i.e., we're at
// the end of all the possible files).
if (targetFile.exists())
{
log.debug ("Removing file \"" + targetFile.getPath() + "\"");
try
{
targetFile.delete();
}
catch (SecurityException ex)
{
throw new IOExceptionExt
(Package.BUNDLE_NAME,
"RollingFileWriter.cantDeleteFile",
"Can't delete file \"{0}\"",
new Object[] {targetFile.getPath()});
}
}
// Attempt to move the source file to the target slot.
renameFile (sourceFile, targetFile);
}
String rollOverMsg = null;
if (rollingFileWriter != null)
{
// Close the current file, and rename it to the 0th rolled-over
// file. If there's a callback defined, use it to get a
// rollover message, and write that message first.
if (callback != null)
{
rollOverMsg = callback.getRollOverMessage();
if (rollOverMsg != null)
{
log.debug ("Appending roll-over message \"" +
rollOverMsg +
"\" to full primary file \"" +
primaryFile +
"\"");
// Calling super.println (anything) will fail, because
// we've overridden the methods. But we haven't
// overridden the write() methods, so we can use them
// to do what we want.
rollingFileWriter.printlnNoRoll (rollOverMsg);
}
}
log.debug ("Closing full primary file \"" + primaryFile + "\".");
rollingFileWriter.flush();
rollingFileWriter.close();
}
File targetFile = resolveFilePattern (fileNamePattern,
0,
maxRolledOverFiles,
null);
renameFile (primaryFile, targetFile);
if (compressionType == Compression.COMPRESS_BACKUPS)
gzipFile (targetFile);
// Finally, open the file. Add the same 'rolled over' message to
// the top of this one.
log.debug ("Reopening \"" + primaryFile + "\"");
Writer result = openFile (primaryFile, charsetName);
if (rollOverMsg != null)
{
try
{
log.debug ("Writing roll-over message \"" +
rollOverMsg +
"\" to top of new primary file \"" +
primaryFile +
"\"");
result.write (rollOverMsg);
result.write (newline);
result.flush();
}
catch (IOException ex)
{
throw new IOExceptionExt (ex);
}
}
return result;
} | Rolls the files over.
@param primaryFile primary file name
@param fileNamePattern file name pattern
@param charsetName encoding to use, or null
@param maxRolledOverFiles max number of rolled-over files
@param compressionType {@link Compression#COMPRESS_BACKUPS} to
compress backups,
{@link Compression#DONT_COMPRESS_BACKUPS} to
leave backups uncompressed
@param rollingFileWriter the open writer for the file being rolled
@param callback callback to invoke on roll-over, or null
@throws IOExceptionExt On error. | rollFilesOver | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RollingFileWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RollingFileWriter.java | MIT |
private static void gzipFile (File file)
throws IOExceptionExt
{
try
{
InputStream is = new FileInputStream (file);
OutputStream os = new GZIPOutputStream
(new FileOutputStream (file.getPath() +
GZIP_EXTENSION));
FileUtil.copyStream (is, os);
is.close();
os.close();
if (! file.delete())
{
throw new IOExceptionExt (Package.BUNDLE_NAME,
"RollingFileWriter.cantDeleteFile",
"Can't delete file \"{0}\"",
new Object[] {file.getPath()});
}
}
catch (IOException ex)
{
throw new IOExceptionExt (Package.BUNDLE_NAME,
"RollingFileWriter.cantGzipFile",
"Can't gzip file \"{0}\"",
new Object[] {file.getPath()});
}
} | Gzip a file.
@param file the file to gzip
@throws IOExceptionExt on error | gzipFile | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/RollingFileWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/RollingFileWriter.java | MIT |
public char getIndentationChar()
{
return indentChar;
} | Get the current indentation character. By default, the indentation
character is a blank.
@return The current indentation character.
@see #setIndentationChar | getIndentationChar | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/WordWrapWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/WordWrapWriter.java | MIT |
public String getPrefix()
{
return prefix;
} | Get the current prefix. The prefix is the string that's displayed before
the first line of output; subsequent wrapped lines are tabbed past the
prefix.
@return the current prefix, or null if there isn't one.
@see #setPrefix | getPrefix | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/WordWrapWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/WordWrapWriter.java | MIT |
public void setIndentationChar (char c)
{
indentChar = c;
} | Change the indentation character. By default, the indentation
character is a blank.
@param c The new indentation character.
@see #getIndentationChar | setIndentationChar | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/WordWrapWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/WordWrapWriter.java | MIT |
private void flushBuffer (StringBuffer buf)
{
// Ask the StringTokenizer to return the delimiters, too. That way,
// empty lines are not skipped. Otherwise, the StringTokenizer will
// parse through multiple adjacent delimiters, causing empty lines
// to be swallowed.
StringTokenizer lineTok = new StringTokenizer (buf.toString(),
"" + NEWLINE_MARKER,
true);
String localPrefix = (prefix == null) ? "" : prefix;
int currentLength = 0;
boolean lastWasNewline = true;
while (lineTok.hasMoreTokens())
{
String line = lineTok.nextToken();
if ((line.length() == 1) && (line.charAt (0) == NEWLINE_MARKER))
{
// Newline. Process and go back for more.
writer.println();
lastWasNewline = true;
currentLength = 0;
continue;
}
StringTokenizer wordTok = new StringTokenizer (line);
// Process this line's worth of tokens.
while (wordTok.hasMoreTokens())
{
String word = wordTok.nextToken();
int wordLength = word.length();
// If the word (plus a delimiting space) exceeds the line
// length, wrap now.
if ((wordLength + currentLength + 1) > this.lineLength)
{
if (! lastWasNewline)
{
writer.println();
currentLength = 0;
lastWasNewline = true;
}
}
if (lastWasNewline)
{
// indent() handles both the prefix and the indentation.
currentLength += indent();
lastWasNewline = false;
}
else
{
writer.print (' ');
currentLength += 1;
}
writer.print (word);
currentLength += wordLength;
}
}
if (currentLength > 0)
writer.println();
writer.flush();
} | Handles the details of flushing specified output buffer to the
output stream.
@param buf The buffer | flushBuffer | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/WordWrapWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/WordWrapWriter.java | MIT |
public void close()
throws IOException
{
out.close();
} | Close this <tt>Writer</tt>
@throws IOException I/O error | close | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/XMLWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/XMLWriter.java | MIT |
public void flush()
throws IOException
{
out.flush();
} | Flush this <tt>Writer</tt>
@throws IOException I/O error | flush | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/XMLWriter.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/XMLWriter.java | MIT |
protected void finalize()
{
try
{
close();
}
catch (IOException ex)
{
}
} | Destroys the object, closing the underlying zip or jar file, if it's
open. | finalize | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/Zipper.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/Zipper.java | MIT |
public synchronized void close() throws IOException
{
if (zipStream != null)
{
zipStream.close();
zipStream = null;
}
} | Close the <tt>Zipper</tt> object, flushing any changes to and closing
the underlying zip or jar file.
@throws IOException error closing Zip/jar file | close | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/Zipper.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/Zipper.java | MIT |
public synchronized boolean containsEntry (String name)
{
return tableOfContents.contains (convertName (name));
} | Determine whether an entry with the specified name has been written
to the zip file. The name will be flattened if this object was
created with flattening enabled.
@param name The name to check
@return <tt>true</tt> if that name was written to the zip file;
<tt>false</tt> otherwise | containsEntry | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/Zipper.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/Zipper.java | MIT |
public File getFile()
{
return zipFile;
} | Get the <tt>File</tt> object that describes the underlying Jar or
zip file to which this <tt>Zipper</tt> object is writing. It is legal
to call this method even after the <tt>Zipper</tt> has been closed.
@return the underlying zip or jar file | getFile | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/Zipper.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/Zipper.java | MIT |
public int getTotalEntries()
{
return totalEntriesWritten;
} | Get the total number of entries written to the zip or jar file so
far. It's legal to call this method even after the <tt>Zipper</tt>
object has been closed.
@return the total number of entries written to this object
@see #put(File)
@see #put(String)
@see #put(InputStream,String)
@see #close() | getTotalEntries | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/Zipper.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/Zipper.java | MIT |
public void put (File file) throws IOException
{
if (! file.exists())
{
throw new IOException ("File \"" + file.getPath() +
"\" does not exist.");
}
if ((! file.isDirectory()) && (! file.canRead()))
{
throw new IOException ("Cannot read file \"" + file.getPath() +
"\".");
}
if (file.isDirectory())
writeDirectory (file);
else
write (file);
} | Put a <tt>File</tt> object to the zip or jar file. The file's
contents will be placed in the zip or jar file immediately following
the last item that was written.
@param file The <tt>File</tt> to be added to the zip or jar file.
The specified file can be a file or a directory.
@throws IOException The specified file doesn't exist or isn't readable.
@see #put(File,String)
@see #put(String)
@see #put(InputStream,String) | put | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/Zipper.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/Zipper.java | MIT |
public void put (File file, String name) throws IOException
{
FileInputStream in = new FileInputStream (file);
write (in, name);
in.close();
} | Put a <tt>File</tt> object to the zip or jar file, but using a
specified Zip entry name, rather than the name of the file itself.
The file's contents will be placed in the zip or jar file
immediately following the last item that was written.
@param file The <tt>File</tt> to be added to the zip or jar file.
The specified file can be a file or a directory.
@param name The name to use for the Zip entry
@throws IOException The specified file doesn't exist or isn't readable.
@see #put(File)
@see #put(String)
@see #put(InputStream,String) | put | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/Zipper.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/Zipper.java | MIT |
public void put (String path) throws IOException
{
put (new File (path));
} | Put a named file to the zip or jar file. The file's contents will be
placed in the zip or jar file immediately following the last item
that was written.
@param path The path to the file to be added to the zip or jar file.
The specified file can be a file or a directory.
@throws IOException The specified file doesn't exist or isn't readable.
@see #put(File,String)
@see #put(File)
@see #put(InputStream,String) | put | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/Zipper.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/Zipper.java | MIT |
public void put (InputStream istream, String name) throws IOException
{
write (istream, name);
} | Put an <tt>InputStream</tt> object to the zip or jar file. The
<tt>InputStream</tt> will be read until EOF, and the stream of bytes
will be placed in the zip or jar file immediately following the
last item that was written.
@param istream The <tt>InputStream</tt> to be added to the zip or
jar file.
@param name The name to give the entry in the zip or jar file.
@throws IOException The specified file doesn't exist or isn't readable.
@see #put(File,String)
@see #put(File)
@see #put(String) | put | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/Zipper.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/Zipper.java | MIT |
public void put (byte[] bytes, String name) throws IOException
{
write (bytes, name);
} | Put an array of bytes to the zip or jar file. The stream of bytes
will be placed in the zip or jar file immediately following the last
item that was written.
@param bytes The bytes to be added to the zip or jar file.
@param name The name to give the entry in the zip or jar file.
@throws IOException The specified file doesn't exist or isn't readable.
@see #put(File,String)
@see #put(File)
@see #put(String) | put | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/Zipper.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/Zipper.java | MIT |
public void put (URL url, String name) throws IOException
{
write (url.openConnection().getInputStream(), name);
} | Open a URL, read its contents, and store the contents in the
underlying zip or jar file. The URL's contents will be placed in the
zip or jar file immediately following the last item that was
written.
@param url The URL to be downloaded and stored in the zip or jar file
@param name The name to give the entry in the zip or jar file
@throws IOException failed to open or read URL | put | java | kiooeht/ModTheSpire | src/main/java/org/clapper/util/io/Zipper.java | https://github.com/kiooeht/ModTheSpire/blob/master/src/main/java/org/clapper/util/io/Zipper.java | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.