protected void initializeCounterIfNecessary() {
		if (!initialized) {
			FsShell fsShell = new FsShell(getFileSystem().getConf(), getFileSystem());
			try {
				if (!fsShell.test(getBasePath())) {
					fsShell.mkdir(getBasePath());
				}
				int maxCounter = 0;
				boolean foundFile = false;
				Collection<FileStatus> fileStats = fsShell.ls(this.getBasePath());
				for (FileStatus fileStatus : fileStats) {
					String shortName = fileStatus.getPath().getName();
					int counterFromName = getCounterFromName(shortName);
					if (counterFromName != -1) {
						foundFile = true;
					}
					if (counterFromName > maxCounter) {
						maxCounter = counterFromName;
					}
				}
				if (foundFile) {
					this.setCounter(maxCounter + 1);
				}
			}
			finally {
				try {
					// fsShell.close();
				}
				catch (Exception e) {
					// ignore
				}
			}
			initialized = true;
		}
	}
Logic for writing to files of a specified size or other strategies go here as they are shared across implementations

@author Mark Pollack
spring-xd-hadoop/src/main/java/org/springframework/xd/hadoop/fs/AbstractHdfsWriter.java